mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
CategoryPicker / PerspectiveStore spec fixes
This commit is contained in:
parent
84ef0e97bf
commit
9fc11512ad
3 changed files with 47 additions and 67 deletions
|
@ -2,8 +2,7 @@ _ = require 'underscore'
|
|||
React = require 'react'
|
||||
|
||||
{Utils,
|
||||
Label,
|
||||
Folder,
|
||||
Category,
|
||||
Thread,
|
||||
Actions,
|
||||
TaskQueue,
|
||||
|
|
|
@ -14,12 +14,13 @@ CategoryPicker = require '../lib/category-picker'
|
|||
TaskFactory,
|
||||
SyncbackCategoryTask,
|
||||
FocusedPerspectiveStore,
|
||||
MailboxPerspective,
|
||||
NylasTestUtils,
|
||||
TaskQueueStatusStore} = require 'nylas-exports'
|
||||
|
||||
{Categories} = require 'nylas-observables'
|
||||
|
||||
describe 'CategoryPicker', ->
|
||||
fdescribe 'CategoryPicker', ->
|
||||
beforeEach ->
|
||||
CategoryStore._categoryCache = {}
|
||||
|
||||
|
@ -34,9 +35,9 @@ describe 'CategoryPicker', ->
|
|||
usesFolders: -> organizationUnit isnt "label"
|
||||
}
|
||||
|
||||
@inboxCategory = new Category(id: 'id-123', name: 'inbox', displayName: "INBOX")
|
||||
@archiveCategory = new Category(id: 'id-456', name: 'archive', displayName: "ArCHIVe")
|
||||
@userCategory = new Category(id: 'id-789', name: null, displayName: "MyCategory")
|
||||
@inboxCategory = new Category(id: 'id-123', name: 'inbox', displayName: "INBOX", accountId: TEST_ACCOUNT_ID)
|
||||
@archiveCategory = new Category(id: 'id-456', name: 'archive', displayName: "ArCHIVe", accountId: TEST_ACCOUNT_ID)
|
||||
@userCategory = new Category(id: 'id-789', name: null, displayName: "MyCategory", accountId: TEST_ACCOUNT_ID)
|
||||
|
||||
spyOn(Categories, "forAccount").andReturn NylasTestUtils.mockObservable(
|
||||
[@inboxCategory, @archiveCategory, @userCategory]
|
||||
|
@ -46,13 +47,13 @@ describe 'CategoryPicker', ->
|
|||
|
||||
# By default we're going to set to "inbox". This has implications for
|
||||
# what categories get filtered out of the list.
|
||||
f = FocusedPerspectiveStore
|
||||
f._setPerspective f._defaultPerspective(@account)
|
||||
spyOn(FocusedPerspectiveStore, 'current').andCallFake =>
|
||||
MailboxPerspective.forCategory(@inboxCategory)
|
||||
|
||||
setupForCreateNew = (orgUnit = "folder") ->
|
||||
setupFor.call(@, orgUnit)
|
||||
|
||||
@testThread = new Thread(id: 't1', subject: "fake")
|
||||
@testThread = new Thread(id: 't1', subject: "fake", accountId: TEST_ACCOUNT_ID)
|
||||
@picker = ReactTestUtils.renderIntoDocument(
|
||||
<CategoryPicker thread={@testThread} />
|
||||
)
|
||||
|
@ -68,7 +69,7 @@ describe 'CategoryPicker', ->
|
|||
beforeEach ->
|
||||
setupFor.call(@, "folder")
|
||||
|
||||
@testThread = new Thread(id: 't1', subject: "fake")
|
||||
@testThread = new Thread(id: 't1', subject: "fake", accountId: TEST_ACCOUNT_ID)
|
||||
@picker = ReactTestUtils.renderIntoDocument(
|
||||
<CategoryPicker thread={@testThread} />
|
||||
)
|
||||
|
@ -77,11 +78,15 @@ describe 'CategoryPicker', ->
|
|||
data = @picker.state.categoryData
|
||||
# NOTE: The inbox category is not included here because it's the
|
||||
# currently focused category, which gets filtered out of the list.
|
||||
expect(data.length).toBe 3
|
||||
|
||||
expect(data[0].id).toBe "id-456"
|
||||
expect(data[0].name).toBe "archive"
|
||||
expect(data[0].category).toBe @archiveCategory
|
||||
|
||||
expect(data[1].divider).toBe true
|
||||
expect(data[1].id).toBe "category-divider"
|
||||
|
||||
expect(data[2].id).toBe "id-789"
|
||||
expect(data[2].name).toBeUndefined()
|
||||
expect(data[2].category).toBe @userCategory
|
||||
|
@ -178,7 +183,7 @@ describe 'CategoryPicker', ->
|
|||
resolveSave = resolve
|
||||
|
||||
spyOn(DatabaseStore, "findBy").andCallFake (klass, {clientId}) ->
|
||||
expect(klass).toBe(Folder)
|
||||
expect(klass).toBe(Category)
|
||||
expect(typeof clientId).toBe("string")
|
||||
Promise.resolve(category)
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
_ = require 'underscore'
|
||||
|
||||
Actions = require '../../src/flux/actions'
|
||||
Label = require '../../src/flux/models/label'
|
||||
Folder = require '../../src/flux/models/folder'
|
||||
Category = require '../../src/flux/models/category'
|
||||
MailboxPerspective = require '../../src/mailbox-perspective'
|
||||
|
||||
CategoryStore = require '../../src/flux/stores/category-store'
|
||||
|
@ -15,62 +14,39 @@ describe "FocusedPerspectiveStore", ->
|
|||
FocusedPerspectiveStore._perspective = null
|
||||
@account = AccountStore.accounts()[0]
|
||||
|
||||
afterEach ->
|
||||
NylasEnv.testOrganizationUnit = null
|
||||
@inboxCategory = new Category(id: 'id-123', name: 'inbox', displayName: "INBOX", accountId: @account.id)
|
||||
@inboxFilter = MailboxPerspective.forCategory(@inboxCategory)
|
||||
@userCategory = new Category(id: 'id-456', name: null, displayName: "MyCategory", accountId: @account.id)
|
||||
@userFilter = MailboxPerspective.forCategory(@userCategory)
|
||||
|
||||
testStore = ->
|
||||
describe "_onCategoryStoreChanged", ->
|
||||
it "should set the current category to Inbox when it is unset", ->
|
||||
FocusedPerspectiveStore._perspective = null
|
||||
FocusedPerspectiveStore._onCategoryStoreChanged()
|
||||
expect(FocusedPerspectiveStore.current()).not.toBe(null)
|
||||
expect(FocusedPerspectiveStore.current().categories()).toEqual([@inboxCategory])
|
||||
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
|
||||
|
||||
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'
|
||||
FocusedPerspectiveStore._perspective = MailboxPerspective.forCategory(otherAccountInbox)
|
||||
FocusedPerspectiveStore._onCategoryStoreChanged()
|
||||
expect(FocusedPerspectiveStore.current().categories()).toEqual([@inboxCategory])
|
||||
describe "_onCategoryStoreChanged", ->
|
||||
it "should set the current category to Inbox when it is unset", ->
|
||||
FocusedPerspectiveStore._perspective = null
|
||||
FocusedPerspectiveStore._onCategoryStoreChanged()
|
||||
expect(FocusedPerspectiveStore.current()).not.toBe(null)
|
||||
expect(FocusedPerspectiveStore.current().categories()).toEqual([@inboxCategory])
|
||||
|
||||
describe "_onFocusPerspective", ->
|
||||
it "should focus the category and trigger when Actions.focusCategory is called", ->
|
||||
FocusedPerspectiveStore._onFocusPerspective(@userFilter)
|
||||
expect(FocusedPerspectiveStore.trigger).toHaveBeenCalled()
|
||||
expect(FocusedPerspectiveStore.current().categories()).toEqual([@userCategory])
|
||||
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'
|
||||
FocusedPerspectiveStore._perspective = MailboxPerspective.forCategory(otherAccountInbox)
|
||||
FocusedPerspectiveStore._onCategoryStoreChanged()
|
||||
expect(FocusedPerspectiveStore.current().categories()).toEqual([@inboxCategory])
|
||||
|
||||
it "should do nothing if the category is already focused", ->
|
||||
FocusedPerspectiveStore._onFocusPerspective(@inboxFilter)
|
||||
spyOn(FocusedPerspectiveStore, '_setPerspective')
|
||||
FocusedPerspectiveStore._onFocusPerspective(@inboxFilter)
|
||||
expect(FocusedPerspectiveStore._setPerspective).not.toHaveBeenCalled()
|
||||
describe "_onFocusPerspective", ->
|
||||
it "should focus the category and trigger when Actions.focusCategory is called", ->
|
||||
FocusedPerspectiveStore._onFocusPerspective(@userFilter)
|
||||
expect(FocusedPerspectiveStore.trigger).toHaveBeenCalled()
|
||||
expect(FocusedPerspectiveStore.current().categories()).toEqual([@userCategory])
|
||||
|
||||
describe 'when using labels', ->
|
||||
beforeEach ->
|
||||
NylasEnv.testOrganizationUnit = 'label'
|
||||
|
||||
@inboxCategory = new Label(id: 'id-123', name: 'inbox', displayName: "INBOX")
|
||||
@inboxFilter = MailboxPerspective.forCategory(@inboxCategory)
|
||||
@userCategory = new Label(id: 'id-456', name: null, displayName: "MyCategory")
|
||||
@userFilter = MailboxPerspective.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 ->
|
||||
NylasEnv.testOrganizationUnit = 'folder'
|
||||
|
||||
@inboxCategory = new Folder(id: 'id-123', name: 'inbox', displayName: "INBOX")
|
||||
@inboxFilter = MailboxPerspective.forCategory(@inboxCategory)
|
||||
@userCategory = new Folder(id: 'id-456', name: null, displayName: "MyCategory")
|
||||
@userFilter = MailboxPerspective.forCategory(@userCategory)
|
||||
|
||||
spyOn(CategoryStore, "getStandardCategory").andReturn @inboxCategory
|
||||
|
||||
testStore()
|
||||
it "should do nothing if the category is already focused", ->
|
||||
FocusedPerspectiveStore._onFocusPerspective(@inboxFilter)
|
||||
spyOn(FocusedPerspectiveStore, '_setPerspective')
|
||||
FocusedPerspectiveStore._onFocusPerspective(@inboxFilter)
|
||||
expect(FocusedPerspectiveStore._setPerspective).not.toHaveBeenCalled()
|
||||
|
|
Loading…
Reference in a new issue