2016-03-01 10:47:22 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
import SpellcheckComposerExtension from '../lib/spellcheck-composer-extension';
|
2016-03-17 10:27:12 +08:00
|
|
|
import {NylasSpellchecker, Message} from 'nylas-exports';
|
2016-03-01 10:47:22 +08:00
|
|
|
|
2016-03-17 10:27:12 +08:00
|
|
|
const initialPath = path.join(__dirname, 'fixtures', 'california-with-misspellings-before.html');
|
|
|
|
const initialHTML = fs.readFileSync(initialPath).toString();
|
2016-09-24 07:34:09 +08:00
|
|
|
const afterPath = path.join(__dirname, 'fixtures', 'california-with-misspellings-after.html');
|
|
|
|
const afterHTML = fs.readFileSync(afterPath).toString();
|
2016-03-01 10:47:22 +08:00
|
|
|
|
2016-05-05 05:03:15 +08:00
|
|
|
describe('SpellcheckComposerExtension', function spellcheckComposerExtension() {
|
2016-03-17 10:27:12 +08:00
|
|
|
beforeEach(() => {
|
2016-03-01 10:47:22 +08:00
|
|
|
// Avoid differences between node-spellcheck on different platforms
|
2016-03-17 10:27:12 +08:00
|
|
|
const lookupPath = path.join(__dirname, 'fixtures', 'california-spelling-lookup.json');
|
|
|
|
const spellings = JSON.parse(fs.readFileSync(lookupPath));
|
|
|
|
spyOn(NylasSpellchecker, 'isMisspelled').andCallFake(word => spellings[word])
|
2016-03-01 10:47:22 +08:00
|
|
|
});
|
|
|
|
|
2016-03-17 10:27:12 +08:00
|
|
|
describe("update", () => {
|
|
|
|
it("correctly walks a DOM tree and surrounds mispelled words", () => {
|
2016-03-01 10:47:22 +08:00
|
|
|
const node = document.createElement('div');
|
|
|
|
node.innerHTML = initialHTML;
|
|
|
|
|
|
|
|
const editor = {
|
|
|
|
rootNode: node,
|
2016-03-17 10:27:12 +08:00
|
|
|
whilePreservingSelection: (cb) => cb(),
|
2016-03-01 10:47:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
SpellcheckComposerExtension.update(editor);
|
2016-09-24 07:34:09 +08:00
|
|
|
expect(node.innerHTML).toEqual(afterHTML);
|
2016-03-01 10:47:22 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-09-24 07:34:09 +08:00
|
|
|
describe("applyTransformsForSending", () => {
|
2016-03-17 10:27:12 +08:00
|
|
|
it("removes the spelling annotations it inserted", () => {
|
2016-09-24 07:34:09 +08:00
|
|
|
const draft = new Message({ body: afterHTML });
|
|
|
|
const fragment = document.createDocumentFragment();
|
|
|
|
const draftBodyRootNode = document.createElement('root')
|
|
|
|
fragment.appendChild(draftBodyRootNode)
|
|
|
|
draftBodyRootNode.innerHTML = afterHTML
|
|
|
|
SpellcheckComposerExtension.applyTransformsForSending({draftBodyRootNode, draft});
|
|
|
|
expect(draftBodyRootNode.innerHTML).toEqual(initialHTML);
|
2016-03-01 10:47:22 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|