mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-28 23:44:38 +08:00
fix(perspective): Fix specs for FocusedPerspectiveStore
This commit is contained in:
parent
92268ad099
commit
d9517101d5
2 changed files with 23 additions and 25 deletions
|
@ -15,9 +15,9 @@ describe "FocusedPerspectiveStore", ->
|
|||
@account = AccountStore.accounts()[0]
|
||||
|
||||
@inboxCategory = new Category(id: 'id-123', name: 'inbox', displayName: "INBOX", accountId: @account.id)
|
||||
@inboxFilter = MailboxPerspective.forCategory(@inboxCategory)
|
||||
@inboxPerspective = MailboxPerspective.forCategory(@inboxCategory)
|
||||
@userCategory = new Category(id: 'id-456', name: null, displayName: "MyCategory", accountId: @account.id)
|
||||
@userFilter = MailboxPerspective.forCategory(@userCategory)
|
||||
@userPerspective = MailboxPerspective.forCategory(@userCategory)
|
||||
|
||||
spyOn(CategoryStore, "getStandardCategory").andReturn @inboxCategory
|
||||
spyOn(CategoryStore, "byId").andCallFake (id) =>
|
||||
|
@ -25,7 +25,7 @@ describe "FocusedPerspectiveStore", ->
|
|||
return @userCategory if id is @userCategory.id
|
||||
return null
|
||||
|
||||
describe "_initCurrentPerspective", ->
|
||||
describe "_loadSavedPerspective", ->
|
||||
beforeEach ->
|
||||
@default = 'default'
|
||||
@accounts = [{id: 1}, {id: 2}]
|
||||
|
@ -33,52 +33,50 @@ describe "FocusedPerspectiveStore", ->
|
|||
spyOn(FocusedPerspectiveStore, '_defaultPerspective').andReturn @default
|
||||
|
||||
it "uses default perspective when no perspective has been saved", ->
|
||||
current = FocusedPerspectiveStore._initCurrentPerspective(undefined, @accounts)
|
||||
current = FocusedPerspectiveStore._loadSavedPerspective(undefined, @accounts)
|
||||
expect(current).toEqual @default
|
||||
|
||||
it "uses default if saved perspective has more account ids not present in current accounts", ->
|
||||
saved = {accountIds: [1,2,3]}
|
||||
current = FocusedPerspectiveStore._initCurrentPerspective(saved, @accounts)
|
||||
current = FocusedPerspectiveStore._loadSavedPerspective(saved, @accounts)
|
||||
expect(current).toEqual @default
|
||||
|
||||
saved = {accountIds: [3]}
|
||||
current = FocusedPerspectiveStore._initCurrentPerspective(saved, @accounts)
|
||||
current = FocusedPerspectiveStore._loadSavedPerspective(saved, @accounts)
|
||||
expect(current).toEqual @default
|
||||
|
||||
it "uses saved perspective if all accounts in saved perspective are present in the current accounts", ->
|
||||
saved = {accountIds: [1,2]}
|
||||
current = FocusedPerspectiveStore._initCurrentPerspective(saved, @accounts)
|
||||
current = FocusedPerspectiveStore._loadSavedPerspective(saved, @accounts)
|
||||
expect(current).toEqual saved
|
||||
|
||||
saved = {accountIds: [1]}
|
||||
current = FocusedPerspectiveStore._initCurrentPerspective(saved, @accounts)
|
||||
current = FocusedPerspectiveStore._loadSavedPerspective(saved, @accounts)
|
||||
expect(current).toEqual saved
|
||||
|
||||
describe "_onCategoryStoreChanged", ->
|
||||
it "should set the current category to unified inbox when it is unset", ->
|
||||
FocusedPerspectiveStore._perspective = null
|
||||
it "should load the saved perspective if the perspective has not been initialized", ->
|
||||
spyOn(FocusedPerspectiveStore, '_loadSavedPerspective').andReturn(@inboxPerspective)
|
||||
FocusedPerspectiveStore._onCategoryStoreChanged()
|
||||
expect(FocusedPerspectiveStore.current()).not.toBe(null)
|
||||
expect(FocusedPerspectiveStore.current()).toEqual(@inboxPerspective)
|
||||
|
||||
# same because the stub above returns @inboxCategory for both accounts
|
||||
expect(FocusedPerspectiveStore.current().categories()).toEqual([@inboxCategory, @inboxCategory])
|
||||
|
||||
it "should set the current category to Inbox when the current category no longer exists in the CategoryStore", ->
|
||||
it "should set the current category to default when the current category no longer exists in the CategoryStore", ->
|
||||
defaultPerspective = @inboxPerspective
|
||||
spyOn(FocusedPerspectiveStore, '_defaultPerspective').andReturn(defaultPerspective)
|
||||
otherAccountInbox = @inboxCategory.clone()
|
||||
otherAccountInbox.serverId = 'other-id'
|
||||
FocusedPerspectiveStore._perspective = MailboxPerspective.forCategory(otherAccountInbox)
|
||||
FocusedPerspectiveStore._current = MailboxPerspective.forCategory(otherAccountInbox)
|
||||
FocusedPerspectiveStore._onCategoryStoreChanged()
|
||||
# same because the stub above returns @inboxCategory for both accounts
|
||||
expect(FocusedPerspectiveStore.current().categories()).toEqual([@inboxCategory, @inboxCategory])
|
||||
expect(FocusedPerspectiveStore.current()).toEqual(defaultPerspective)
|
||||
|
||||
describe "_onFocusPerspective", ->
|
||||
it "should focus the category and trigger", ->
|
||||
FocusedPerspectiveStore._onFocusPerspective(@userFilter)
|
||||
FocusedPerspectiveStore._onFocusPerspective(@userPerspective)
|
||||
expect(FocusedPerspectiveStore.trigger).toHaveBeenCalled()
|
||||
expect(FocusedPerspectiveStore.current().categories()).toEqual([@userCategory])
|
||||
|
||||
it "should do nothing if the category is already focused", ->
|
||||
FocusedPerspectiveStore._onFocusPerspective(@inboxFilter)
|
||||
FocusedPerspectiveStore._onFocusPerspective(@inboxPerspective)
|
||||
spyOn(FocusedPerspectiveStore, '_setPerspective')
|
||||
FocusedPerspectiveStore._onFocusPerspective(@inboxFilter)
|
||||
FocusedPerspectiveStore._onFocusPerspective(@inboxPerspective)
|
||||
expect(FocusedPerspectiveStore._setPerspective).not.toHaveBeenCalled()
|
||||
|
|
|
@ -14,7 +14,7 @@ class FocusedPerspectiveStore extends NylasStore
|
|||
@listenTo Actions.focusDefaultMailboxPerspectiveForAccounts, @_onFocusAccounts
|
||||
|
||||
|
||||
_createDefaultPerspective: (savedPerspective, accounts = AccountStore.accounts()) =>
|
||||
_loadSavedPerspective: (savedPerspective, accounts = AccountStore.accounts()) =>
|
||||
if savedPerspective
|
||||
perspective = MailboxPerspective.fromJSON(savedPerspective)
|
||||
if perspective
|
||||
|
@ -29,7 +29,7 @@ class FocusedPerspectiveStore extends NylasStore
|
|||
|
||||
_onCategoryStoreChanged: ->
|
||||
if @_current.isEqual(MailboxPerspective.forNothing())
|
||||
perspective = @_createDefaultPerspective(NylasEnv.savedState.perspective)
|
||||
perspective = @_loadSavedPerspective(NylasEnv.savedState.perspective)
|
||||
@_setPerspective(perspective)
|
||||
else
|
||||
accountIds = @_current.accountIds
|
||||
|
@ -37,8 +37,8 @@ class FocusedPerspectiveStore extends NylasStore
|
|||
catExists = (cat) -> CategoryStore.byId(cat.accountId, cat.id)
|
||||
categoryHasBeenDeleted = categories and not _.every(categories, catExists)
|
||||
|
||||
if categoryHasBeenDeleted
|
||||
@_setPerspective(@_defaultPerspective(accountIds))
|
||||
if categoryHasBeenDeleted
|
||||
@_setPerspective(@_defaultPerspective(accountIds))
|
||||
|
||||
_onFocusPerspective: (perspective) =>
|
||||
return if perspective.isEqual(@_current)
|
||||
|
|
Loading…
Add table
Reference in a new issue