mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-28 19:31:14 +08:00
Fix CategoryPicker specs
- Add NylasUtils.mockObservable helper
This commit is contained in:
parent
a352e40af7
commit
e97ca2b606
4 changed files with 32 additions and 9 deletions
|
@ -55,10 +55,9 @@ class CategoryPicker extends React.Component
|
|||
|
||||
_registerObservables: =>
|
||||
@_unregisterObservables()
|
||||
@disposables = []
|
||||
@disposables.push(
|
||||
@disposables = [
|
||||
Categories.forAccount(@_account).subscribe(@_onCategoriesChanged)
|
||||
)
|
||||
]
|
||||
|
||||
_unregisterObservables: =>
|
||||
return unless @disposables
|
||||
|
|
|
@ -15,8 +15,11 @@ CategoryPicker = require '../lib/category-picker'
|
|||
TaskFactory,
|
||||
SyncbackCategoryTask,
|
||||
FocusedPerspectiveStore,
|
||||
NylasTestUtils,
|
||||
TaskQueueStatusStore} = require 'nylas-exports'
|
||||
|
||||
{Categories} = require 'nylas-observables'
|
||||
|
||||
describe 'CategoryPicker', ->
|
||||
beforeEach ->
|
||||
CategoryStore._categoryCache = {}
|
||||
|
@ -27,19 +30,27 @@ describe 'CategoryPicker', ->
|
|||
setupFor = (organizationUnit) ->
|
||||
NylasEnv.testOrganizationUnit = organizationUnit
|
||||
@categoryClass = if organizationUnit is "label" then Label else Folder
|
||||
@account = {
|
||||
id: TEST_ACCOUNT_ID
|
||||
usesLabels: -> organizationUnit is "label"
|
||||
usesFolders: -> organizationUnit isnt "label"
|
||||
categoryClass: => @categoryClass
|
||||
}
|
||||
|
||||
@inboxCategory = new @categoryClass(id: 'id-123', name: 'inbox', displayName: "INBOX")
|
||||
@archiveCategory = new @categoryClass(id: 'id-456', name: 'archive', displayName: "ArCHIVe")
|
||||
@userCategory = new @categoryClass(id: 'id-789', name: null, displayName: "MyCategory")
|
||||
|
||||
spyOn(CategoryStore, "getStandardCategories").andReturn [ @inboxCategory, @archiveCategory ]
|
||||
spyOn(CategoryStore, "getUserCategories").andReturn [ @userCategory ]
|
||||
spyOn(Categories, "forAccount").andReturn NylasTestUtils.mockObservable(
|
||||
[@inboxCategory, @archiveCategory, @userCategory]
|
||||
)
|
||||
spyOn(CategoryStore, "getStandardCategory").andReturn @inboxCategory
|
||||
spyOn(AccountStore, "accountForItems").andReturn @account
|
||||
|
||||
# By default we're going to set to "inbox". This has implications for
|
||||
# what categories get filtered out of the list.
|
||||
f = FocusedPerspectiveStore
|
||||
f._setMailView f._defaultMailView()
|
||||
f._setPerspective f._defaultPerspective(@account)
|
||||
|
||||
setupForCreateNew = (orgUnit = "folder") ->
|
||||
setupFor.call(@, orgUnit)
|
||||
|
|
|
@ -40,4 +40,18 @@ NylasTestUtils =
|
|||
document.body.removeChild(child)
|
||||
return
|
||||
|
||||
# Returns mock observable that triggers immediately and provides helper
|
||||
# function to trigger later
|
||||
mockObservable: (data, {dispose} = {}) ->
|
||||
dispose ?= ->
|
||||
func = ->
|
||||
return {
|
||||
subscribe: (fn) ->
|
||||
func = fn
|
||||
func(data)
|
||||
return {dispose}
|
||||
triggerNext: (nextData = data) ->
|
||||
func(nextData)
|
||||
}
|
||||
|
||||
module.exports = NylasTestUtils
|
||||
|
|
|
@ -41,9 +41,8 @@ class FocusedPerspectiveStore extends NylasStore
|
|||
@_setPerspective(@_currentBeforeSearch)
|
||||
@_currentBeforeSearch = null
|
||||
|
||||
_defaultPerspective: ->
|
||||
# TODO Update unified MailboxPerspective
|
||||
account = AccountStore.accounts()[0]
|
||||
# TODO Update unified MailboxPerspective
|
||||
_defaultPerspective: (account = AccountStore.accounts()[0])->
|
||||
category = CategoryStore.getStandardCategory(account, "inbox")
|
||||
return null unless category
|
||||
MailboxPerspective.forCategory(account, category)
|
||||
|
|
Loading…
Reference in a new issue