Mailspring/app/spec/spellchecker-spec.es6

53 lines
1.8 KiB
Plaintext
Raw Normal View History

/* eslint global-require: 0 */
2017-09-27 02:33:08 +08:00
import fs from 'fs';
import { Spellchecker } from 'mailspring-exports';
2017-09-27 02:33:08 +08:00
describe('Spellchecker', function spellcheckerTests() {
beforeEach(() => {
// 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 = '{}';
spyOn(fs, 'writeFile').andCallFake((path, customDict, cb) => {
2017-09-27 02:33:08 +08:00
this.customDict = customDict;
cb();
});
spyOn(fs, 'readFile').andCallFake((path, cb) => {
2017-09-27 02:33:08 +08:00
cb(null, this.customDict);
});
// Apparently handleElectronSpellCheck returns !misspelled
2017-09-27 02:33:08 +08:00
spyOn(Spellchecker.handler, 'handleElectronSpellCheck').andReturn(false);
Spellchecker.isMisspelledCache = {};
});
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();
});
2017-09-27 02:33:08 +08:00
describe('when a custom word is added', () => {
this.customWord = 'becaause';
beforeEach(() => {
2017-09-27 02:33:08 +08:00
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(true);
Spellchecker.learnWord(this.customWord);
2017-09-27 02:33:08 +08:00
});
afterEach(() => {
Spellchecker.unlearnWord(this.customWord);
2017-09-27 02:33:08 +08:00
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(true);
});
it("doesn't think it's misspelled", () => {
2017-09-27 02:33:08 +08:00
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(false);
});
2017-09-27 02:33:08 +08:00
it('maintains it across instances', () => {
const Spellchecker2 = require('../src/spellchecker').default;
expect(Spellchecker2.isMisspelled(this.customWord)).toEqual(false);
2017-09-27 02:33:08 +08:00
});
});
});