{File, Utils, Thread, Actions, Contact, Message, DraftStore, AccountStore, DatabaseStore, SoundRegistry, SendDraftTask, ChangeMailTask, DestroyDraftTask, ComposerExtension, ExtensionRegistry, FocusedContentStore, DatabaseTransaction, SanitizeTransformer, InlineStyleTransformer} = require 'nylas-exports' ModelQuery = require '../../src/flux/models/query' _ = require 'underscore' {ipcRenderer} = require 'electron' msgFromMe = null fakeThread = null fakeMessages = null fakeMessage1 = null fakeMessage2 = null msgWithReplyTo = null messageWithStyleTags = null fakeMessageWithFiles = null msgWithReplyToDuplicates = null account = null class TestExtension extends ComposerExtension @prepareNewDraft: ({draft}) -> draft.body = "Edited by TestExtension!" + draft.body describe "DraftStore", -> beforeEach -> spyOn(NylasEnv, 'newWindow').andCallFake -> for id, session of DraftStore._draftSessions if session.teardown DraftStore._doneWithSession(session) DraftStore._draftSessions = {} describe "creating drafts", -> beforeEach -> spyOn(DraftStore, "_prepareBodyForQuoting").andCallFake (body) -> Promise.resolve(body) spyOn(ipcRenderer, "send").andCallFake (message, body) -> if message is "inline-style-parse" # There needs to be a defer block in here so the promise # responsible for handling the `inline-style-parse` can be # properly set. If the whole path is synchronous instead of # asynchrounous, the promise is not cleared properly. Doing this # requires us to add `advanceClock` blocks. _.defer -> DraftStore._onInlineStylesResult({}, body) account = AccountStore.accounts()[0] fakeThread = new Thread id: 'fake-thread-id' accountId: account.id subject: 'Fake Subject' fakeMessage1 = new Message id: 'fake-message-1' accountId: account.id to: [new Contact(email: 'ben@nylas.com'), new Contact(email: 'evan@nylas.com')] cc: [new Contact(email: 'mg@nylas.com'), account.me()] bcc: [new Contact(email: 'recruiting@nylas.com')] from: [new Contact(email: 'customer@example.com', name: 'Customer')] threadId: 'fake-thread-id' body: 'Fake Message 1' subject: 'Fake Subject' date: new Date(1415814587) fakeMessage2 = new Message id: 'fake-message-2' accountId: account.id to: [new Contact(email: 'customer@example.com')] from: [new Contact(email: 'ben@nylas.com')] threadId: 'fake-thread-id' body: 'Fake Message 2' subject: 'Re: Fake Subject' date: new Date(1415814587) fakeMessageWithFiles = new Message id: 'fake-message-with-files' accountId: account.id to: [new Contact(email: 'ben@nylas.com'), new Contact(email: 'evan@nylas.com')] cc: [new Contact(email: 'mg@nylas.com'), account.me()] bcc: [new Contact(email: 'recruiting@nylas.com')] from: [new Contact(email: 'customer@example.com', name: 'Customer')] files: [new File(filename: "test.jpg"), new File(filename: "test.pdj")] threadId: 'fake-thread-id' body: 'Fake Message 1' subject: 'Fake Subject' date: new Date(1415814587) msgFromMe = new Message id: 'fake-message-3' accountId: account.id to: [new Contact(email: '1@1.com'), new Contact(email: '2@2.com')] cc: [new Contact(email: '3@3.com'), new Contact(email: '4@4.com')] bcc: [new Contact(email: '5@5.com'), new Contact(email: '6@6.com')] from: [account.me()] threadId: 'fake-thread-id' body: 'Fake Message 2' subject: 'Re: Fake Subject' date: new Date(1415814587) msgWithReplyTo = new Message id: 'fake-message-reply-to' accountId: account.id to: [new Contact(email: '1@1.com'), new Contact(email: '2@2.com')] cc: [new Contact(email: '3@3.com'), new Contact(email: '4@4.com')] bcc: [new Contact(email: '5@5.com'), new Contact(email: '6@6.com')] replyTo: [new Contact(email: 'reply-to@5.com'), new Contact(email: 'reply-to@6.com')] from: [new Contact(email: 'from@5.com')] threadId: 'fake-thread-id' body: 'Fake Message 2' subject: 'Re: Fake Subject' date: new Date(1415814587) msgWithReplyToDuplicates = new Message id: 'fake-message-reply-to-duplicates' accountId: account.id to: [new Contact(email: '1@1.com'), new Contact(email: '2@2.com')] cc: [new Contact(email: '1@1.com'), new Contact(email: '4@4.com')] from: [new Contact(email: 'reply-to@5.com')] replyTo: [new Contact(email: 'reply-to@5.com')] threadId: 'fake-thread-id' body: 'Fake Message Duplicates' subject: 'Re: Fake Subject' date: new Date(1415814587) messageWithStyleTags = new Message id: 'message-with-style-tags' accountId: account.id to: [new Contact(email: 'ben@nylas.com'), new Contact(email: 'evan@nylas.com')] cc: [new Contact(email: 'mg@nylas.com'), account.me()] bcc: [new Contact(email: 'recruiting@nylas.com')] from: [new Contact(email: 'customer@example.com', name: 'Customer')] threadId: 'fake-thread-id' body: '