Mailspring/internal_packages/composer-spellcheck/spec/spellcheck-composer-extension-spec.es6
Ben Gotow 96c70368c4 fix(spellcheck): Enables spellcheck menu for basic inputs (#1600)
Summary: Just moves some code so we can easily attach spelling menus to the basic inputs.

Test Plan: Updated existing tests

Reviewers: juan, drew

Reviewed By: drew

Differential Revision: https://phab.nylas.com/D2721
2016-03-14 10:23:57 -07:00

57 lines
1.8 KiB
JavaScript

/* global waitsForPromise */
import fs from 'fs';
import path from 'path';
import SpellcheckComposerExtension from '../lib/spellcheck-composer-extension';
import {NylasSpellchecker} from 'nylas-exports';
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(NylasSpellchecker, '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});
});
});
});
});
});