2016-10-07 08:11:50 +08:00
|
|
|
|
/* eslint global-require: 0 */
|
|
|
|
|
import {Spellchecker} from 'nylas-exports';
|
|
|
|
|
|
|
|
|
|
describe("Spellchecker", function spellcheckerTests() {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
Spellchecker.handler.switchLanguage('en-US'); // Start with US English
|
2016-11-10 07:07:30 +08:00
|
|
|
|
});
|
2016-10-07 08:11:50 +08:00
|
|
|
|
|
2016-11-10 07:07:30 +08:00
|
|
|
|
// Note, on Linux, calling provideHintText can result in a Hunspell dictionary
|
|
|
|
|
// being downloaded. Typically this is fast but if this causes intermittent
|
|
|
|
|
// failures we should disable these specs on Linux.
|
|
|
|
|
[
|
|
|
|
|
{name: "French", code: "fr", sentence: "Ceci est une phrase avec quelques mots."},
|
|
|
|
|
{name: "German", code: "de", sentence: "Das ist ein Satz mit einigen Worten."},
|
|
|
|
|
{name: "Italian", code: "it", sentence: "Questa è una frase con alcune parole."},
|
|
|
|
|
{name: "Russian", code: "ru", sentence: "Это предложение с некоторыми словами."},
|
|
|
|
|
{name: "Spanish", code: "es", sentence: "Esta es una oración con algunas palabras."},
|
|
|
|
|
// English shouldn't be first since we start out as English.
|
|
|
|
|
{name: "English", code: "en", sentence: "This is a sentence with some words."},
|
|
|
|
|
].forEach(({name, code, sentence}) => {
|
|
|
|
|
it(`properly detects language when given a full sentence (${name})`, () => {
|
|
|
|
|
waitsForPromise(() =>
|
|
|
|
|
Spellchecker.handler.provideHintText(sentence)
|
|
|
|
|
)
|
2016-10-07 08:11:50 +08:00
|
|
|
|
runs(() => {
|
2016-11-10 07:07:30 +08:00
|
|
|
|
expect(Spellchecker.handler.currentSpellcheckerLanguage.startsWith(code)).toEqual(true)
|
2016-10-07 08:11:50 +08:00
|
|
|
|
})
|
2016-11-10 07:07:30 +08:00
|
|
|
|
});
|
2016-10-07 08:11:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("knows whether a word is misspelled or not", () => {
|
|
|
|
|
const correctlySpelled = ["hello", "world", "create", "goodbye", "regards"]
|
2016-10-13 08:06:35 +08:00
|
|
|
|
const misspelled = ["mispelled", "particularily", "kelfiekd", "adlkdgiekdl"]
|
2016-10-07 08:11:50 +08:00
|
|
|
|
for (const word of correctlySpelled) {
|
|
|
|
|
expect(Spellchecker.isMisspelled(word)).toEqual(false);
|
|
|
|
|
}
|
|
|
|
|
for (const word of misspelled) {
|
|
|
|
|
expect(Spellchecker.isMisspelled(word)).toEqual(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("provides suggestions for misspelled words", () => {
|
|
|
|
|
const suggestions = Spellchecker.handler.currentSpellchecker.getCorrectionsForMisspelling("mispelled")
|
|
|
|
|
expect(suggestions.length > 0).toEqual(true);
|
|
|
|
|
expect(suggestions[0]).toEqual('misspelled');
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
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 when switching languages", () => {
|
|
|
|
|
Spellchecker.handler.switchLanguage("de-DE")
|
|
|
|
|
expect(Spellchecker.isMisspelled(this.customWord)).toEqual(false);
|
|
|
|
|
Spellchecker.handler.switchLanguage("en-US")
|
|
|
|
|
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);
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
});
|