Mailspring/internal_packages/composer-signature/spec/signature-composer-extension-spec.es6
Annie bd361c8abb refactor(signatures): Removed old signature imgs and made static empty signatures page
Summary:
Refactored signature preferences page to allow more signatures than the previous 1-1 mapping for signatures and accounts. Created a multi select dropdown of the accounts for which a certain signature is set as default for. Added a button into the draft header From field to toggle between saved signatures.

refactor(signatures): Add basic add/remove capabilities to static

refactor(signatures): Hooked up signature actions and signature store for basic functionality

fix(signatures): Cleaned up signature store and started on multiselectdropdown

fix(signatures): Add multi signature toggle select to multiselect dropdown

build(signatures): Built framework for multiselect dropdown

build(signatures): Toggle button functionality for dropdown

build(signatures): Build multi select from components and add debounce

refactor(signatures): Move signature actions and signature store into flux

fix(signatures): Styled composer signatures button/dropdown and fixed preferences checkmarks

build(signatures): Finish main functionality, about to refactor composer signature button into injected component

fix(signatures): Changed position styles

fix(signatures): Fixed background color for dropdown button when blurred

build(signatures): Began to write tests for signatures store, preferences and dropdown

Test Plan: Wrote tests for preferences signatures, signature store, signature composer dropdown and refactored tests for signature composer extension. For signature composer extension I removed applyTransformsToDraft and unapplyTransformsToDraft and tested by sending emails with signatures to different providers to make sure the <signature> tag caused problems.

Reviewers: bengotow, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3073
2016-07-11 12:35:41 -07:00

77 lines
3 KiB
JavaScript

import {Message, SignatureStore} from 'nylas-exports';
import SignatureComposerExtension from '../lib/signature-composer-extension';
const TEST_ID = 1
const TEST_SIGNATURE = {
id: TEST_ID,
title: 'test-sig',
body: '<div class="something">This is my signature.</div>',
}
const TEST_SIGNATURES = {}
TEST_SIGNATURES[TEST_ID] = TEST_SIGNATURE
describe('SignatureComposerExtension', function signatureComposerExtension() {
describe("prepareNewDraft", () => {
describe("when a signature is defined", () => {
beforeEach(() => {
spyOn(NylasEnv.config, 'get').andCallFake(() => TEST_SIGNATURES);
spyOn(SignatureStore, 'signatureForAccountId').andReturn(TEST_SIGNATURE)
SignatureStore.activate()
});
it("should insert the signature at the end of the message or before the first quoted text block and have a newline", () => {
const a = new Message({
draft: true,
accountId: TEST_ACCOUNT_ID,
body: 'This is a test! <div class="gmail_quote">Hello world</div>',
});
const b = new Message({
draft: true,
accountId: TEST_ACCOUNT_ID,
body: 'This is a another test.',
});
SignatureComposerExtension.prepareNewDraft({draft: a});
expect(a.body).toEqual(`This is a test! <signature>${TEST_SIGNATURE.body}</signature><div class="gmail_quote">Hello world</div>`);
SignatureComposerExtension.prepareNewDraft({draft: b});
expect(b.body).toEqual(`This is a another test.<br><br><signature>${TEST_SIGNATURE.body}</signature>`);
});
const scenarios = [
{
name: 'With blockquote',
body: `This is a test! <signature><div>SIG</div></signature><div class="gmail_quote">Hello world</div>`,
expected: `This is a test! <signature>${TEST_SIGNATURE.body}</signature><div class="gmail_quote">Hello world</div>`,
},
{
name: 'Populated signature div',
body: `This is a test! <signature><div>SIG</div></signature>`,
expected: `This is a test! <signature>${TEST_SIGNATURE.body}</signature>`,
},
{
name: 'Empty signature div',
body: 'This is a test! <signature></signature>',
expected: `This is a test! <signature>${TEST_SIGNATURE.body}</signature>`,
},
{
name: 'With newlines',
body: 'This is a test!<br/> <signature>\n<br>\n<div>SIG</div>\n</signature>',
expected: `This is a test!<br/> <signature>${TEST_SIGNATURE.body}</signature>`,
},
]
scenarios.forEach((scenario) => {
it(`should replace the signature if a signature is already present (${scenario.name})`, () => {
const message = new Message({
draft: true,
body: scenario.body,
accountId: TEST_ACCOUNT_ID,
})
SignatureComposerExtension.prepareNewDraft({draft: message});
expect(message.body).toEqual(scenario.expected)
});
});
});
});
});