2015-09-05 03:23:15 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
|
2015-09-10 07:04:13 +08:00
|
|
|
Actions = require '../../src/flux/actions'
|
2015-09-05 03:23:15 +08:00
|
|
|
Label = require '../../src/flux/models/label'
|
|
|
|
Folder = require '../../src/flux/models/folder'
|
|
|
|
MailViewFilter = require '../../src/mail-view-filter'
|
|
|
|
|
|
|
|
CategoryStore = require '../../src/flux/stores/category-store'
|
|
|
|
AccountStore = require '../../src/flux/stores/account-store'
|
|
|
|
FocusedMailViewStore = require '../../src/flux/stores/focused-mail-view-store'
|
|
|
|
|
|
|
|
describe "FocusedMailViewStore", ->
|
|
|
|
beforeEach ->
|
|
|
|
spyOn(FocusedMailViewStore, 'trigger')
|
|
|
|
FocusedMailViewStore._mailView = null
|
|
|
|
|
|
|
|
afterEach ->
|
2015-11-12 02:25:11 +08:00
|
|
|
NylasEnv.testOrganizationUnit = null
|
2015-09-05 03:23:15 +08:00
|
|
|
|
|
|
|
testStore = ->
|
|
|
|
describe "_onCategoryStoreChanged", ->
|
|
|
|
it "should set the current category to Inbox when it is unset", ->
|
|
|
|
FocusedMailViewStore._mailView = null
|
|
|
|
FocusedMailViewStore._onCategoryStoreChanged()
|
|
|
|
expect(FocusedMailViewStore.mailView()).not.toBe(null)
|
|
|
|
expect(FocusedMailViewStore.mailView().categoryId()).toEqual(@inboxCategory.id)
|
|
|
|
|
|
|
|
it "should set the current category to Inbox when the current category no longer exists in the CategoryStore", ->
|
|
|
|
otherAccountInbox = @inboxCategory.clone()
|
|
|
|
otherAccountInbox.serverId = 'other-id'
|
|
|
|
FocusedMailViewStore._mailView = MailViewFilter.forCategory(otherAccountInbox)
|
|
|
|
FocusedMailViewStore._onCategoryStoreChanged()
|
|
|
|
expect(FocusedMailViewStore.mailView().categoryId()).toEqual(@inboxCategory.id)
|
|
|
|
|
|
|
|
describe "_onSearchQueryCommitted", ->
|
2015-09-05 06:31:03 +08:00
|
|
|
it "should change to a search mail view when a search query is committed", ->
|
2015-09-05 03:23:15 +08:00
|
|
|
FocusedMailViewStore._onFocusMailView(@userFilter)
|
|
|
|
FocusedMailViewStore._onSearchQueryCommitted('bla')
|
|
|
|
expect(FocusedMailViewStore.trigger).toHaveBeenCalled()
|
2015-09-05 06:31:03 +08:00
|
|
|
expect(FocusedMailViewStore.mailView().isEqual(MailViewFilter.forSearch('bla'))).toBe(true)
|
2015-09-05 03:23:15 +08:00
|
|
|
|
|
|
|
it "should restore the category that was previously focused and trigger when a search query is cleared", ->
|
|
|
|
FocusedMailViewStore._onFocusMailView(@userFilter)
|
|
|
|
FocusedMailViewStore._onSearchQueryCommitted('bla')
|
2015-09-05 06:31:03 +08:00
|
|
|
expect(FocusedMailViewStore.mailView().isEqual(MailViewFilter.forSearch('bla'))).toBe(true)
|
2015-09-05 03:23:15 +08:00
|
|
|
FocusedMailViewStore._onSearchQueryCommitted('')
|
|
|
|
expect(FocusedMailViewStore.trigger).toHaveBeenCalled()
|
|
|
|
expect(FocusedMailViewStore.mailView().categoryId()).toEqual(@userCategory.id)
|
|
|
|
|
|
|
|
describe "_onFocusMailView", ->
|
|
|
|
it "should focus the category and trigger when Actions.focusCategory is called", ->
|
|
|
|
FocusedMailViewStore._onFocusMailView(@userFilter)
|
|
|
|
expect(FocusedMailViewStore.trigger).toHaveBeenCalled()
|
|
|
|
expect(FocusedMailViewStore.mailView().categoryId()).toEqual(@userCategory.id)
|
|
|
|
|
|
|
|
it "should do nothing if the category is already focused", ->
|
|
|
|
FocusedMailViewStore._onFocusMailView(@inboxFilter)
|
|
|
|
spyOn(FocusedMailViewStore, '_setMailView')
|
|
|
|
FocusedMailViewStore._onFocusMailView(@inboxFilter)
|
|
|
|
expect(FocusedMailViewStore._setMailView).not.toHaveBeenCalled()
|
|
|
|
|
2015-09-10 07:04:13 +08:00
|
|
|
it "should clear existing searches if any other category is focused", ->
|
|
|
|
spyOn(Actions, 'searchQueryCommitted')
|
|
|
|
FocusedMailViewStore._onSearchQueryCommitted('bla')
|
|
|
|
FocusedMailViewStore._onFocusMailView(@userFilter)
|
|
|
|
expect(Actions.searchQueryCommitted).toHaveBeenCalledWith('')
|
|
|
|
|
2015-09-05 03:23:15 +08:00
|
|
|
describe 'when using labels', ->
|
|
|
|
beforeEach ->
|
2015-11-12 02:25:11 +08:00
|
|
|
NylasEnv.testOrganizationUnit = 'label'
|
2015-09-05 03:23:15 +08:00
|
|
|
|
|
|
|
@inboxCategory = new Label(id: 'id-123', name: 'inbox', displayName: "INBOX")
|
|
|
|
@inboxFilter = MailViewFilter.forCategory(@inboxCategory)
|
|
|
|
@userCategory = new Label(id: 'id-456', name: null, displayName: "MyCategory")
|
|
|
|
@userFilter = MailViewFilter.forCategory(@userCategory)
|
|
|
|
|
|
|
|
spyOn(CategoryStore, "getStandardCategory").andReturn @inboxCategory
|
|
|
|
spyOn(CategoryStore, "byId").andCallFake (id) =>
|
|
|
|
return @inboxCategory if id is @inboxCategory.id
|
|
|
|
return @userCategory if id is @userCategory.id
|
|
|
|
return null
|
|
|
|
|
|
|
|
testStore()
|
|
|
|
|
|
|
|
describe 'when using folders', ->
|
|
|
|
beforeEach ->
|
2015-11-12 02:25:11 +08:00
|
|
|
NylasEnv.testOrganizationUnit = 'folder'
|
2015-09-05 03:23:15 +08:00
|
|
|
|
|
|
|
@inboxCategory = new Folder(id: 'id-123', name: 'inbox', displayName: "INBOX")
|
|
|
|
@inboxFilter = MailViewFilter.forCategory(@inboxCategory)
|
|
|
|
@userCategory = new Folder(id: 'id-456', name: null, displayName: "MyCategory")
|
|
|
|
@userFilter = MailViewFilter.forCategory(@userCategory)
|
|
|
|
|
|
|
|
spyOn(CategoryStore, "getStandardCategory").andReturn @inboxCategory
|
|
|
|
|
|
|
|
testStore()
|