From 9fc11512ade4a9cc857f5b4d81906070d5f3b1b1 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Mon, 25 Jan 2016 11:07:40 -0800 Subject: [PATCH] CategoryPicker / PerspectiveStore spec fixes --- .../category-picker/lib/category-picker.cjsx | 3 +- .../spec/category-picker-spec.cjsx | 23 +++-- .../focused-perspective-store-spec.coffee | 88 +++++++------------ 3 files changed, 47 insertions(+), 67 deletions(-) diff --git a/internal_packages/category-picker/lib/category-picker.cjsx b/internal_packages/category-picker/lib/category-picker.cjsx index 7536ef39d..6314368d2 100644 --- a/internal_packages/category-picker/lib/category-picker.cjsx +++ b/internal_packages/category-picker/lib/category-picker.cjsx @@ -2,8 +2,7 @@ _ = require 'underscore' React = require 'react' {Utils, - Label, - Folder, + Category, Thread, Actions, TaskQueue, diff --git a/internal_packages/category-picker/spec/category-picker-spec.cjsx b/internal_packages/category-picker/spec/category-picker-spec.cjsx index 6c5e76d76..019a32076 100644 --- a/internal_packages/category-picker/spec/category-picker-spec.cjsx +++ b/internal_packages/category-picker/spec/category-picker-spec.cjsx @@ -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( ) @@ -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( ) @@ -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) diff --git a/spec/stores/focused-perspective-store-spec.coffee b/spec/stores/focused-perspective-store-spec.coffee index 395fa81fd..b8bececc3 100644 --- a/spec/stores/focused-perspective-store-spec.coffee +++ b/spec/stores/focused-perspective-store-spec.coffee @@ -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()