2016-10-07 08:11:50 +08:00
|
|
|
/* eslint global-require: 0 */
|
2017-09-27 02:33:08 +08:00
|
|
|
import fs from 'fs';
|
2017-09-27 02:42:18 +08:00
|
|
|
import { Spellchecker } from 'mailspring-exports';
|
2016-10-07 08:11:50 +08:00
|
|
|
|
2017-09-27 02:33:08 +08:00
|
|
|
describe('Spellchecker', function spellcheckerTests() {
|
2016-10-07 08:11:50 +08:00
|
|
|
beforeEach(() => {
|
2017-02-11 04:26:01 +08:00
|
|
|
// electron-spellchecker is under heavy development, make sure we can still
|
|
|
|
// rely on this method
|
2017-09-27 02:33:08 +08:00
|
|
|
expect(Spellchecker.handler.handleElectronSpellCheck).toBeDefined();
|
|
|
|
this.customDict = '{}';
|
2017-02-11 04:26:01 +08:00
|
|
|
spyOn(fs, 'writeFile').andCallFake((path, customDict, cb) => {
|
2017-09-27 02:33:08 +08:00
|
|
|
this.customDict = customDict;
|
|
|
|
cb();
|
|
|
|
});
|
2017-02-11 04:26:01 +08:00
|
|
|
spyOn(fs, 'readFile').andCallFake((path, cb) => {
|
2017-09-27 02:33:08 +08:00
|
|
|
cb(null, this.customDict);
|
|
|
|
});
|
2017-02-11 04:26:01 +08:00
|
|
|
// Apparently handleElectronSpellCheck returns !misspelled
|
2017-09-27 02:33:08 +08:00
|
|
|
spyOn(Spellchecker.handler, 'handleElectronSpellCheck').andReturn(false);
|
|
|
|
Spellchecker.isMisspelledCache = {};
|
2016-10-07 08:11:50 +08:00
|
|
|
});
|
|
|
|
|
2017-02-11 04:26:01 +08:00
|
|
|
it('does not call spellchecker when word has already been learned', () => {
|
2017-09-27 02:33:08 +08:00
|
|
|
Spellchecker.isMisspelledCache = { mispelled: true };
|
|
|
|
const misspelled = Spellchecker.isMisspelled('mispelled');
|
|
|
|
expect(misspelled).toBe(true);
|
|
|
|
expect(Spellchecker.handler.handleElectronSpellCheck).not.toHaveBeenCalled();
|
2016-10-07 08:11:50 +08:00
|
|
|
});
|
|
|
|
|
2017-09-27 02:33:08 +08:00
|
|
|
describe('when a custom word is added', () => {
|
|
|
|
this.customWord = 'becaause';
|
2016-10-07 08:11:50 +08:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-09-27 02:33:08 +08:00
|
|
|
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(true);
|
2016-10-07 08:11:50 +08:00
|
|
|
Spellchecker.learnWord(this.customWord);
|
2017-09-27 02:33:08 +08:00
|
|
|
});
|
2016-10-07 08:11:50 +08:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Spellchecker.unlearnWord(this.customWord);
|
2017-09-27 02:33:08 +08:00
|
|
|
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(true);
|
|
|
|
});
|
2016-10-07 08:11:50 +08:00
|
|
|
|
|
|
|
it("doesn't think it's misspelled", () => {
|
2017-09-27 02:33:08 +08:00
|
|
|
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(false);
|
|
|
|
});
|
2016-10-07 08:11:50 +08:00
|
|
|
|
2017-09-27 02:33:08 +08:00
|
|
|
it('maintains it across instances', () => {
|
|
|
|
const Spellchecker2 = require('../src/spellchecker').default;
|
2016-10-07 08:11:50 +08:00
|
|
|
expect(Spellchecker2.isMisspelled(this.customWord)).toEqual(false);
|
2017-09-27 02:33:08 +08:00
|
|
|
});
|
|
|
|
});
|
2016-10-07 08:11:50 +08:00
|
|
|
});
|