2016-01-09 06:58:31 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
|
2016-10-28 09:48:33 +08:00
|
|
|
Actions = require('../../src/flux/actions').default
|
2016-10-27 07:01:23 +08:00
|
|
|
Category = require('../../src/flux/models/category').default
|
2016-01-09 06:58:31 +08:00
|
|
|
MailboxPerspective = require '../../src/mailbox-perspective'
|
|
|
|
|
|
|
|
CategoryStore = require '../../src/flux/stores/category-store'
|
fix(spec): add support for async specs and disable misbehaving ones
More spec fixes
replace process.nextTick with setTimeout(fn, 0) for specs
Also added an unspy in the afterEach
Temporarily disable specs
fix(spec): start fixing specs
Summary:
This is the WIP fix to our spec runner.
Several tests have been completely commented out that will require
substantially more work to fix. These have been added to our sprint
backlog.
Other tests have been fixed to update to new APIs or to deal with genuine
bugs that were introduced without our knowing!
The most common non-trivial change relates to observing the `NylasAPI` and
`NylasAPIRequest`. We used to observe the arguments to `makeRequest`.
Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do:
`NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the
`options` passed into the object. the `.object` property grabs the context
of the spy when it was last called.
Fixing these tests uncovered several concerning issues with our test
runner. I spent a while tracking down why our participant-text-field-spec
was failling every so often. I chose that spec because it was the first
spec to likely fail, thereby requiring looking at the least number of
preceding files. I tried binary searching, turning on and off, several
files beforehand only to realize that the failure rate was not determined
by a particular preceding test, but rather the existing and quantity of
preceding tests, AND the number of console.log statements I had. There is
some processor-dependent race condition going on that needs further
investigation.
I also discovered an issue with the file-download-spec. We were getting
errors about it accessing a file, which was very suspicious given the code
stubs out all fs access. This was caused due to a spec that called an
async function outside ot a `waitsForPromise` block or a `waitsFor` block.
The test completed, the spies were cleaned up, but the downstream async
chain was still running. By the time the async chain finished the runner
was already working on the next spec and the spies had been restored
(causing the real fs access to run).
Juan had an idea to kill the specs once one fails to prevent cascading
failures. I'll implement this in the next diff update
Test Plan: npm test
Reviewers: juan, halla, jackie
Differential Revision: https://phab.nylas.com/D3501
Disable other specs
Disable more broken specs
All specs turned off till passing state
Use async-safe versions of spec functions
Add async test spec
Remove unused package code
Remove canary spec
2016-12-13 04:12:20 +08:00
|
|
|
AccountStore = require('../../src/flux/stores/account-store').default
|
2016-10-01 15:08:19 +08:00
|
|
|
FocusedPerspectiveStore = require('../../src/flux/stores/focused-perspective-store').default
|
2016-01-09 06:58:31 +08:00
|
|
|
|
2016-09-22 02:56:54 +08:00
|
|
|
describe "FocusedPerspectiveStore", ->
|
2016-01-09 06:58:31 +08:00
|
|
|
beforeEach ->
|
|
|
|
spyOn(FocusedPerspectiveStore, 'trigger')
|
2016-09-29 05:46:03 +08:00
|
|
|
FocusedPerspectiveStore._current = MailboxPerspective.forNothing()
|
2016-01-12 07:58:10 +08:00
|
|
|
@account = AccountStore.accounts()[0]
|
2016-01-09 06:58:31 +08:00
|
|
|
|
2016-01-26 03:07:40 +08:00
|
|
|
@inboxCategory = new Category(id: 'id-123', name: 'inbox', displayName: "INBOX", accountId: @account.id)
|
2016-04-11 22:59:40 +08:00
|
|
|
@inboxPerspective = MailboxPerspective.forCategory(@inboxCategory)
|
2016-01-26 03:07:40 +08:00
|
|
|
@userCategory = new Category(id: 'id-456', name: null, displayName: "MyCategory", accountId: @account.id)
|
2016-04-11 22:59:40 +08:00
|
|
|
@userPerspective = MailboxPerspective.forCategory(@userCategory)
|
2016-01-26 03:07:40 +08:00
|
|
|
|
2017-06-24 09:01:14 +08:00
|
|
|
spyOn(CategoryStore, "getCategoryByRole").andReturn @inboxCategory
|
2016-09-29 05:46:03 +08:00
|
|
|
spyOn(CategoryStore, "byId").andCallFake (aid, cid) =>
|
|
|
|
return {id: 'A'} if aid is 1 and cid is 'A'
|
|
|
|
return @inboxCategory if cid is @inboxCategory.id
|
|
|
|
return @userCategory if cid is @userCategory.id
|
2016-01-26 03:07:40 +08:00
|
|
|
return null
|
|
|
|
|
2016-09-29 05:46:03 +08:00
|
|
|
describe "_initializeFromSavedState", ->
|
2016-02-10 12:06:48 +08:00
|
|
|
beforeEach ->
|
2016-09-29 05:46:03 +08:00
|
|
|
@default = MailboxPerspective.forCategory(@inboxCategory)
|
|
|
|
spyOn(AccountStore, 'accountIds').andReturn([1, 2])
|
2016-02-10 12:06:48 +08:00
|
|
|
spyOn(MailboxPerspective, 'fromJSON').andCallFake (json) -> json
|
|
|
|
spyOn(FocusedPerspectiveStore, '_defaultPerspective').andReturn @default
|
2016-09-29 05:46:03 +08:00
|
|
|
spyOn(FocusedPerspectiveStore, '_setPerspective')
|
2016-02-10 12:06:48 +08:00
|
|
|
|
|
|
|
it "uses default perspective when no perspective has been saved", ->
|
2016-09-29 05:46:03 +08:00
|
|
|
NylasEnv.savedState.sidebarAccountIds = undefined
|
2016-09-22 02:23:38 +08:00
|
|
|
NylasEnv.savedState.perspective = undefined
|
2016-09-29 05:46:03 +08:00
|
|
|
FocusedPerspectiveStore._initializeFromSavedState()
|
|
|
|
expect(FocusedPerspectiveStore._setPerspective).toHaveBeenCalledWith(@default, @default.accountIds)
|
2016-02-10 12:06:48 +08:00
|
|
|
|
2016-09-29 05:46:03 +08:00
|
|
|
it "uses default if the saved perspective has account ids no longer present", ->
|
|
|
|
NylasEnv.savedState.sidebarAccountIds = [1, 2, 3]
|
|
|
|
NylasEnv.savedState.perspective =
|
|
|
|
accountIds: [1, 2, 3],
|
2016-09-29 06:58:16 +08:00
|
|
|
categories: => [{accountId: 1, id: 'A'}],
|
2016-09-29 05:46:03 +08:00
|
|
|
FocusedPerspectiveStore._initializeFromSavedState()
|
|
|
|
expect(FocusedPerspectiveStore._setPerspective).toHaveBeenCalledWith(@default, @default.accountIds)
|
2016-02-10 12:06:48 +08:00
|
|
|
|
2016-09-29 05:46:03 +08:00
|
|
|
NylasEnv.savedState.sidebarAccountIds = [1, 2, 3]
|
|
|
|
NylasEnv.savedState.perspective =
|
|
|
|
accountIds: [3]
|
2016-09-29 06:58:16 +08:00
|
|
|
categories: => [{accountId: 3, id: 'A'}]
|
2016-09-29 05:46:03 +08:00
|
|
|
FocusedPerspectiveStore._initializeFromSavedState()
|
|
|
|
expect(FocusedPerspectiveStore._setPerspective).toHaveBeenCalledWith(@default, @default.accountIds)
|
2016-02-10 12:06:48 +08:00
|
|
|
|
2016-09-29 05:46:03 +08:00
|
|
|
it "uses default if the saved perspective has category ids no longer present", ->
|
|
|
|
NylasEnv.savedState.sidebarAccountIds = [2]
|
|
|
|
NylasEnv.savedState.perspective =
|
|
|
|
accountIds: [2]
|
2016-09-29 06:58:16 +08:00
|
|
|
categories: => [{accountId: 2, id: 'C'}]
|
2016-09-29 05:46:03 +08:00
|
|
|
FocusedPerspectiveStore._initializeFromSavedState()
|
|
|
|
expect(FocusedPerspectiveStore._setPerspective).toHaveBeenCalledWith(@default, @default.accountIds)
|
2016-02-10 12:06:48 +08:00
|
|
|
|
2016-09-29 05:46:03 +08:00
|
|
|
it "does not honor sidebarAccountIds if it includes account ids no longer present", ->
|
|
|
|
NylasEnv.savedState.sidebarAccountIds = [1, 2, 3]
|
|
|
|
NylasEnv.savedState.perspective =
|
|
|
|
accountIds: [1]
|
2016-09-29 06:58:16 +08:00
|
|
|
categories: => [{accountId: 1, id: 'A'}]
|
2016-09-29 05:46:03 +08:00
|
|
|
FocusedPerspectiveStore._initializeFromSavedState()
|
|
|
|
expect(FocusedPerspectiveStore._setPerspective).toHaveBeenCalledWith(NylasEnv.savedState.perspective, [1])
|
|
|
|
|
|
|
|
it "uses the saved perspective if it is still valid", ->
|
|
|
|
NylasEnv.savedState.sidebarAccountIds = [1, 2]
|
|
|
|
NylasEnv.savedState.perspective =
|
|
|
|
accountIds: [1, 2]
|
2016-09-29 06:58:16 +08:00
|
|
|
categories: => [{accountId: 1, id: 'A'}]
|
2016-09-29 05:46:03 +08:00
|
|
|
FocusedPerspectiveStore._initializeFromSavedState()
|
|
|
|
expect(FocusedPerspectiveStore._setPerspective).toHaveBeenCalledWith(NylasEnv.savedState.perspective, [1, 2])
|
|
|
|
|
|
|
|
NylasEnv.savedState.sidebarAccountIds = [1, 2]
|
|
|
|
NylasEnv.savedState.perspective =
|
|
|
|
accountIds: [1]
|
2016-09-29 06:58:16 +08:00
|
|
|
categories: => []
|
2016-09-29 05:46:03 +08:00
|
|
|
type: 'DraftsMailboxPerspective'
|
|
|
|
|
|
|
|
FocusedPerspectiveStore._initializeFromSavedState()
|
|
|
|
expect(FocusedPerspectiveStore._setPerspective).toHaveBeenCalledWith(NylasEnv.savedState.perspective, [1, 2])
|
|
|
|
|
|
|
|
NylasEnv.savedState.sidebarAccountIds = [1]
|
|
|
|
NylasEnv.savedState.perspective =
|
|
|
|
accountIds: [1]
|
2016-09-29 06:58:16 +08:00
|
|
|
categories: => []
|
2016-09-29 05:46:03 +08:00
|
|
|
type: 'DraftsMailboxPerspective'
|
|
|
|
|
|
|
|
FocusedPerspectiveStore._initializeFromSavedState()
|
|
|
|
expect(FocusedPerspectiveStore._setPerspective).toHaveBeenCalledWith(NylasEnv.savedState.perspective, [1])
|
2016-02-10 12:06:48 +08:00
|
|
|
|
2016-01-26 03:07:40 +08:00
|
|
|
describe "_onCategoryStoreChanged", ->
|
2016-11-18 07:37:44 +08:00
|
|
|
it "should try to initialize if the curernt perspective hasn't been fully initialized", ->
|
2016-09-29 05:46:03 +08:00
|
|
|
spyOn(FocusedPerspectiveStore, '_initializeFromSavedState')
|
|
|
|
|
|
|
|
FocusedPerspectiveStore._current = @inboxPerspective
|
2016-11-18 07:37:44 +08:00
|
|
|
FocusedPerspectiveStore._initialized = true
|
2016-09-29 05:46:03 +08:00
|
|
|
FocusedPerspectiveStore._onCategoryStoreChanged()
|
|
|
|
expect(FocusedPerspectiveStore._initializeFromSavedState).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
FocusedPerspectiveStore._current = MailboxPerspective.forNothing()
|
2016-11-18 07:37:44 +08:00
|
|
|
FocusedPerspectiveStore._initialized = false
|
2016-01-26 03:07:40 +08:00
|
|
|
FocusedPerspectiveStore._onCategoryStoreChanged()
|
2016-09-29 05:46:03 +08:00
|
|
|
expect(FocusedPerspectiveStore._initializeFromSavedState).toHaveBeenCalled()
|
2016-03-25 10:35:24 +08:00
|
|
|
|
2016-04-11 22:59:40 +08:00
|
|
|
it "should set the current category to default when the current category no longer exists in the CategoryStore", ->
|
|
|
|
defaultPerspective = @inboxPerspective
|
2016-11-18 07:37:44 +08:00
|
|
|
FocusedPerspectiveStore._initialized = true
|
2016-04-11 22:59:40 +08:00
|
|
|
spyOn(FocusedPerspectiveStore, '_defaultPerspective').andReturn(defaultPerspective)
|
2016-09-29 05:46:03 +08:00
|
|
|
|
2016-01-26 03:07:40 +08:00
|
|
|
otherAccountInbox = @inboxCategory.clone()
|
2017-06-22 04:12:49 +08:00
|
|
|
otherAccountInbox.id = 'other-id'
|
2016-04-11 22:59:40 +08:00
|
|
|
FocusedPerspectiveStore._current = MailboxPerspective.forCategory(otherAccountInbox)
|
2016-09-29 05:46:03 +08:00
|
|
|
|
2016-01-26 03:07:40 +08:00
|
|
|
FocusedPerspectiveStore._onCategoryStoreChanged()
|
2016-04-11 22:59:40 +08:00
|
|
|
expect(FocusedPerspectiveStore.current()).toEqual(defaultPerspective)
|
2016-01-26 03:07:40 +08:00
|
|
|
|
|
|
|
describe "_onFocusPerspective", ->
|
2016-01-26 08:36:56 +08:00
|
|
|
it "should focus the category and trigger", ->
|
2016-04-11 22:59:40 +08:00
|
|
|
FocusedPerspectiveStore._onFocusPerspective(@userPerspective)
|
2016-01-26 03:07:40 +08:00
|
|
|
expect(FocusedPerspectiveStore.trigger).toHaveBeenCalled()
|
|
|
|
expect(FocusedPerspectiveStore.current().categories()).toEqual([@userCategory])
|
|
|
|
|
2016-05-05 02:50:54 +08:00
|
|
|
describe "_setPerspective", ->
|
|
|
|
it "should not trigger if the perspective is already focused", ->
|
|
|
|
FocusedPerspectiveStore._setPerspective(@inboxPerspective)
|
|
|
|
FocusedPerspectiveStore.trigger.reset()
|
|
|
|
FocusedPerspectiveStore._setPerspective(@inboxPerspective)
|
|
|
|
expect(FocusedPerspectiveStore.trigger).not.toHaveBeenCalled()
|