diff --git a/internal_packages/category-picker/lib/category-picker.cjsx b/internal_packages/category-picker/lib/category-picker.cjsx index 408ef3c82..07752f327 100644 --- a/internal_packages/category-picker/lib/category-picker.cjsx +++ b/internal_packages/category-picker/lib/category-picker.cjsx @@ -55,10 +55,9 @@ class CategoryPicker extends React.Component _registerObservables: => @_unregisterObservables() - @disposables = [] - @disposables.push( + @disposables = [ Categories.forAccount(@_account).subscribe(@_onCategoriesChanged) - ) + ] _unregisterObservables: => return unless @disposables diff --git a/internal_packages/category-picker/spec/category-picker-spec.cjsx b/internal_packages/category-picker/spec/category-picker-spec.cjsx index 4be936d37..8dfad109d 100644 --- a/internal_packages/category-picker/spec/category-picker-spec.cjsx +++ b/internal_packages/category-picker/spec/category-picker-spec.cjsx @@ -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) diff --git a/spec/nylas-test-utils.coffee b/spec/nylas-test-utils.coffee index fe27afffe..1e1565c1d 100644 --- a/spec/nylas-test-utils.coffee +++ b/spec/nylas-test-utils.coffee @@ -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 diff --git a/src/flux/stores/focused-perspective-store.coffee b/src/flux/stores/focused-perspective-store.coffee index d20d0aa07..a297f53b2 100644 --- a/src/flux/stores/focused-perspective-store.coffee +++ b/src/flux/stores/focused-perspective-store.coffee @@ -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)