mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-27 19:07:15 +08:00
149b389508
* 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
141 lines
3.8 KiB
TypeScript
141 lines
3.8 KiB
TypeScript
import {
|
|
Account,
|
|
TaskQueue,
|
|
AccountStore,
|
|
DatabaseStore,
|
|
ComponentRegistry,
|
|
MailboxPerspective,
|
|
FocusedPerspectiveStore,
|
|
} from 'mailspring-exports';
|
|
import { clipboard } from 'electron';
|
|
|
|
import Config from '../../src/config';
|
|
import * as configUtils from '../../src/config-utils';
|
|
import TimeOverride from './time-override';
|
|
import TestConstants from './test-constants';
|
|
import * as jasmineExtensions from './jasmine-extensions';
|
|
|
|
class MasterBeforeEach {
|
|
loadSettings: any;
|
|
|
|
setup(loadSettings, beforeEach) {
|
|
this.loadSettings = loadSettings;
|
|
const self = this;
|
|
|
|
beforeEach(function jasmineBeforeEach() {
|
|
const currentSpec = this;
|
|
currentSpec.addMatchers({
|
|
toHaveLength: jasmineExtensions.toHaveLength,
|
|
});
|
|
|
|
self._resetAppEnv();
|
|
self._resetDatabase();
|
|
self._resetTaskQueue();
|
|
self._resetTimeOverride();
|
|
self._resetAccountStore();
|
|
self._resetConfig();
|
|
self._resetClipboard();
|
|
ComponentRegistry._clear();
|
|
|
|
advanceClock(1000);
|
|
TimeOverride.resetSpyData();
|
|
});
|
|
}
|
|
|
|
_resetAppEnv() {
|
|
// Don't actually write to disk
|
|
spyOn(AppEnv, 'saveWindowState');
|
|
|
|
// prevent specs from modifying N1's menus
|
|
spyOn(AppEnv.menu, 'sendToBrowserProcess');
|
|
|
|
FocusedPerspectiveStore._current = MailboxPerspective.forNothing();
|
|
}
|
|
|
|
_resetDatabase() {
|
|
global.localStorage.clear();
|
|
DatabaseStore._transactionQueue = undefined;
|
|
|
|
// If we don't spy on DatabaseStore._query, then
|
|
// `DatabaseStore.inTransaction` will never complete and cause all
|
|
// tests that depend on transactions to hang.
|
|
//
|
|
// @_query("BEGIN IMMEDIATE TRANSACTION") never resolves because
|
|
// DatabaseStore._query never runs because the @_open flag is always
|
|
// false because we never setup the DB when `AppEnv.inSpecMode` is
|
|
// true.
|
|
spyOn(DatabaseStore, '_query').andCallFake(() => Promise.resolve([]));
|
|
}
|
|
|
|
_resetTaskQueue() {
|
|
TaskQueue._queue = [];
|
|
TaskQueue._completed = [];
|
|
TaskQueue._onlineStatus = true;
|
|
}
|
|
|
|
_resetTimeOverride() {
|
|
TimeOverride.resetTime();
|
|
TimeOverride.enableSpies();
|
|
}
|
|
|
|
_resetAccountStore() {
|
|
// Log in a fake user, and ensure that accountForId, etc. work
|
|
AccountStore._accounts = [
|
|
new Account({
|
|
provider: 'gmail',
|
|
name: TestConstants.TEST_ACCOUNT_NAME,
|
|
emailAddress: TestConstants.TEST_ACCOUNT_EMAIL,
|
|
id: TestConstants.TEST_ACCOUNT_ID,
|
|
aliases: [
|
|
`${TestConstants.TEST_ACCOUNT_NAME} Alternate <${
|
|
TestConstants.TEST_ACCOUNT_ALIAS_EMAIL
|
|
}>`,
|
|
],
|
|
}),
|
|
|
|
new Account({
|
|
provider: 'gmail',
|
|
name: 'Second',
|
|
emailAddress: 'second@gmail.com',
|
|
id: 'second-test-account-id',
|
|
aliases: [
|
|
'Second Support <second@gmail.com>',
|
|
'Second Alternate <second+alternate@gmail.com>',
|
|
'Second <second+third@gmail.com>',
|
|
],
|
|
}),
|
|
];
|
|
}
|
|
|
|
_resetConfig() {
|
|
// reset config before each spec; don't load or save from/to `config.json`
|
|
let fakePersistedConfig = {
|
|
env: 'production',
|
|
};
|
|
|
|
spyOn(Config.prototype, 'getRawValues').andCallFake(() => {
|
|
return fakePersistedConfig;
|
|
});
|
|
|
|
spyOn(Config.prototype, 'setRawValue').andCallFake(function setRawValue(keyPath, value) {
|
|
if (keyPath) {
|
|
configUtils.setValueForKeyPath(fakePersistedConfig, keyPath, value);
|
|
} else {
|
|
fakePersistedConfig = value;
|
|
}
|
|
return this.load();
|
|
});
|
|
|
|
AppEnv.config = new Config();
|
|
AppEnv.loadConfig();
|
|
}
|
|
|
|
_resetClipboard() {
|
|
let clipboardContent = 'initial clipboard content';
|
|
spyOn(clipboard, 'writeText').andCallFake(text => {
|
|
clipboardContent = text;
|
|
});
|
|
spyOn(clipboard, 'readText').andCallFake(() => clipboardContent);
|
|
}
|
|
}
|
|
export default new MasterBeforeEach();
|