2016-03-04 04:37:20 +08:00
|
|
|
import moment from 'moment'
|
|
|
|
import {
|
|
|
|
Actions,
|
|
|
|
TaskQueueStatusStore,
|
|
|
|
TaskFactory,
|
|
|
|
DatabaseStore,
|
|
|
|
Category,
|
|
|
|
Thread,
|
|
|
|
CategoryStore,
|
fix(sync-status): Change old per model status, in favor of per folder
Summary:
Addresses T7275
Previously, we kept track of the sync status of each API model, and the progress
we'd made syncing all available models (e.g. all threads, messages, events, etc)
Given K2's set up, we are now keeping track of sync status per folder, i.e. what
percent of the folder's messages we've synced. This status is now reported from K2
to N1 via folder object deltas, and this commit rewrites the
NylasSyncStatusStore (in ES6) to reflect that.
The new Store keeps the sync state per account, which is the merged state of
per folder sync state, and delta connections state.
We also got rid of `CategoryStore.whenCategoriesReady` in favor of
`whenCategoryListSynced`, which is derived from the fact hat as long as we've
started syncing one folder, we've already synced the entire list of of folders/labels.
There are a couple of TODOs to be addressed in upcoming diffs:
- T7329 Restore the sidebar component to show sync progress, which was previously removed
- T7330 Figure out how to report sync progress per label, specifically, we are interested in knowing how much of the inbox we've synced, which is a label in Gmail. (This might be a non-issue if we sync the inbox very fast, first)
Depends on D3514
Test Plan: Manual
Reviewers: mark, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D3515
2016-12-16 03:07:11 +08:00
|
|
|
NylasSyncStatusStore,
|
2016-03-04 04:37:20 +08:00
|
|
|
} from 'nylas-exports'
|
|
|
|
import SnoozeUtils from '../lib/snooze-utils'
|
|
|
|
|
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
|
|
|
xdescribe('Snooze Utils', function snoozeUtils() {
|
2016-05-06 13:30:34 +08:00
|
|
|
beforeEach(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
this.name = 'Snoozed Folder'
|
|
|
|
this.accId = 123
|
fix(sync-status): Change old per model status, in favor of per folder
Summary:
Addresses T7275
Previously, we kept track of the sync status of each API model, and the progress
we'd made syncing all available models (e.g. all threads, messages, events, etc)
Given K2's set up, we are now keeping track of sync status per folder, i.e. what
percent of the folder's messages we've synced. This status is now reported from K2
to N1 via folder object deltas, and this commit rewrites the
NylasSyncStatusStore (in ES6) to reflect that.
The new Store keeps the sync state per account, which is the merged state of
per folder sync state, and delta connections state.
We also got rid of `CategoryStore.whenCategoriesReady` in favor of
`whenCategoryListSynced`, which is derived from the fact hat as long as we've
started syncing one folder, we've already synced the entire list of of folders/labels.
There are a couple of TODOs to be addressed in upcoming diffs:
- T7329 Restore the sidebar component to show sync progress, which was previously removed
- T7330 Figure out how to report sync progress per label, specifically, we are interested in knowing how much of the inbox we've synced, which is a label in Gmail. (This might be a non-issue if we sync the inbox very fast, first)
Depends on D3514
Test Plan: Manual
Reviewers: mark, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D3515
2016-12-16 03:07:11 +08:00
|
|
|
spyOn(NylasSyncStatusStore, 'whenCategoryListSynced').andReturn(Promise.resolve())
|
2016-03-04 04:37:20 +08:00
|
|
|
})
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('snoozedUntilMessage', () => {
|
|
|
|
it('returns correct message if no snooze date provided', () => {
|
2016-05-06 07:22:44 +08:00
|
|
|
expect(SnoozeUtils.snoozedUntilMessage()).toEqual('Snoozed')
|
2016-03-04 04:37:20 +08:00
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('when less than 24 hours from now', () => {
|
|
|
|
it('returns correct message if snoozeDate is on the hour of the clock', () => {
|
2016-11-06 02:56:23 +08:00
|
|
|
const now9AM = window.testNowMoment().hour(9).minute(0)
|
2016-03-04 04:37:20 +08:00
|
|
|
const tomorrowAt8 = moment(now9AM).add(1, 'day').hour(8)
|
2016-05-06 07:22:44 +08:00
|
|
|
const result = SnoozeUtils.snoozedUntilMessage(tomorrowAt8, now9AM)
|
2016-03-07 08:55:28 +08:00
|
|
|
expect(result).toEqual('Snoozed until 8 AM')
|
2016-03-04 04:37:20 +08:00
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('returns correct message if snoozeDate otherwise', () => {
|
2016-11-06 02:56:23 +08:00
|
|
|
const now9AM = window.testNowMoment().hour(9).minute(0)
|
2016-03-04 04:37:20 +08:00
|
|
|
const snooze10AM = moment(now9AM).hour(10).minute(5)
|
2016-05-06 07:22:44 +08:00
|
|
|
const result = SnoozeUtils.snoozedUntilMessage(snooze10AM, now9AM)
|
2016-03-07 08:55:28 +08:00
|
|
|
expect(result).toEqual('Snoozed until 10:05 AM')
|
2016-03-04 04:37:20 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('when more than 24 hourse from now', () => {
|
|
|
|
it('returns correct message if snoozeDate is on the hour of the clock', () => {
|
2016-03-04 04:37:20 +08:00
|
|
|
// Jan 1
|
2016-11-06 02:56:23 +08:00
|
|
|
const now9AM = window.testNowMoment().month(0).date(1).hour(9).minute(0)
|
2016-03-04 04:37:20 +08:00
|
|
|
const tomorrowAt10 = moment(now9AM).add(1, 'day').hour(10)
|
2016-05-06 07:22:44 +08:00
|
|
|
const result = SnoozeUtils.snoozedUntilMessage(tomorrowAt10, now9AM)
|
2016-03-07 08:55:28 +08:00
|
|
|
expect(result).toEqual('Snoozed until Jan 2, 10 AM')
|
2016-03-04 04:37:20 +08:00
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('returns correct message if snoozeDate otherwise', () => {
|
2016-03-04 04:37:20 +08:00
|
|
|
// Jan 1
|
2016-11-06 02:56:23 +08:00
|
|
|
const now9AM = window.testNowMoment().month(0).date(1).hour(9).minute(0)
|
2016-03-04 04:37:20 +08:00
|
|
|
const tomorrowAt930 = moment(now9AM).add(1, 'day').minute(30)
|
2016-05-06 07:22:44 +08:00
|
|
|
const result = SnoozeUtils.snoozedUntilMessage(tomorrowAt930, now9AM)
|
2016-03-07 08:55:28 +08:00
|
|
|
expect(result).toEqual('Snoozed until Jan 2, 9:30 AM')
|
2016-03-04 04:37:20 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('createSnoozeCategory', () => {
|
|
|
|
beforeEach(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
this.category = new Category({
|
|
|
|
displayName: this.name,
|
|
|
|
accountId: this.accId,
|
|
|
|
clientId: 321,
|
|
|
|
serverId: 321,
|
|
|
|
})
|
|
|
|
spyOn(Actions, 'queueTask')
|
|
|
|
spyOn(TaskQueueStatusStore, 'waitForPerformRemote').andReturn(Promise.resolve())
|
|
|
|
spyOn(DatabaseStore, 'findBy').andReturn(Promise.resolve(this.category))
|
|
|
|
})
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('creates category with correct snooze name', () => {
|
2016-05-06 07:22:44 +08:00
|
|
|
SnoozeUtils.createSnoozeCategory(this.accId, this.name)
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(Actions.queueTask).toHaveBeenCalled()
|
|
|
|
const task = Actions.queueTask.calls[0].args[0]
|
|
|
|
expect(task.category.displayName).toEqual(this.name)
|
|
|
|
expect(task.category.accountId).toEqual(this.accId)
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('resolves with the updated category that has been saved to the server', () => {
|
|
|
|
waitsForPromise(() => {
|
|
|
|
return SnoozeUtils.createSnoozeCategory(this.accId, this.name).then((result) => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(DatabaseStore.findBy).toHaveBeenCalled()
|
|
|
|
expect(result).toBe(this.category)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('rejects if the category could not be found in the database', () => {
|
2016-03-04 04:37:20 +08:00
|
|
|
this.category.serverId = null
|
|
|
|
jasmine.unspy(DatabaseStore, 'findBy')
|
|
|
|
spyOn(DatabaseStore, 'findBy').andReturn(Promise.resolve(this.category))
|
2016-05-06 13:30:34 +08:00
|
|
|
waitsForPromise(() => {
|
2016-05-06 07:22:44 +08:00
|
|
|
return SnoozeUtils.createSnoozeCategory(this.accId, this.name)
|
2016-05-06 13:30:34 +08:00
|
|
|
.then(() => {
|
2016-05-06 07:22:44 +08:00
|
|
|
throw new Error('SnoozeUtils.createSnoozeCategory should not resolve in this case!')
|
2016-03-04 04:37:20 +08:00
|
|
|
})
|
2016-05-06 13:30:34 +08:00
|
|
|
.catch((error) => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(DatabaseStore.findBy).toHaveBeenCalled()
|
|
|
|
expect(error.message).toEqual('Could not create Snooze category')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('rejects if the category could not be saved to the server', () => {
|
2016-03-04 04:37:20 +08:00
|
|
|
jasmine.unspy(DatabaseStore, 'findBy')
|
|
|
|
spyOn(DatabaseStore, 'findBy').andReturn(Promise.resolve(undefined))
|
2016-05-06 13:30:34 +08:00
|
|
|
waitsForPromise(() => {
|
2016-05-06 07:22:44 +08:00
|
|
|
return SnoozeUtils.createSnoozeCategory(this.accId, this.name)
|
2016-05-06 13:30:34 +08:00
|
|
|
.then(() => {
|
2016-05-06 07:22:44 +08:00
|
|
|
throw new Error('SnoozeUtils.createSnoozeCategory should not resolve in this case!')
|
2016-03-04 04:37:20 +08:00
|
|
|
})
|
2016-05-06 13:30:34 +08:00
|
|
|
.catch((error) => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(DatabaseStore.findBy).toHaveBeenCalled()
|
|
|
|
expect(error.message).toEqual('Could not create Snooze category')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('getSnoozeCategory', () => {
|
|
|
|
it('resolves category if it exists in the category store', () => {
|
2016-03-04 04:37:20 +08:00
|
|
|
const categories = [
|
|
|
|
new Category({accountId: this.accId, name: 'inbox'}),
|
|
|
|
new Category({accountId: this.accId, displayName: this.name}),
|
|
|
|
]
|
|
|
|
spyOn(CategoryStore, 'categories').andReturn(categories)
|
|
|
|
spyOn(SnoozeUtils, 'createSnoozeCategory')
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
waitsForPromise(() => {
|
2016-05-06 07:22:44 +08:00
|
|
|
return SnoozeUtils.getSnoozeCategory(this.accountId, this.name)
|
2016-05-06 13:30:34 +08:00
|
|
|
.then((result) => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(SnoozeUtils.createSnoozeCategory).not.toHaveBeenCalled()
|
|
|
|
expect(result).toBe(categories[1])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('creates category if it does not exist', () => {
|
2016-03-04 04:37:20 +08:00
|
|
|
const categories = [
|
|
|
|
new Category({accountId: this.accId, name: 'inbox'}),
|
|
|
|
]
|
|
|
|
const snoozeCat = new Category({accountId: this.accId, displayName: this.name})
|
|
|
|
spyOn(CategoryStore, 'categories').andReturn(categories)
|
|
|
|
spyOn(SnoozeUtils, 'createSnoozeCategory').andReturn(Promise.resolve(snoozeCat))
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
waitsForPromise(() => {
|
2016-05-06 07:22:44 +08:00
|
|
|
return SnoozeUtils.getSnoozeCategory(this.accId, this.name)
|
2016-05-06 13:30:34 +08:00
|
|
|
.then((result) => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(SnoozeUtils.createSnoozeCategory).toHaveBeenCalledWith(this.accId, this.name)
|
|
|
|
expect(result).toBe(snoozeCat)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
describe('moveThreads', () => {
|
|
|
|
beforeEach(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
this.description = 'Snoozin';
|
|
|
|
this.snoozeCatsByAccount = {
|
2016-05-07 07:06:16 +08:00
|
|
|
123: new Category({accountId: 123, displayName: this.name, serverId: 'sr-1'}),
|
|
|
|
321: new Category({accountId: 321, displayName: this.name, serverId: 'sr-2'}),
|
2016-03-04 04:37:20 +08:00
|
|
|
}
|
|
|
|
this.inboxCatsByAccount = {
|
2016-05-07 07:06:16 +08:00
|
|
|
123: new Category({accountId: 123, name: 'inbox', serverId: 'sr-3'}),
|
|
|
|
321: new Category({accountId: 321, name: 'inbox', serverId: 'sr-4'}),
|
2016-03-04 04:37:20 +08:00
|
|
|
}
|
|
|
|
this.threads = [
|
|
|
|
new Thread({accountId: 123}),
|
|
|
|
new Thread({accountId: 123}),
|
|
|
|
new Thread({accountId: 321}),
|
|
|
|
]
|
2016-03-08 10:13:53 +08:00
|
|
|
this.getInboxCat = (accId) => [this.inboxCatsByAccount[accId]]
|
|
|
|
this.getSnoozeCat = (accId) => [this.snoozeCatsByAccount[accId]]
|
2016-03-04 04:37:20 +08:00
|
|
|
|
|
|
|
spyOn(DatabaseStore, 'modelify').andReturn(Promise.resolve(this.threads))
|
|
|
|
spyOn(TaskFactory, 'tasksForApplyingCategories').andReturn([])
|
|
|
|
spyOn(TaskQueueStatusStore, 'waitForPerformRemote').andReturn(Promise.resolve())
|
|
|
|
spyOn(Actions, 'queueTasks')
|
|
|
|
})
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('creates the tasks to move threads correctly when snoozing', () => {
|
2016-03-04 04:37:20 +08:00
|
|
|
const snooze = true
|
|
|
|
const description = this.description
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
waitsForPromise(() => {
|
2016-05-06 07:22:44 +08:00
|
|
|
return SnoozeUtils.moveThreads(this.threads, {snooze, description, getInboxCategory: this.getInboxCat, getSnoozeCategory: this.getSnoozeCat})
|
2016-05-06 13:30:34 +08:00
|
|
|
.then(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(TaskFactory.tasksForApplyingCategories).toHaveBeenCalled()
|
|
|
|
expect(Actions.queueTasks).toHaveBeenCalled()
|
2016-03-08 10:13:53 +08:00
|
|
|
const {threads, categoriesToAdd, categoriesToRemove, taskDescription} = TaskFactory.tasksForApplyingCategories.calls[0].args[0]
|
|
|
|
expect(threads).toBe(this.threads)
|
|
|
|
expect(categoriesToRemove('123')[0]).toBe(this.inboxCatsByAccount['123'])
|
|
|
|
expect(categoriesToRemove('321')[0]).toBe(this.inboxCatsByAccount['321'])
|
|
|
|
expect(categoriesToAdd('123')[0]).toBe(this.snoozeCatsByAccount['123'])
|
|
|
|
expect(categoriesToAdd('321')[0]).toBe(this.snoozeCatsByAccount['321'])
|
|
|
|
expect(taskDescription).toEqual(description)
|
2016-03-04 04:37:20 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
it('creates the tasks to move threads correctly when unsnoozing', () => {
|
2016-03-04 04:37:20 +08:00
|
|
|
const snooze = false
|
|
|
|
const description = this.description
|
|
|
|
|
2016-05-06 13:30:34 +08:00
|
|
|
waitsForPromise(() => {
|
2016-05-06 07:22:44 +08:00
|
|
|
return SnoozeUtils.moveThreads(this.threads, {snooze, description, getInboxCategory: this.getInboxCat, getSnoozeCategory: this.getSnoozeCat})
|
2016-05-06 13:30:34 +08:00
|
|
|
.then(() => {
|
2016-03-04 04:37:20 +08:00
|
|
|
expect(TaskFactory.tasksForApplyingCategories).toHaveBeenCalled()
|
|
|
|
expect(Actions.queueTasks).toHaveBeenCalled()
|
2016-03-08 10:13:53 +08:00
|
|
|
const {threads, categoriesToAdd, categoriesToRemove, taskDescription} = TaskFactory.tasksForApplyingCategories.calls[0].args[0]
|
|
|
|
expect(threads).toBe(this.threads)
|
|
|
|
expect(categoriesToAdd('123')[0]).toBe(this.inboxCatsByAccount['123'])
|
|
|
|
expect(categoriesToAdd('321')[0]).toBe(this.inboxCatsByAccount['321'])
|
|
|
|
expect(categoriesToRemove('123')[0]).toBe(this.snoozeCatsByAccount['123'])
|
|
|
|
expect(categoriesToRemove('321')[0]).toBe(this.snoozeCatsByAccount['321'])
|
|
|
|
expect(taskDescription).toEqual(description)
|
2016-03-04 04:37:20 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|