mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-29 03:17:47 +08:00
94badcda15
There could be a few lurking bugs. Please test!
55 lines
1.7 KiB
JavaScript
55 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});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|