mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-24 09:16:07 +08:00
96c70368c4
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
57 lines
1.8 KiB
JavaScript
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});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|