mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 21:57:55 +08:00
466bca813b
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
62 lines
2.6 KiB
JavaScript
62 lines
2.6 KiB
JavaScript
import OpenTrackingComposerExtension from '../lib/open-tracking-composer-extension'
|
|
import {PLUGIN_ID, PLUGIN_URL} from '../lib/open-tracking-constants';
|
|
import {Message, QuotedHTMLTransformer} from 'nylas-exports';
|
|
|
|
const quote = `<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> On Feb 25 2016, at 3:38 pm, Drew <drew@nylas.com> wrote: <br> twst </blockquote>`;
|
|
|
|
describe("Open tracking composer extension", () => {
|
|
// Set up a draft, session that returns the draft, and metadata
|
|
beforeEach(() => {
|
|
this.draft = new Message({
|
|
body: `<head></head><body>TEST_BODY ${quote}</body>`,
|
|
});
|
|
});
|
|
|
|
describe("applyTransformsToDraft", () => {
|
|
it("takes no action if there is no metadata", () => {
|
|
const out = OpenTrackingComposerExtension.applyTransformsToDraft({draft: this.draft});
|
|
expect(out.body).toEqual(this.draft.body);
|
|
});
|
|
|
|
it("reports an error if the metadata is missing required fields", () => {
|
|
this.draft.applyPluginMetadata(PLUGIN_ID, {});
|
|
spyOn(NylasEnv, "reportError");
|
|
OpenTrackingComposerExtension.applyTransformsToDraft({draft: this.draft});
|
|
expect(NylasEnv.reportError).toHaveBeenCalled()
|
|
});
|
|
|
|
describe("With properly formatted metadata and correct params", () => {
|
|
beforeEach(() => {
|
|
this.metadata = {uid: "TEST_UID"};
|
|
this.draft.applyPluginMetadata(PLUGIN_ID, this.metadata);
|
|
const out = OpenTrackingComposerExtension.applyTransformsToDraft({draft: this.draft});
|
|
this.unquoted = QuotedHTMLTransformer.removeQuotedHTML(out.body);
|
|
});
|
|
|
|
it("appends an image to the unquoted body", () => {
|
|
expect(this.unquoted).toMatch(/<img .*?>/);
|
|
});
|
|
|
|
it("has the right server URL", () => {
|
|
const img = this.unquoted.match(/<img .*?>/)[0];
|
|
expect(img).toContain(`${PLUGIN_URL}/open/${this.draft.accountId}/${this.metadata.uid}`);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("unapplyTransformsToDraft", () => {
|
|
it("takes no action if the img tag is missing", () => {
|
|
const out = OpenTrackingComposerExtension.unapplyTransformsToDraft({draft: this.draft});
|
|
expect(out.body).toEqual(this.draft.body);
|
|
});
|
|
|
|
it("removes the image from the body and restore the body to it's exact original content", () => {
|
|
this.metadata = {uid: "TEST_UID"};
|
|
this.draft.applyPluginMetadata(PLUGIN_ID, this.metadata);
|
|
const withImg = OpenTrackingComposerExtension.applyTransformsToDraft({draft: this.draft});
|
|
|
|
const withoutImg = OpenTrackingComposerExtension.unapplyTransformsToDraft({draft: withImg});
|
|
expect(withoutImg.body).toEqual(this.draft.body);
|
|
});
|
|
});
|
|
});
|