Mailspring/internal_packages/composer-spellcheck/spec/spellcheck-composer-extension-spec.es6
Ben Gotow 94badcda15 es6(*): convert 20+ source files used in example packages to ES2016
There could be a few lurking bugs. Please test!
2016-02-29 18:47:22 -08:00

56 lines
1.7 KiB
JavaScript

/* global waitsForPromise */
import fs from 'fs';
import path from 'path';
import SpellcheckComposerExtension from '../lib/spellcheck-composer-extension';
const initialHTML = fs.readFileSync(path.join(__dirname, 'fixtures', 'california-with-misspellings-before.html')).toString();
const expectedHTML = fs.readFileSync(path.join(__dirname, 'fixtures', 'california-with-misspellings-after.html')).toString();
describe("SpellcheckComposerExtension", ()=> {
beforeEach(()=> {
// Avoid differences between node-spellcheck on different platforms
const spellings = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', 'california-spelling-lookup.json')));
spyOn(SpellcheckComposerExtension, 'isMisspelled').andCallFake(word=> spellings[word])
});
describe("update", ()=> {
it("correctly walks a DOM tree and surrounds mispelled words", ()=> {
const node = document.createElement('div');
node.innerHTML = initialHTML;
const editor = {
rootNode: node,
whilePreservingSelection: (cb)=> {
return cb();
},
};
SpellcheckComposerExtension.update(editor);
expect(node.innerHTML).toEqual(expectedHTML);
});
});
describe("finalizeSessionBeforeSending", ()=> {
it("removes the annotations it inserted", ()=> {
const session = {
draft: ()=> {
return {
body: expectedHTML,
};
},
changes: {
add: jasmine.createSpy('add').andReturn(Promise.resolve()),
},
};
waitsForPromise(()=> {
return SpellcheckComposerExtension.finalizeSessionBeforeSending({session}).then(()=> {
expect(session.changes.add).toHaveBeenCalledWith({body: initialHTML});
});
});
});
});
});