Mailspring/internal_packages/composer-spellcheck/spec/spellcheck-composer-extension-spec.es6
Ben Gotow 466bca813b fix(syncback): Bidirectional transforms, ready-to-send saved state
Summary:
This diff replaces "finalizeSessionBeforeSending" with a
plugin hook that is bidirectional and allows us to put the draft in
the "ready to send" state every time we save it, and restore it to
the "ready to edit" state every time a draft session is created to
edit it.

This diff also significantly restructures the draft tasks:

1. SyncbackDraftUploadsTask:
   - ensures that `uploads` are converted to `files` and that any
     existing files on the draft are part of the correct account.

1. SyncbackDraftTask:
   - saves the draft, nothing else.

3. SendDraftTask
   - sends the draft, nothing else.
   - deletes the entire uploads directory for the draft

Test Plan: WIP

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2753
2016-03-16 19:27:12 -07:00

52 lines
1.9 KiB
JavaScript

/* global waitsForPromise */
import fs from 'fs';
import path from 'path';
import SpellcheckComposerExtension from '../lib/spellcheck-composer-extension';
import {NylasSpellchecker, Message} from 'nylas-exports';
const initialPath = path.join(__dirname, 'fixtures', 'california-with-misspellings-before.html');
const initialHTML = fs.readFileSync(initialPath).toString();
const expectedPath = path.join(__dirname, 'fixtures', 'california-with-misspellings-after.html');
const expectedHTML = fs.readFileSync(expectedPath).toString();
describe("SpellcheckComposerExtension", () => {
beforeEach(() => {
// Avoid differences between node-spellcheck on different platforms
const lookupPath = path.join(__dirname, 'fixtures', 'california-spelling-lookup.json');
const spellings = JSON.parse(fs.readFileSync(lookupPath));
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) => cb(),
};
SpellcheckComposerExtension.update(editor);
expect(node.innerHTML).toEqual(expectedHTML);
});
});
describe("applyTransformsToDraft", () => {
it("removes the spelling annotations it inserted", () => {
const draft = new Message({ body: expectedHTML });
const out = SpellcheckComposerExtension.applyTransformsToDraft({draft});
expect(out.body).toEqual(initialHTML);
});
});
describe("unapplyTransformsToDraft", () => {
it("returns the magic no-op option", () => {
const draft = new Message({ body: expectedHTML });
const out = SpellcheckComposerExtension.unapplyTransformsToDraft({draft});
expect(out).toEqual('unnecessary');
});
});
});