2016-10-07 08:11:50 +08:00
|
|
|
/* eslint global-require: 0 */
|
2017-02-11 04:26:01 +08:00
|
|
|
import fs from 'fs'
|
2016-10-07 08:11:50 +08:00
|
|
|
import {Spellchecker} from 'nylas-exports';
|
|
|
|
|
2017-01-26 04:26:38 +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
|
|
|
|
expect(Spellchecker.handler.handleElectronSpellCheck).toBeDefined()
|
|
|
|
this.customDict = '{}'
|
|
|
|
spyOn(fs, 'writeFile').andCallFake((path, customDict, cb) => {
|
|
|
|
this.customDict = customDict
|
|
|
|
cb()
|
|
|
|
})
|
|
|
|
spyOn(fs, 'readFile').andCallFake((path, cb) => {
|
|
|
|
cb(null, this.customDict)
|
|
|
|
})
|
|
|
|
// Apparently handleElectronSpellCheck returns !misspelled
|
|
|
|
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', () => {
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
describe("when a custom word is added", () => {
|
2016-10-13 08:06:35 +08:00
|
|
|
this.customWord = "becaause"
|
2016-10-07 08:11:50 +08:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(true)
|
|
|
|
Spellchecker.learnWord(this.customWord);
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Spellchecker.unlearnWord(this.customWord);
|
|
|
|
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("doesn't think it's misspelled", () => {
|
|
|
|
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("maintains it across instances", () => {
|
|
|
|
const Spellchecker2 = require("../src/spellchecker").default;
|
|
|
|
expect(Spellchecker2.isMisspelled(this.customWord)).toEqual(false);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|