import {Message} from 'nylas-exports'; import SignatureComposerExtension from '../lib/signature-composer-extension'; describe("SignatureComposerExtension", ()=> { describe("prepareNewDraft", ()=> { describe("when a signature is defined", ()=> { beforeEach(()=> { this.signature = '
This is my signature.
'; spyOn(NylasEnv.config, 'get').andCallFake(()=> this.signature); }); it("should insert the signature at the end of the message or before the first blockquote and have a newline", ()=> { const a = new Message({ draft: true, body: 'This is a test!
Hello world
', }); const b = new Message({ draft: true, body: 'This is a another test.', }); SignatureComposerExtension.prepareNewDraft({draft: a}); expect(a.body).toEqual('This is a test!
This is my signature.
Hello world
'); SignatureComposerExtension.prepareNewDraft({draft: b}); expect(b.body).toEqual('This is a another test.

This is my signature.
'); }); it("should replace the signature if a signature is already present", ()=> { const a = new Message({ draft: true, body: 'This is a test!
SIG
Hello world
', }) const b = new Message({ draft: true, body: 'This is a test!
SIG
', }) const c = new Message({ draft: true, body: 'This is a test!
', }) SignatureComposerExtension.prepareNewDraft({draft: a}); expect(a.body).toEqual(`This is a test!
${this.signature}
Hello world
`); SignatureComposerExtension.prepareNewDraft({draft: b}); expect(b.body).toEqual(`This is a test!
${this.signature}
`); SignatureComposerExtension.prepareNewDraft({draft: c}); expect(c.body).toEqual(`This is a test!
${this.signature}
`); }); }); describe("when a signature is not defined", ()=> { beforeEach(()=> { spyOn(NylasEnv.config, 'get').andCallFake(()=> null); }); it("should not do anything", ()=> { const a = new Message({ draft: true, body: 'This is a test!
Hello world
', }); SignatureComposerExtension.prepareNewDraft({draft: a}); expect(a.body).toEqual('This is a test!
Hello world
'); }); }); }); });