mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-21 22:54:11 +08:00
fix(focused-persepective): Init saved perspective correctly
- When accounts changed and the saved perspective could reference accounts that no longer exist and cause all sorts of errors. This is fixed. - Add specs - Fixes some sentry errors
This commit is contained in:
parent
8a8170eb0e
commit
68b6d7df60
2 changed files with 41 additions and 3 deletions
|
@ -25,6 +25,35 @@ describe "FocusedPerspectiveStore", ->
|
|||
return @userCategory if id is @userCategory.id
|
||||
return null
|
||||
|
||||
describe "_initCurrentPerspective", ->
|
||||
beforeEach ->
|
||||
@default = 'default'
|
||||
@accounts = [{id: 1}, {id: 2}]
|
||||
spyOn(MailboxPerspective, 'fromJSON').andCallFake (json) -> json
|
||||
spyOn(FocusedPerspectiveStore, '_defaultPerspective').andReturn @default
|
||||
|
||||
it "uses default perspective when no perspective has been saved", ->
|
||||
current = FocusedPerspectiveStore._initCurrentPerspective(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)
|
||||
expect(current).toEqual @default
|
||||
|
||||
saved = {accountIds: [3]}
|
||||
current = FocusedPerspectiveStore._initCurrentPerspective(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)
|
||||
expect(current).toEqual saved
|
||||
|
||||
saved = {accountIds: [1]}
|
||||
current = FocusedPerspectiveStore._initCurrentPerspective(saved, @accounts)
|
||||
expect(current).toEqual saved
|
||||
|
||||
describe "_onCategoryStoreChanged", ->
|
||||
it "should set the current category to Inbox when it is unset", ->
|
||||
FocusedPerspectiveStore._perspective = null
|
||||
|
|
|
@ -7,14 +7,23 @@ Actions = require '../actions'
|
|||
|
||||
class FocusedPerspectiveStore extends NylasStore
|
||||
constructor: ->
|
||||
if NylasEnv.savedState.perspective
|
||||
@_current = MailboxPerspective.fromJSON(NylasEnv.savedState.perspective)
|
||||
@_current ?= @_defaultPerspective()
|
||||
@_current = @_initCurrentPerspective(NylasEnv.savedState.perspective)
|
||||
|
||||
@listenTo CategoryStore, @_onCategoryStoreChanged
|
||||
@listenTo Actions.focusMailboxPerspective, @_onFocusPerspective
|
||||
@listenTo Actions.focusDefaultMailboxPerspectiveForAccounts, @_onFocusAccounts
|
||||
|
||||
_initCurrentPerspective: (savedPerspective, accounts = AccountStore.accounts()) =>
|
||||
if savedPerspective
|
||||
current = MailboxPerspective.fromJSON(savedPerspective)
|
||||
if current
|
||||
accountIds = _.pluck(accounts, 'id')
|
||||
accountIdsNotPresent = _.difference(current.accountIds, accountIds)
|
||||
current = null if accountIdsNotPresent.length > 0
|
||||
|
||||
current ?= @_defaultPerspective()
|
||||
return current
|
||||
|
||||
# Inbound Events
|
||||
|
||||
_onCategoryStoreChanged: ->
|
||||
|
|
Loading…
Reference in a new issue