Mailspring/app/internal_packages/thread-snooze/specs/snooze-store-spec.es6

117 lines
4.1 KiB
Plaintext
Raw Normal View History

import { AccountStore, CategoryStore, Thread, Actions, Folder } from 'mailspring-exports';
2017-09-27 02:33:08 +08:00
import * as SnoozeUtils from '../lib/snooze-utils';
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404) * Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-05 03:03:12 +08:00
import { SnoozeStore } from '../lib/snooze-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
xdescribe('SnoozeStore', function snoozeStore() {
2016-05-06 13:30:34 +08:00
beforeEach(() => {
2017-09-27 02:33:08 +08:00
this.store = new SnoozeStore('plug-id', 'plug-name');
this.name = 'Snooze folder';
this.accounts = [{ id: 123 }, { id: 321 }];
this.snoozeCatsByAccount = {
2017-09-27 02:33:08 +08:00
123: new Folder({ accountId: 123, displayName: this.name, id: 'sn-1' }),
321: new Folder({ accountId: 321, displayName: this.name, id: 'sn-2' }),
};
this.inboxCatsByAccount = {
2017-09-27 02:33:08 +08:00
123: new Folder({ accountId: 123, name: 'inbox', id: 'in-1' }),
321: new Folder({ accountId: 321, name: 'inbox', id: 'in-2' }),
};
this.threads = [
2017-09-27 02:33:08 +08:00
new Thread({ accountId: 123, id: 's-1' }),
new Thread({ accountId: 123, id: 's-2' }),
new Thread({ accountId: 321, id: 's-3' }),
];
this.updatedThreadsByAccountId = {
2016-05-07 07:23:48 +08:00
123: {
threads: [this.threads[0], this.threads[1]],
snoozeCategoryId: 'sn-1',
returnCategoryId: 'in-1',
},
2016-05-07 07:23:48 +08:00
321: {
threads: [this.threads[2]],
snoozeCategoryId: 'sn-2',
returnCategoryId: 'in-2',
},
2017-09-27 02:33:08 +08:00
};
this.store.snoozeCategoriesPromise = Promise.resolve();
spyOn(this.store, 'recordSnoozeEvent');
spyOn(this.store, 'groupUpdatedThreads').andReturn(
Promise.resolve(this.updatedThreadsByAccountId)
);
2017-09-27 02:33:08 +08:00
spyOn(AccountStore, 'accountsForItems').andReturn(this.accounts);
spyOn(SnoozeUtils, 'moveThreads');
spyOn(Actions, 'closePopover');
2017-09-27 02:36:58 +08:00
spyOn(AppEnv, 'reportError');
spyOn(AppEnv, 'showErrorDialog');
2017-09-27 02:33:08 +08:00
});
2016-05-06 13:30:34 +08:00
describe('groupUpdatedThreads', () => {
it('groups the threads correctly by account id, with their snooze and inbox categories', () => {
Replace Babel with TypeScript compiler, switch entire app to TypeScript 🎉 (#1404) * Switch to using Typescript instead of Babel * Switch all es6 / jsx file extensions to ts / tsx * Convert Utils to a TS module from module.exports style module * Move everything from module.exports to typescript exports * Define .d.ts files for mailspring-exports and component kit… Yes it seems this is the best option :( * Load up on those @types * Synthesize TS types from PropTypes for standard components * Add types to Model classes and move constructor constants to instance vars * 9800 => 7700 TS errors * 7700 => 5600 TS errors * 5600 => 5330 TS errors * 5330 => 4866 TS errors * 4866 => 4426 TS errors * 4426 => 2411 TS errors * 2411 > 1598 TS errors * 1598 > 769 TS errors * 769 > 129 TS errors * 129 > 22 TS errors * Fix runtime errors * More runtime error fixes * Remove support for custom .es6 file extension * Remove a few odd remaining references to Nylas * Don’t ship Typescript support in the compiled app for now * Fix issues in compiled app - module resolution in TS is case sensitive? * README updates * Fix a few more TS errors * Make “No Signature” option clickable + selectable * Remove flicker when saving file and reloading keymaps * Fix mail rule item height in preferences * Fix missing spacing in thread sharing popover * Fix scrollbar ticks being nested incorrectly * Add Japanese as a manually reviewed language * Prevent the thread list from “sticking” * Re-use Sheet when switching root tabs, prevent sidebar from resetting * Ensure specs run * Update package configuration to avoid shpping types * Turn eslint back on - we will opt-in to the TS rules one by one
2019-03-05 03:03:12 +08:00
spyOn(CategoryStore, 'getInboxCategory').andCallFake(
accId => this.inboxCatsByAccount[accId]
);
2016-05-06 13:30:34 +08:00
waitsForPromise(() => {
2017-09-27 02:33:08 +08:00
return this.store
.groupUpdatedThreads(this.threads, this.snoozeCatsByAccount)
.then(result => {
expect(result['123']).toEqual({
threads: [this.threads[0], this.threads[1]],
snoozeCategoryId: 'sn-1',
returnCategoryId: 'in-1',
});
expect(result['321']).toEqual({
threads: [this.threads[2]],
snoozeCategoryId: 'sn-2',
returnCategoryId: 'in-2',
});
});
});
});
});
2016-05-06 13:30:34 +08:00
describe('onSnoozeThreads', () => {
it('calls Actions.queueTask with the correct metadata', () => {
2016-05-06 13:30:34 +08:00
waitsForPromise(() => {
2017-09-27 02:33:08 +08:00
return this.store.onSnoozeThreads(this.threads, 'date', 'label').then(() => {
expect(Actions.queueTask).toHaveBeenCalled();
const task1 = Actions.queueTask.calls[0].args[0];
expect(task1.pluginId).toEqual('plug-id');
expect(task1.modelId).toEqual(this.updatedThreadsByAccountId['123'].threads[0].id);
expect(task1.value).toEqual({
snoozeDate: 'date',
snoozeCategoryId: 'sn-1',
returnCategoryId: 'in-1',
});
const task2 = Actions.queueTask.calls[1].args[0];
expect(task2.pluginId).toEqual('plug-id');
expect(task2.modelId).toEqual(this.updatedThreadsByAccountId['321'].threads[0].id);
expect(task2.value).toEqual({
snoozeDate: 'date',
snoozeCategoryId: 'sn-2',
returnCategoryId: 'in-2',
});
2017-09-27 02:33:08 +08:00
});
});
});
2016-05-06 13:30:34 +08:00
it('displays dialog on error', () => {
2017-09-27 02:33:08 +08:00
jasmine.unspy(SnoozeUtils, 'moveThreads');
spyOn(SnoozeUtils, 'moveThreads').andReturn(Promise.reject(new Error('Oh no!')));
waitsForPromise(async () => {
try {
2017-09-27 02:33:08 +08:00
await this.store.onSnoozeThreads(this.threads, 'date', 'label');
} catch (err) {
//
}
2017-09-27 02:33:08 +08:00
expect(SnoozeUtils.moveThreads).toHaveBeenCalled();
2017-09-27 02:36:58 +08:00
expect(AppEnv.reportError).toHaveBeenCalled();
expect(AppEnv.showErrorDialog).toHaveBeenCalled();
});
});
});
2017-09-27 02:33:08 +08:00
});