Mailspring/spec-nylas/stores/draft-store-spec.coffee

768 lines
31 KiB
CoffeeScript
Raw Normal View History

Thread = require '../../src/flux/models/thread'
Message = require '../../src/flux/models/message'
Contact = require '../../src/flux/models/contact'
ModelQuery = require '../../src/flux/models/query'
AccountStore = require '../../src/flux/stores/account-store'
DatabaseStore = require '../../src/flux/stores/database-store'
DraftStore = require '../../src/flux/stores/draft-store'
feat(signatures): Initial signature support Summary: - Draft Store extensions can now implement `prepareNewDraft` to have an opportunity to change a draft before it's displayed for the first time. - When composers are torn down, they delete their draft if it is still pristine. This makes the behavior of closing unedited popout drafts the same as leaving unedited inline drafts. - The DraftStoreProxy keeps the initial body of the draft *if* it started in a pristine state. This means "is the body empty" is just a simple == check, and it takes into account anything added to the body by extensions. - Calling Actions.destroyDraft doesn't blow up anymore if the draft session can't be found. This was a bug and meant that you couldn't destroy drafts which hadn't been previously edited, and also meant that bad things(tm) happened when you called destroyDraft twice, which seemed like overkill. - DestroyDraft task now exits gracefully when the draft cannot be found. You can test this feature by adding the following to your config.cson: ``` signatures: NAMESPACEID: "<br/><br/><div id=\"Signature\"><div id=\"divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\"><p></p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450\" style=\"font-family:'Times New Roman'; table-layout:fixed\"><tbody><tr><td class=\"logo-td\" align=\"left\" valign=\"top\" width=\"76\"><p style=\"margin-bottom:10px; margin-right:10px; font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px\"><a href=\"http://www.nylas.com/\" class=\"clink logo-container\" style=\"text-decoration:none\"><img alt=\"Nylas\" border=\"0\" class=\"sig-logo\" height=\"80\" width=\"66\" style=\"-webkit-user-select: none;\" src=\"https://s3-us-west-2.amazonaws.com/nylas-static-assets/nylas-email-signature.png\"></a></p><p class=\"social-list\" style=\"font-size:0px; line-height:0; font-family:Helvetica,Arial,sans-serif\"></p></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"spacer-td\" width=\"16\" style=\"border-left-width:2px; border-left-style:solid; border-left-color:rgb(30,162,162)\"><img width=\"10\" style=\"-webkit-user-select: none;\" src=\"https://s3.amazonaws.com/htmlsig-assets/spacer.gif\"></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"content-td\" width=\"368\"><div class=\"content-pad\"><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; color:rgb(33,33,33); margin-bottom:10px\"><span class=\"txt signature_name-target sig-hide\" style=\"font-weight:bold; display:inline\">Gleb Polyakov</span>&nbsp;<span class=\"email-sep break\" style=\"display:inline\"><br></span><a class=\"link email signature_email-target sig-hide\" href=\"mailto:gleb@nylas.com\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">gleb@nylas.com</a><span class=\"signature_email-sep sep\" style=\"display:inline\">&nbsp;/&nbsp;</span><span class=\"txt signature_mobilephone-target sig-hide\" style=\"display:inline\">404-786-4100</span></p><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; margin-bottom:10px\"><span class=\"txt signature_companyname-target sig-hide\" style=\"font-weight:bold; color:rgb(33,33,33); display:inline\">Nylas</span>&nbsp;<span class=\"company-sep break\" style=\"display:inline\"><br></span><span class=\"address-sep break\"></span><span class=\"address2-sep break\"></span><span class=\"website-sep break\"></span><a class=\"link signature_website-target sig-hide\" href=\"http://www.nylas.com/\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">http://www.nylas.com</a></p></div></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"><p class=\"txt signature_disclaimer-target\" style=\"font-family:Helvetica,Arial,sans-serif; color:rgb(33,33,33); font-size:9px; line-height:12px; margin-top:10px\"></p></td></tr></tbody></table><p></p></div></div>" ``` specs for draft store extension hooks, some draft store refactoring Test Plan: Run a few new specs that make sure extensions are run Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1741
2015-07-15 03:20:06 +08:00
DraftStoreExtension = require '../../src/flux/stores/draft-store-extension'
TaskQueue = require '../../src/flux/stores/task-queue'
SendDraftTask = require '../../src/flux/tasks/send-draft'
DestroyDraftTask = require '../../src/flux/tasks/destroy-draft'
Actions = require '../../src/flux/actions'
Utils = require '../../src/flux/models/utils'
_ = require 'underscore'
fakeThread = null
fakeMessage1 = null
fakeMessage2 = null
msgFromMe = null
msgWithReplyTo = null
msgWithReplyToDuplicates = null
fakeMessages = null
feat(signatures): Initial signature support Summary: - Draft Store extensions can now implement `prepareNewDraft` to have an opportunity to change a draft before it's displayed for the first time. - When composers are torn down, they delete their draft if it is still pristine. This makes the behavior of closing unedited popout drafts the same as leaving unedited inline drafts. - The DraftStoreProxy keeps the initial body of the draft *if* it started in a pristine state. This means "is the body empty" is just a simple == check, and it takes into account anything added to the body by extensions. - Calling Actions.destroyDraft doesn't blow up anymore if the draft session can't be found. This was a bug and meant that you couldn't destroy drafts which hadn't been previously edited, and also meant that bad things(tm) happened when you called destroyDraft twice, which seemed like overkill. - DestroyDraft task now exits gracefully when the draft cannot be found. You can test this feature by adding the following to your config.cson: ``` signatures: NAMESPACEID: "<br/><br/><div id=\"Signature\"><div id=\"divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\"><p></p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450\" style=\"font-family:'Times New Roman'; table-layout:fixed\"><tbody><tr><td class=\"logo-td\" align=\"left\" valign=\"top\" width=\"76\"><p style=\"margin-bottom:10px; margin-right:10px; font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px\"><a href=\"http://www.nylas.com/\" class=\"clink logo-container\" style=\"text-decoration:none\"><img alt=\"Nylas\" border=\"0\" class=\"sig-logo\" height=\"80\" width=\"66\" style=\"-webkit-user-select: none;\" src=\"https://s3-us-west-2.amazonaws.com/nylas-static-assets/nylas-email-signature.png\"></a></p><p class=\"social-list\" style=\"font-size:0px; line-height:0; font-family:Helvetica,Arial,sans-serif\"></p></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"spacer-td\" width=\"16\" style=\"border-left-width:2px; border-left-style:solid; border-left-color:rgb(30,162,162)\"><img width=\"10\" style=\"-webkit-user-select: none;\" src=\"https://s3.amazonaws.com/htmlsig-assets/spacer.gif\"></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"content-td\" width=\"368\"><div class=\"content-pad\"><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; color:rgb(33,33,33); margin-bottom:10px\"><span class=\"txt signature_name-target sig-hide\" style=\"font-weight:bold; display:inline\">Gleb Polyakov</span>&nbsp;<span class=\"email-sep break\" style=\"display:inline\"><br></span><a class=\"link email signature_email-target sig-hide\" href=\"mailto:gleb@nylas.com\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">gleb@nylas.com</a><span class=\"signature_email-sep sep\" style=\"display:inline\">&nbsp;/&nbsp;</span><span class=\"txt signature_mobilephone-target sig-hide\" style=\"display:inline\">404-786-4100</span></p><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; margin-bottom:10px\"><span class=\"txt signature_companyname-target sig-hide\" style=\"font-weight:bold; color:rgb(33,33,33); display:inline\">Nylas</span>&nbsp;<span class=\"company-sep break\" style=\"display:inline\"><br></span><span class=\"address-sep break\"></span><span class=\"address2-sep break\"></span><span class=\"website-sep break\"></span><a class=\"link signature_website-target sig-hide\" href=\"http://www.nylas.com/\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">http://www.nylas.com</a></p></div></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"><p class=\"txt signature_disclaimer-target\" style=\"font-family:Helvetica,Arial,sans-serif; color:rgb(33,33,33); font-size:9px; line-height:12px; margin-top:10px\"></p></td></tr></tbody></table><p></p></div></div>" ``` specs for draft store extension hooks, some draft store refactoring Test Plan: Run a few new specs that make sure extensions are run Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1741
2015-07-15 03:20:06 +08:00
class TestExtension extends DraftStoreExtension
@prepareNewDraft: (draft) ->
draft.body = "Edited by TestExtension!" + draft.body
fix(drafts): Various improvements and fixes to drafts, draft state management Summary: This diff contains a few major changes: 1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario: - View thread with draft, edit draft - Move to another thread - Move back to thread with draft - Move to another thread. Notice that one or more messages from thread with draft are still there. There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great. 2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here: - In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI. - Previously, when you added a contact to To/CC/BCC, this happened: <input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state. To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source! This diff includes a few minor fixes as well: 1. Draft.state is gone—use Message.object = draft instead 2. String model attributes should never be null 3. Pre-send checks that can cancel draft send 4. Put the entire curl history and task queue into feedback reports 5. Cache localIds for extra speed 6. Move us up to latest React Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1125
2015-02-04 08:24:31 +08:00
describe "DraftStore", ->
feat(signatures): Initial signature support Summary: - Draft Store extensions can now implement `prepareNewDraft` to have an opportunity to change a draft before it's displayed for the first time. - When composers are torn down, they delete their draft if it is still pristine. This makes the behavior of closing unedited popout drafts the same as leaving unedited inline drafts. - The DraftStoreProxy keeps the initial body of the draft *if* it started in a pristine state. This means "is the body empty" is just a simple == check, and it takes into account anything added to the body by extensions. - Calling Actions.destroyDraft doesn't blow up anymore if the draft session can't be found. This was a bug and meant that you couldn't destroy drafts which hadn't been previously edited, and also meant that bad things(tm) happened when you called destroyDraft twice, which seemed like overkill. - DestroyDraft task now exits gracefully when the draft cannot be found. You can test this feature by adding the following to your config.cson: ``` signatures: NAMESPACEID: "<br/><br/><div id=\"Signature\"><div id=\"divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\"><p></p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450\" style=\"font-family:'Times New Roman'; table-layout:fixed\"><tbody><tr><td class=\"logo-td\" align=\"left\" valign=\"top\" width=\"76\"><p style=\"margin-bottom:10px; margin-right:10px; font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px\"><a href=\"http://www.nylas.com/\" class=\"clink logo-container\" style=\"text-decoration:none\"><img alt=\"Nylas\" border=\"0\" class=\"sig-logo\" height=\"80\" width=\"66\" style=\"-webkit-user-select: none;\" src=\"https://s3-us-west-2.amazonaws.com/nylas-static-assets/nylas-email-signature.png\"></a></p><p class=\"social-list\" style=\"font-size:0px; line-height:0; font-family:Helvetica,Arial,sans-serif\"></p></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"spacer-td\" width=\"16\" style=\"border-left-width:2px; border-left-style:solid; border-left-color:rgb(30,162,162)\"><img width=\"10\" style=\"-webkit-user-select: none;\" src=\"https://s3.amazonaws.com/htmlsig-assets/spacer.gif\"></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"content-td\" width=\"368\"><div class=\"content-pad\"><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; color:rgb(33,33,33); margin-bottom:10px\"><span class=\"txt signature_name-target sig-hide\" style=\"font-weight:bold; display:inline\">Gleb Polyakov</span>&nbsp;<span class=\"email-sep break\" style=\"display:inline\"><br></span><a class=\"link email signature_email-target sig-hide\" href=\"mailto:gleb@nylas.com\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">gleb@nylas.com</a><span class=\"signature_email-sep sep\" style=\"display:inline\">&nbsp;/&nbsp;</span><span class=\"txt signature_mobilephone-target sig-hide\" style=\"display:inline\">404-786-4100</span></p><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; margin-bottom:10px\"><span class=\"txt signature_companyname-target sig-hide\" style=\"font-weight:bold; color:rgb(33,33,33); display:inline\">Nylas</span>&nbsp;<span class=\"company-sep break\" style=\"display:inline\"><br></span><span class=\"address-sep break\"></span><span class=\"address2-sep break\"></span><span class=\"website-sep break\"></span><a class=\"link signature_website-target sig-hide\" href=\"http://www.nylas.com/\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">http://www.nylas.com</a></p></div></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"><p class=\"txt signature_disclaimer-target\" style=\"font-family:Helvetica,Arial,sans-serif; color:rgb(33,33,33); font-size:9px; line-height:12px; margin-top:10px\"></p></td></tr></tbody></table><p></p></div></div>" ``` specs for draft store extension hooks, some draft store refactoring Test Plan: Run a few new specs that make sure extensions are run Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1741
2015-07-15 03:20:06 +08:00
beforeEach ->
spyOn(atom, 'newWindow').andCallFake ->
describe "creating drafts", ->
beforeEach ->
fakeThread = new Thread
id: 'fake-thread-id'
subject: 'Fake Subject'
fakeMessage1 = new Message
id: 'fake-message-1'
to: [new Contact(email: 'ben@nylas.com'), new Contact(email: 'evan@nylas.com')]
cc: [new Contact(email: 'mg@nylas.com'), new Contact(email: AccountStore.current().me().email)]
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'
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)
msgFromMe = new Message
id: 'fake-message-3'
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: [new Contact(email: AccountStore.current().me().email)]
threadId: 'fake-thread-id'
body: 'Fake Message 2'
subject: 'Re: Fake Subject'
date: new Date(1415814587)
msgWithReplyTo = new Message
id: 'fake-message-reply-to'
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'
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)
fakeMessages =
'fake-message-1': fakeMessage1
'fake-message-3': msgFromMe
'fake-message-2': fakeMessage2
'fake-message-reply-to': msgWithReplyTo
'fake-message-reply-to-duplicates': msgWithReplyToDuplicates
spyOn(DatabaseStore, 'find').andCallFake (klass, id) ->
query = new ModelQuery(klass, {id})
spyOn(query, 'then').andCallFake (fn) ->
return fn(fakeThread) if klass is Thread
return fn(fakeMessages[id]) if klass is Message
return fn(new Error('Not Stubbed'))
query
spyOn(DatabaseStore, 'run').andCallFake (query) ->
return Promise.resolve(fakeMessage2) if query._klass is Message
return Promise.reject(new Error('Not Stubbed'))
spyOn(DatabaseStore, 'persistModel').andCallFake -> Promise.resolve()
fix(draft-speed): Optimize draft creation and reduce scroll / focus delays Summary: This diff attempts to improve the responsiveness of the app when you hit "Reply". This is achieved by being smarter about creating the draft and loading it into the draft store, and also by allowing the compose* actions to take objects instead of just IDs (resulting in a fetch of the object). Allow Actions.composeReply,etc. to optionally be called with thread and message objects instead of IDs. This prevents a database lookup and the data is "right there." Create DraftStoreProxy for new drafts optimistically—this allows us to hand it the draft model we just created and it doesn't have to go query for it When we create a new Draft, immediately bind it to a LocalId. This means that when the MessageStore receives the trigger() event from the Database, it doesn't have to wait while a localId is created When MessageStore sees a new Message come in which is on the current thread, a draft, and not in the localIds map, assume it's a new draft and shortcut fetchFromCaceh to manually add it to the items array and display. This means the user sees the... ...draft instantly. Remove delays from focusing draft, scrolling to draft after content is ready. I actually removed these thinking it would break something, and it didn't break anything.... Maybe new Chromium handles better? Fix specs Test Plan: Run specs - more in progress right now Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1598
2015-06-06 02:38:30 +08:00
spyOn(DatabaseStore, 'bindToLocalId')
afterEach ->
# Have to cleanup the DraftStoreProxy objects or we'll get a memory
# leak error
for id, session of DraftStore._draftSessions
DraftStore._doneWithSession(session)
describe "onComposeReply", ->
beforeEach ->
runs ->
DraftStore._onComposeReply({threadId: fakeThread.id, messageId: fakeMessage1.id})
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
it "should include quoted text", ->
expect(@model.body.indexOf('blockquote') > 0).toBe(true)
expect(@model.body.indexOf(fakeMessage1.body) > 0).toBe(true)
it "should address the message to the previous message's sender", ->
expect(@model.to).toEqual(fakeMessage1.from)
it "should set the replyToMessageId to the previous message's ids", ->
expect(@model.replyToMessageId).toEqual(fakeMessage1.id)
describe "onComposeReply", ->
describe "when the message provided as context has one or more 'ReplyTo' recipients", ->
it "addresses the draft to all of the message's 'ReplyTo' recipients", ->
runs ->
DraftStore._onComposeReply({threadId: fakeThread.id, messageId: msgWithReplyTo.id})
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
expect(@model.to).toEqual(msgWithReplyTo.replyTo)
expect(@model.cc.length).toBe 0
expect(@model.bcc.length).toBe 0
describe "onComposeReply", ->
describe "when the message provided as context was sent by the current user", ->
it "addresses the draft to all of the last messages's 'To' recipients", ->
runs ->
DraftStore._onComposeReply({threadId: fakeThread.id, messageId: msgFromMe.id})
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
expect(@model.to).toEqual(msgFromMe.to)
expect(@model.cc.length).toBe 0
expect(@model.bcc.length).toBe 0
describe "onComposeReplyAll", ->
beforeEach ->
runs ->
DraftStore._onComposeReplyAll({threadId: fakeThread.id, messageId: fakeMessage1.id})
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
it "should include quoted text", ->
expect(@model.body.indexOf('blockquote') > 0).toBe(true)
expect(@model.body.indexOf(fakeMessage1.body) > 0).toBe(true)
it "should address the message to the previous message's sender", ->
expect(@model.to).toEqual(fakeMessage1.from)
it "should cc everyone who was on the previous message in to or cc", ->
ccEmails = @model.cc.map (cc) -> cc.email
expect(ccEmails.sort()).toEqual([ 'ben@nylas.com', 'evan@nylas.com', 'mg@nylas.com'])
it "should not include people who were bcc'd on the previous message", ->
expect(@model.bcc).toEqual([])
expect(@model.cc.indexOf(fakeMessage1.bcc[0])).toEqual(-1)
it "should not include you when you were cc'd on the previous message", ->
ccEmails = @model.cc.map (cc) -> cc.email
expect(ccEmails.indexOf(AccountStore.current().me().email)).toEqual(-1)
it "should set the replyToMessageId to the previous message's ids", ->
expect(@model.replyToMessageId).toEqual(fakeMessage1.id)
describe "onComposeReplyAll", ->
describe "when the message provided as context has one or more 'ReplyTo' recipients", ->
beforeEach ->
runs ->
DraftStore._onComposeReply({threadId: fakeThread.id, messageId: msgWithReplyTo.id})
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
it "addresses the draft to all of the message's 'ReplyTo' recipients", ->
expect(@model.to).toEqual(msgWithReplyTo.replyTo)
it "should not include the message's 'From' recipient in any field", ->
all = [].concat(@model.to, @model.cc, @model.bcc)
match = _.find all, (c) -> c.email is msgWithReplyTo.from[0].email
expect(match).toEqual(undefined)
describe "onComposeReplyAll", ->
describe "when the message provided has one or more 'ReplyTo' recipients and duplicates in the To/Cc fields", ->
it "should unique the to/cc fields", ->
runs ->
DraftStore._onComposeReplyAll({threadId: fakeThread.id, messageId: msgWithReplyToDuplicates.id})
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
model = DatabaseStore.persistModel.mostRecentCall.args[0]
ccEmails = model.cc.map (cc) -> cc.email
expect(ccEmails.sort()).toEqual(['1@1.com', '2@2.com', '4@4.com'])
toEmails = model.to.map (to) -> to.email
expect(toEmails.sort()).toEqual(['reply-to@5.com'])
describe "onComposeReplyAll", ->
describe "when the message provided as context was sent by the current user", ->
it "addresses the draft to all of the last messages's recipients", ->
runs ->
DraftStore._onComposeReplyAll({threadId: fakeThread.id, messageId: msgFromMe.id})
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
expect(@model.to).toEqual(msgFromMe.to)
expect(@model.cc).toEqual(msgFromMe.cc)
expect(@model.bcc.length).toBe 0
describe "onComposeForward", ->
beforeEach ->
runs ->
DraftStore._onComposeForward({threadId: fakeThread.id, messageId: fakeMessage1.id})
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
@model = DatabaseStore.persistModel.mostRecentCall.args[0]
it "should include quoted text", ->
expect(@model.body.indexOf('blockquote') > 0).toBe(true)
expect(@model.body.indexOf(fakeMessage1.body) > 0).toBe(true)
it "should not address the message to anyone", ->
expect(@model.to).toEqual([])
expect(@model.cc).toEqual([])
expect(@model.bcc).toEqual([])
it "should not set the replyToMessageId", ->
expect(@model.replyToMessageId).toEqual(undefined)
describe "_newMessageWithContext", ->
beforeEach ->
# A helper method that makes it easy to test _newMessageWithContext, which
# is asynchronous and whose output is a model persisted to the database.
@_callNewMessageWithContext = (context, attributesCallback, modelCallback) ->
runs ->
DraftStore._newMessageWithContext(context, attributesCallback)
waitsFor ->
DatabaseStore.persistModel.callCount > 0
runs ->
model = DatabaseStore.persistModel.mostRecentCall.args[0]
modelCallback(model) if modelCallback
it "should create a new message", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
{}
, (model) ->
expect(model.constructor).toBe(Message)
fix(draft-speed): Optimize draft creation and reduce scroll / focus delays Summary: This diff attempts to improve the responsiveness of the app when you hit "Reply". This is achieved by being smarter about creating the draft and loading it into the draft store, and also by allowing the compose* actions to take objects instead of just IDs (resulting in a fetch of the object). Allow Actions.composeReply,etc. to optionally be called with thread and message objects instead of IDs. This prevents a database lookup and the data is "right there." Create DraftStoreProxy for new drafts optimistically—this allows us to hand it the draft model we just created and it doesn't have to go query for it When we create a new Draft, immediately bind it to a LocalId. This means that when the MessageStore receives the trigger() event from the Database, it doesn't have to wait while a localId is created When MessageStore sees a new Message come in which is on the current thread, a draft, and not in the localIds map, assume it's a new draft and shortcut fetchFromCaceh to manually add it to the items array and display. This means the user sees the... ...draft instantly. Remove delays from focusing draft, scrolling to draft after content is ready. I actually removed these thinking it would break something, and it didn't break anything.... Maybe new Chromium handles better? Fix specs Test Plan: Run specs - more in progress right now Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1598
2015-06-06 02:38:30 +08:00
it "should assign and save a local Id for the new message", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
{}
, (model) ->
expect(DatabaseStore.bindToLocalId).toHaveBeenCalled()
it "should setup a draft session for the draftLocalId, so that a subsequent request for the session's draft resolves immediately.", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
{}
, (model) ->
[draft, localId] = DatabaseStore.bindToLocalId.mostRecentCall.args
session = DraftStore.sessionForLocalId(localId).value()
expect(session.draft()).toBe(draft)
it "should set the subject of the new message automatically", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
{}
, (model) ->
expect(model.subject).toEqual("Re: Fake Subject")
it "should apply attributes provided by the attributesCallback", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
subject: "Fwd: Fake subject"
to: [new Contact(email: 'weird@example.com')]
, (model) ->
expect(model.subject).toEqual("Fwd: Fake subject")
feat(signatures): Initial signature support Summary: - Draft Store extensions can now implement `prepareNewDraft` to have an opportunity to change a draft before it's displayed for the first time. - When composers are torn down, they delete their draft if it is still pristine. This makes the behavior of closing unedited popout drafts the same as leaving unedited inline drafts. - The DraftStoreProxy keeps the initial body of the draft *if* it started in a pristine state. This means "is the body empty" is just a simple == check, and it takes into account anything added to the body by extensions. - Calling Actions.destroyDraft doesn't blow up anymore if the draft session can't be found. This was a bug and meant that you couldn't destroy drafts which hadn't been previously edited, and also meant that bad things(tm) happened when you called destroyDraft twice, which seemed like overkill. - DestroyDraft task now exits gracefully when the draft cannot be found. You can test this feature by adding the following to your config.cson: ``` signatures: NAMESPACEID: "<br/><br/><div id=\"Signature\"><div id=\"divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\"><p></p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450\" style=\"font-family:'Times New Roman'; table-layout:fixed\"><tbody><tr><td class=\"logo-td\" align=\"left\" valign=\"top\" width=\"76\"><p style=\"margin-bottom:10px; margin-right:10px; font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px\"><a href=\"http://www.nylas.com/\" class=\"clink logo-container\" style=\"text-decoration:none\"><img alt=\"Nylas\" border=\"0\" class=\"sig-logo\" height=\"80\" width=\"66\" style=\"-webkit-user-select: none;\" src=\"https://s3-us-west-2.amazonaws.com/nylas-static-assets/nylas-email-signature.png\"></a></p><p class=\"social-list\" style=\"font-size:0px; line-height:0; font-family:Helvetica,Arial,sans-serif\"></p></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"spacer-td\" width=\"16\" style=\"border-left-width:2px; border-left-style:solid; border-left-color:rgb(30,162,162)\"><img width=\"10\" style=\"-webkit-user-select: none;\" src=\"https://s3.amazonaws.com/htmlsig-assets/spacer.gif\"></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"content-td\" width=\"368\"><div class=\"content-pad\"><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; color:rgb(33,33,33); margin-bottom:10px\"><span class=\"txt signature_name-target sig-hide\" style=\"font-weight:bold; display:inline\">Gleb Polyakov</span>&nbsp;<span class=\"email-sep break\" style=\"display:inline\"><br></span><a class=\"link email signature_email-target sig-hide\" href=\"mailto:gleb@nylas.com\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">gleb@nylas.com</a><span class=\"signature_email-sep sep\" style=\"display:inline\">&nbsp;/&nbsp;</span><span class=\"txt signature_mobilephone-target sig-hide\" style=\"display:inline\">404-786-4100</span></p><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; margin-bottom:10px\"><span class=\"txt signature_companyname-target sig-hide\" style=\"font-weight:bold; color:rgb(33,33,33); display:inline\">Nylas</span>&nbsp;<span class=\"company-sep break\" style=\"display:inline\"><br></span><span class=\"address-sep break\"></span><span class=\"address2-sep break\"></span><span class=\"website-sep break\"></span><a class=\"link signature_website-target sig-hide\" href=\"http://www.nylas.com/\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">http://www.nylas.com</a></p></div></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"><p class=\"txt signature_disclaimer-target\" style=\"font-family:Helvetica,Arial,sans-serif; color:rgb(33,33,33); font-size:9px; line-height:12px; margin-top:10px\"></p></td></tr></tbody></table><p></p></div></div>" ``` specs for draft store extension hooks, some draft store refactoring Test Plan: Run a few new specs that make sure extensions are run Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1741
2015-07-15 03:20:06 +08:00
describe "extensions", ->
beforeEach ->
DraftStore.registerExtension(TestExtension)
afterEach ->
DraftStore.unregisterExtension(TestExtension)
it "should give extensions a chance to customize the draft via ext.prepareNewDraft", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
{}
, (model) ->
expect(model.body.indexOf("Edited by TestExtension!")).toBe(0)
fix(draft-speed): Optimize draft creation and reduce scroll / focus delays Summary: This diff attempts to improve the responsiveness of the app when you hit "Reply". This is achieved by being smarter about creating the draft and loading it into the draft store, and also by allowing the compose* actions to take objects instead of just IDs (resulting in a fetch of the object). Allow Actions.composeReply,etc. to optionally be called with thread and message objects instead of IDs. This prevents a database lookup and the data is "right there." Create DraftStoreProxy for new drafts optimistically—this allows us to hand it the draft model we just created and it doesn't have to go query for it When we create a new Draft, immediately bind it to a LocalId. This means that when the MessageStore receives the trigger() event from the Database, it doesn't have to wait while a localId is created When MessageStore sees a new Message come in which is on the current thread, a draft, and not in the localIds map, assume it's a new draft and shortcut fetchFromCaceh to manually add it to the items array and display. This means the user sees the... ...draft instantly. Remove delays from focusing draft, scrolling to draft after content is ready. I actually removed these thinking it would break something, and it didn't break anything.... Maybe new Chromium handles better? Fix specs Test Plan: Run specs - more in progress right now Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1598
2015-06-06 02:38:30 +08:00
describe "context", ->
it "should accept `thread` or look up a thread when given `threadId`", ->
@_callNewMessageWithContext {thread: fakeThread}
, (thread, message) ->
expect(thread).toBe(fakeThread)
expect(DatabaseStore.find).not.toHaveBeenCalled()
{}
, (model) ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
expect(thread).toBe(fakeThread)
expect(DatabaseStore.find).toHaveBeenCalled()
{}
, (model) ->
it "should accept `message` or look up a message when given `messageId`", ->
@_callNewMessageWithContext {thread: fakeThread, message: fakeMessage1}
, (thread, message) ->
expect(message).toBe(fakeMessage1)
expect(DatabaseStore.find).not.toHaveBeenCalled()
{}
, (model) ->
@_callNewMessageWithContext {thread: fakeThread, messageId: fakeMessage1.id}
, (thread, message) ->
expect(message).toBe(fakeMessage1)
expect(DatabaseStore.find).toHaveBeenCalled()
{}
, (model) ->
describe "when a reply-to message is provided by the attributesCallback", ->
it "should include quoted text in the new message", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
replyToMessage: fakeMessage1
, (model) ->
expect(model.body.indexOf('gmail_quote') > 0).toBe(true)
expect(model.body.indexOf('Fake Message 1') > 0).toBe(true)
it "should include the `On ... wrote:` line", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
replyToMessage: fakeMessage1
, (model) ->
expect(model.body.search(/On .+, at .+, Customer &lt;customer@example.com&gt; wrote/) > 0).toBe(true)
it "should make the subject the subject of the message, not the thread", ->
fakeMessage1.subject = "OLD SUBJECT"
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
replyToMessage: fakeMessage1
, (model) ->
expect(model.subject).toEqual("Re: OLD SUBJECT")
it "should change the subject from Fwd: back to Re: if necessary", ->
fakeMessage1.subject = "Fwd: This is my DRAFT"
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
replyToMessage: fakeMessage1
, (model) ->
expect(model.subject).toEqual("Re: This is my DRAFT")
it "should only include the sender's name if it was available", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
replyToMessage: fakeMessage2
, (model) ->
expect(model.body.search(/On .+, at .+, ben@nylas.com wrote:/) > 0).toBe(true)
describe "when a forward message is provided by the attributesCallback", ->
it "should include quoted text in the new message", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
forwardMessage: fakeMessage1
, (model) ->
expect(model.body.indexOf('gmail_quote') > 0).toBe(true)
expect(model.body.indexOf('Fake Message 1') > 0).toBe(true)
it "should include the `Begin forwarded message:` line", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
forwardMessage: fakeMessage1
, (model) ->
expect(model.body.indexOf('Begin forwarded message') > 0).toBe(true)
it "should make the subject the subject of the message, not the thread", ->
fakeMessage1.subject = "OLD SUBJECT"
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
forwardMessage: fakeMessage1
, (model) ->
expect(model.subject).toEqual("Fwd: OLD SUBJECT")
it "should change the subject from Re: back to Fwd: if necessary", ->
fakeMessage1.subject = "Re: This is my DRAFT"
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
forwardMessage: fakeMessage1
, (model) ->
expect(model.subject).toEqual("Fwd: This is my DRAFT")
it "should print the headers of the original message", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
forwardMessage: fakeMessage2
, (model) ->
expect(model.body.indexOf('From: ben@nylas.com') > 0).toBe(true)
expect(model.body.indexOf('Subject: Re: Fake Subject') > 0).toBe(true)
expect(model.body.indexOf('To: customer@example.com') > 0).toBe(true)
describe "attributesCallback", ->
describe "when a threadId is provided", ->
it "should receive the thread", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
expect(thread).toEqual(fakeThread)
{}
it "should receive the last message in the fakeThread", ->
@_callNewMessageWithContext {threadId: fakeThread.id}
, (thread, message) ->
expect(message).toEqual(fakeMessage2)
{}
describe "when a threadId and messageId are provided", ->
it "should receive the thread", ->
@_callNewMessageWithContext {threadId: fakeThread.id, messageId: fakeMessage1.id}
, (thread, message) ->
expect(thread).toEqual(fakeThread)
{}
it "should receive the desired message in the thread", ->
@_callNewMessageWithContext {threadId: fakeThread.id, messageId: fakeMessage1.id}
, (thread, message) ->
expect(message).toEqual(fakeMessage1)
{}
describe "onDestroyDraft", ->
beforeEach ->
@draftSessionTeardown = jasmine.createSpy('draft teardown')
@session =
draft: ->
pristine: false
changes:
commit: -> Promise.resolve()
teardown: ->
teardown: @draftSessionTeardown
DraftStore._draftSessions = {"abc": @session}
spyOn(Actions, 'queueTask')
it "should teardown the draft session, ensuring no more saves are made", ->
DraftStore._onDestroyDraft('abc')
expect(@draftSessionTeardown).toHaveBeenCalled()
feat(signatures): Initial signature support Summary: - Draft Store extensions can now implement `prepareNewDraft` to have an opportunity to change a draft before it's displayed for the first time. - When composers are torn down, they delete their draft if it is still pristine. This makes the behavior of closing unedited popout drafts the same as leaving unedited inline drafts. - The DraftStoreProxy keeps the initial body of the draft *if* it started in a pristine state. This means "is the body empty" is just a simple == check, and it takes into account anything added to the body by extensions. - Calling Actions.destroyDraft doesn't blow up anymore if the draft session can't be found. This was a bug and meant that you couldn't destroy drafts which hadn't been previously edited, and also meant that bad things(tm) happened when you called destroyDraft twice, which seemed like overkill. - DestroyDraft task now exits gracefully when the draft cannot be found. You can test this feature by adding the following to your config.cson: ``` signatures: NAMESPACEID: "<br/><br/><div id=\"Signature\"><div id=\"divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\"><p></p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450\" style=\"font-family:'Times New Roman'; table-layout:fixed\"><tbody><tr><td class=\"logo-td\" align=\"left\" valign=\"top\" width=\"76\"><p style=\"margin-bottom:10px; margin-right:10px; font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px\"><a href=\"http://www.nylas.com/\" class=\"clink logo-container\" style=\"text-decoration:none\"><img alt=\"Nylas\" border=\"0\" class=\"sig-logo\" height=\"80\" width=\"66\" style=\"-webkit-user-select: none;\" src=\"https://s3-us-west-2.amazonaws.com/nylas-static-assets/nylas-email-signature.png\"></a></p><p class=\"social-list\" style=\"font-size:0px; line-height:0; font-family:Helvetica,Arial,sans-serif\"></p></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"spacer-td\" width=\"16\" style=\"border-left-width:2px; border-left-style:solid; border-left-color:rgb(30,162,162)\"><img width=\"10\" style=\"-webkit-user-select: none;\" src=\"https://s3.amazonaws.com/htmlsig-assets/spacer.gif\"></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"content-td\" width=\"368\"><div class=\"content-pad\"><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; color:rgb(33,33,33); margin-bottom:10px\"><span class=\"txt signature_name-target sig-hide\" style=\"font-weight:bold; display:inline\">Gleb Polyakov</span>&nbsp;<span class=\"email-sep break\" style=\"display:inline\"><br></span><a class=\"link email signature_email-target sig-hide\" href=\"mailto:gleb@nylas.com\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">gleb@nylas.com</a><span class=\"signature_email-sep sep\" style=\"display:inline\">&nbsp;/&nbsp;</span><span class=\"txt signature_mobilephone-target sig-hide\" style=\"display:inline\">404-786-4100</span></p><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; margin-bottom:10px\"><span class=\"txt signature_companyname-target sig-hide\" style=\"font-weight:bold; color:rgb(33,33,33); display:inline\">Nylas</span>&nbsp;<span class=\"company-sep break\" style=\"display:inline\"><br></span><span class=\"address-sep break\"></span><span class=\"address2-sep break\"></span><span class=\"website-sep break\"></span><a class=\"link signature_website-target sig-hide\" href=\"http://www.nylas.com/\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">http://www.nylas.com</a></p></div></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"><p class=\"txt signature_disclaimer-target\" style=\"font-family:Helvetica,Arial,sans-serif; color:rgb(33,33,33); font-size:9px; line-height:12px; margin-top:10px\"></p></td></tr></tbody></table><p></p></div></div>" ``` specs for draft store extension hooks, some draft store refactoring Test Plan: Run a few new specs that make sure extensions are run Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1741
2015-07-15 03:20:06 +08:00
it "should not throw if the draft session is not in the window", ->
expect ->
DraftStore._onDestroyDraft('other')
feat(signatures): Initial signature support Summary: - Draft Store extensions can now implement `prepareNewDraft` to have an opportunity to change a draft before it's displayed for the first time. - When composers are torn down, they delete their draft if it is still pristine. This makes the behavior of closing unedited popout drafts the same as leaving unedited inline drafts. - The DraftStoreProxy keeps the initial body of the draft *if* it started in a pristine state. This means "is the body empty" is just a simple == check, and it takes into account anything added to the body by extensions. - Calling Actions.destroyDraft doesn't blow up anymore if the draft session can't be found. This was a bug and meant that you couldn't destroy drafts which hadn't been previously edited, and also meant that bad things(tm) happened when you called destroyDraft twice, which seemed like overkill. - DestroyDraft task now exits gracefully when the draft cannot be found. You can test this feature by adding the following to your config.cson: ``` signatures: NAMESPACEID: "<br/><br/><div id=\"Signature\"><div id=\"divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\"><p></p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450\" style=\"font-family:'Times New Roman'; table-layout:fixed\"><tbody><tr><td class=\"logo-td\" align=\"left\" valign=\"top\" width=\"76\"><p style=\"margin-bottom:10px; margin-right:10px; font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px\"><a href=\"http://www.nylas.com/\" class=\"clink logo-container\" style=\"text-decoration:none\"><img alt=\"Nylas\" border=\"0\" class=\"sig-logo\" height=\"80\" width=\"66\" style=\"-webkit-user-select: none;\" src=\"https://s3-us-west-2.amazonaws.com/nylas-static-assets/nylas-email-signature.png\"></a></p><p class=\"social-list\" style=\"font-size:0px; line-height:0; font-family:Helvetica,Arial,sans-serif\"></p></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"spacer-td\" width=\"16\" style=\"border-left-width:2px; border-left-style:solid; border-left-color:rgb(30,162,162)\"><img width=\"10\" style=\"-webkit-user-select: none;\" src=\"https://s3.amazonaws.com/htmlsig-assets/spacer.gif\"></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"content-td\" width=\"368\"><div class=\"content-pad\"><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; color:rgb(33,33,33); margin-bottom:10px\"><span class=\"txt signature_name-target sig-hide\" style=\"font-weight:bold; display:inline\">Gleb Polyakov</span>&nbsp;<span class=\"email-sep break\" style=\"display:inline\"><br></span><a class=\"link email signature_email-target sig-hide\" href=\"mailto:gleb@nylas.com\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">gleb@nylas.com</a><span class=\"signature_email-sep sep\" style=\"display:inline\">&nbsp;/&nbsp;</span><span class=\"txt signature_mobilephone-target sig-hide\" style=\"display:inline\">404-786-4100</span></p><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; margin-bottom:10px\"><span class=\"txt signature_companyname-target sig-hide\" style=\"font-weight:bold; color:rgb(33,33,33); display:inline\">Nylas</span>&nbsp;<span class=\"company-sep break\" style=\"display:inline\"><br></span><span class=\"address-sep break\"></span><span class=\"address2-sep break\"></span><span class=\"website-sep break\"></span><a class=\"link signature_website-target sig-hide\" href=\"http://www.nylas.com/\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">http://www.nylas.com</a></p></div></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"><p class=\"txt signature_disclaimer-target\" style=\"font-family:Helvetica,Arial,sans-serif; color:rgb(33,33,33); font-size:9px; line-height:12px; margin-top:10px\"></p></td></tr></tbody></table><p></p></div></div>" ``` specs for draft store extension hooks, some draft store refactoring Test Plan: Run a few new specs that make sure extensions are run Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1741
2015-07-15 03:20:06 +08:00
.not.toThrow()
it "should queue a destroy draft task", ->
DraftStore._onDestroyDraft('abc')
expect(Actions.queueTask).toHaveBeenCalled()
expect(Actions.queueTask.mostRecentCall.args[0] instanceof DestroyDraftTask).toBe(true)
it "should clean up the draft session", ->
spyOn(DraftStore, '_doneWithSession')
DraftStore._onDestroyDraft('abc')
expect(DraftStore._doneWithSession).toHaveBeenCalledWith(@session)
it "should close the window if it's a popout", ->
spyOn(atom, "close")
spyOn(DraftStore, "_isPopout").andReturn true
DraftStore._onDestroyDraft('abc')
expect(atom.close).toHaveBeenCalled()
it "should NOT close the window if isn't a popout", ->
spyOn(atom, "close")
spyOn(DraftStore, "_isPopout").andReturn false
DraftStore._onDestroyDraft('abc')
expect(atom.close).not.toHaveBeenCalled()
describe "before unloading", ->
it "should destroy pristine drafts", ->
DraftStore._draftSessions = {"abc": {
changes: {}
draft: ->
pristine: true
}}
spyOn(Actions, 'queueTask')
DraftStore._onBeforeUnload()
expect(Actions.queueTask).toHaveBeenCalled()
expect(Actions.queueTask.mostRecentCall.args[0] instanceof DestroyDraftTask).toBe(true)
describe "when drafts return unresolved commit promises", ->
beforeEach ->
@resolve = null
DraftStore._draftSessions = {"abc": {
changes:
commit: => new Promise (resolve, reject) => @resolve = resolve
draft: ->
pristine: false
}}
it "should return false and call window.close itself", ->
spyOn(atom, 'finishUnload')
expect(DraftStore._onBeforeUnload()).toBe(false)
expect(atom.finishUnload).not.toHaveBeenCalled()
@resolve()
advanceClock(1000)
expect(atom.finishUnload).toHaveBeenCalled()
describe "when drafts return immediately fulfilled commit promises", ->
beforeEach ->
DraftStore._draftSessions = {"abc": {
changes:
commit: => Promise.resolve()
draft: ->
pristine: false
}}
it "should still wait one tick before firing atom.close again", ->
spyOn(atom, 'finishUnload')
expect(DraftStore._onBeforeUnload()).toBe(false)
expect(atom.finishUnload).not.toHaveBeenCalled()
advanceClock()
expect(atom.finishUnload).toHaveBeenCalled()
describe "when there are no drafts", ->
beforeEach ->
DraftStore._draftSessions = {}
it "should return true and allow the window to close", ->
expect(DraftStore._onBeforeUnload()).toBe(true)
describe "sending a draft", ->
draftLocalId = "local-123"
beforeEach ->
DraftStore._draftSessions = {}
proxy =
prepare: -> Promise.resolve(proxy)
teardown: ->
draft: -> {}
changes:
commit: -> Promise.resolve()
DraftStore._draftSessions[draftLocalId] = proxy
spyOn(DraftStore, "_doneWithSession").andCallThrough()
spyOn(DraftStore, "trigger")
TaskQueue._queue = []
it "sets the sending state when sending", ->
spyOn(atom, "isMainWindow").andReturn true
feat(offline-mode, undo-redo): Tasks handle network errors better and retry, undo/redo based on tasks Summary: This diff does a couple things: - Undo redo with a new undo/redo store that maintains it's own queue of undo/redo tasks. This queue is separate from the TaskQueue because not all tasks should be considered for undo history! Right now just the AddRemoveTagsTask is undoable. - NylasAPI.makeRequest now returns a promise which resolves with the result or rejects with an error. For things that still need them, there's still `success` and `error` callbacks. I also added `started:(req) ->` which allows you to get the underlying request. - Aborting a NylasAPI request now makes it call it's error callback / promise reject. - You can now run code after perform local has completed using this syntax: ``` task = new AddRemoveTagsTask(focused, ['archive'], ['inbox']) task.waitForPerformLocal().then -> Actions.setFocus(collection: 'thread', item: nextFocus) Actions.setCursorPosition(collection: 'thread', item: nextKeyboard) Actions.queueTask(task) ``` - In specs, you can now use `advanceClock` to get through a Promise.then/catch/finally. Turns out it was using something low level and not using setTimeout(0). - The TaskQueue uses promises better and defers a lot of the complexity around queueState for performLocal/performRemote to a task subclass called APITask. APITask implements "perform" and breaks it into "performLocal" and "performRemote". - All tasks either resolve or reject. They're always removed from the queue, unless they resolve with Task.Status.Retry, which means they internally did a .catch (err) => Promise.resolve(Task.Status.Retry) and they want to be run again later. - API tasks retry until they succeed or receive a NylasAPI.PermanentErrorCode (400,404,500), in which case they revert and finish. - The AddRemoveTags Task can now take more than one thread! This is super cool because you can undo/redo a bulk action and also because we'll probably have a bulk tag modification API endpoint soon. Getting undo / redo working revealed that the thread versioning system we built isn't working because the server was incrementing things by more than 1 at a time. Now we count the number of unresolved "optimistic" changes we've made to a given model, and only accept the server's version of it once the number of optimistic changes is back at zero. Known Issues: - AddRemoveTagsTasks aren't dependent on each other, so if you (undo/redo x lots) and then come back online, all the tasks try to add / remove all the tags at the same time. To fix this we can either allow the tasks to be merged together into a minimal set or make them block on each other. - When Offline, you still get errors in the console for GET requests. Need to catch these and display an offline status bar. - The metadata tasks haven't been updated yet to the new API. Wanted to get it reviewed first! Test Plan: All the tests still pass! Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1694
2015-07-08 01:38:53 +08:00
spyOn(TaskQueue, "_updateSoon")
spyOn(Actions, "queueTask").andCallThrough()
runs ->
DraftStore._onSendDraft(draftLocalId)
waitsFor ->
Actions.queueTask.calls.length > 0
runs ->
expect(DraftStore.isSendingDraft(draftLocalId)).toBe true
expect(DraftStore.trigger).toHaveBeenCalled()
it "returns false if the draft hasn't been seen", ->
spyOn(atom, "isMainWindow").andReturn true
expect(DraftStore.isSendingDraft(draftLocalId)).toBe false
it "closes the window if it's a popout", ->
feat(salesforce): add Salesforce creator Summary: tests on the schemas build input elements form builder pulls data grouping by row salesforce object store salesforce api logic successfully pulling salesforce objects into db object store saving to db refactoring tokenizing text field full documented tokenizing text field with specs linking in object picker component converting generated form to a controlled input form change handlers for controlled inputs Salesforce object creator store new way of opening windows removed atom.state.mode create new salesforce object creator in new window form creator loading in popup with generated form generated form renders select and multiselcet and textarea add checkbox creating related objects windnows know when others close remove debugger statements form submission converting data for salesforce posting hot window loading new hot window registration hot loading windows actions for listening to salesforce objects created generated form errors error handling for salesforce object creator rename saleforce object form store display errors to form submitting state passed through properly posts objects to Salesforce change name to salesforce object form add deep clone use formItemEach styling for Salesforce form creator salesforce required fields come back and populate form generated form loads related objects into fields remove console logs and fix sales schema adapter test fix task queue and formbuilder specs fix action bridge spec fix tokenizing text field spec fix draft store and tokenizing proptypes fix linter issues fix tokenizing text field bug rename to refresh window props remove console.log Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Differential Revision: https://review.inboxapp.com/D1425
2015-04-25 00:36:19 +08:00
spyOn(atom, "getWindowType").andReturn "composer"
spyOn(atom, "isMainWindow").andReturn false
spyOn(atom, "close")
runs ->
DraftStore._onSendDraft(draftLocalId)
waitsFor "Atom to close", ->
atom.close.calls.length > 0
it "doesn't close the window if it's inline", ->
feat(salesforce): add Salesforce creator Summary: tests on the schemas build input elements form builder pulls data grouping by row salesforce object store salesforce api logic successfully pulling salesforce objects into db object store saving to db refactoring tokenizing text field full documented tokenizing text field with specs linking in object picker component converting generated form to a controlled input form change handlers for controlled inputs Salesforce object creator store new way of opening windows removed atom.state.mode create new salesforce object creator in new window form creator loading in popup with generated form generated form renders select and multiselcet and textarea add checkbox creating related objects windnows know when others close remove debugger statements form submission converting data for salesforce posting hot window loading new hot window registration hot loading windows actions for listening to salesforce objects created generated form errors error handling for salesforce object creator rename saleforce object form store display errors to form submitting state passed through properly posts objects to Salesforce change name to salesforce object form add deep clone use formItemEach styling for Salesforce form creator salesforce required fields come back and populate form generated form loads related objects into fields remove console logs and fix sales schema adapter test fix task queue and formbuilder specs fix action bridge spec fix tokenizing text field spec fix draft store and tokenizing proptypes fix linter issues fix tokenizing text field bug rename to refresh window props remove console.log Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Differential Revision: https://review.inboxapp.com/D1425
2015-04-25 00:36:19 +08:00
spyOn(atom, "getWindowType").andReturn "other"
spyOn(atom, "isMainWindow").andReturn false
spyOn(atom, "close")
spyOn(DraftStore, "_isPopout").andCallThrough()
runs ->
DraftStore._onSendDraft(draftLocalId)
waitsFor ->
DraftStore._isPopout.calls.length > 0
runs ->
expect(atom.close).not.toHaveBeenCalled()
it "queues a SendDraftTask", ->
spyOn(Actions, "queueTask")
runs ->
DraftStore._onSendDraft(draftLocalId)
waitsFor ->
DraftStore._doneWithSession.calls.length > 0
runs ->
expect(Actions.queueTask).toHaveBeenCalled()
task = Actions.queueTask.calls[0].args[0]
expect(task instanceof SendDraftTask).toBe true
expect(task.draftLocalId).toBe draftLocalId
expect(task.fromPopout).toBe false
it "queues a SendDraftTask with popout info", ->
feat(salesforce): add Salesforce creator Summary: tests on the schemas build input elements form builder pulls data grouping by row salesforce object store salesforce api logic successfully pulling salesforce objects into db object store saving to db refactoring tokenizing text field full documented tokenizing text field with specs linking in object picker component converting generated form to a controlled input form change handlers for controlled inputs Salesforce object creator store new way of opening windows removed atom.state.mode create new salesforce object creator in new window form creator loading in popup with generated form generated form renders select and multiselcet and textarea add checkbox creating related objects windnows know when others close remove debugger statements form submission converting data for salesforce posting hot window loading new hot window registration hot loading windows actions for listening to salesforce objects created generated form errors error handling for salesforce object creator rename saleforce object form store display errors to form submitting state passed through properly posts objects to Salesforce change name to salesforce object form add deep clone use formItemEach styling for Salesforce form creator salesforce required fields come back and populate form generated form loads related objects into fields remove console logs and fix sales schema adapter test fix task queue and formbuilder specs fix action bridge spec fix tokenizing text field spec fix draft store and tokenizing proptypes fix linter issues fix tokenizing text field bug rename to refresh window props remove console.log Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Differential Revision: https://review.inboxapp.com/D1425
2015-04-25 00:36:19 +08:00
spyOn(atom, "getWindowType").andReturn "composer"
spyOn(atom, "isMainWindow").andReturn false
spyOn(atom, "close")
spyOn(Actions, "queueTask")
runs ->
DraftStore._onSendDraft(draftLocalId)
waitsFor ->
DraftStore._doneWithSession.calls.length > 0
runs ->
expect(Actions.queueTask).toHaveBeenCalled()
task = Actions.queueTask.calls[0].args[0]
expect(task.fromPopout).toBe true
describe "session teardown", ->
beforeEach ->
@draftTeardown = jasmine.createSpy('draft teardown')
@session =
draftLocalId: "abc"
draft: ->
pristine: false
changes:
commit: -> Promise.resolve()
reset: ->
teardown: @draftTeardown
DraftStore._draftSessions = {"abc": @session}
DraftStore._doneWithSession(@session)
it "removes from the list of draftSessions", ->
expect(DraftStore._draftSessions["abc"]).toBeUndefined()
it "Calls teardown on the session", ->
expect(@draftTeardown).toHaveBeenCalled
describe "mailto handling", ->
feat(signatures): Initial signature support Summary: - Draft Store extensions can now implement `prepareNewDraft` to have an opportunity to change a draft before it's displayed for the first time. - When composers are torn down, they delete their draft if it is still pristine. This makes the behavior of closing unedited popout drafts the same as leaving unedited inline drafts. - The DraftStoreProxy keeps the initial body of the draft *if* it started in a pristine state. This means "is the body empty" is just a simple == check, and it takes into account anything added to the body by extensions. - Calling Actions.destroyDraft doesn't blow up anymore if the draft session can't be found. This was a bug and meant that you couldn't destroy drafts which hadn't been previously edited, and also meant that bad things(tm) happened when you called destroyDraft twice, which seemed like overkill. - DestroyDraft task now exits gracefully when the draft cannot be found. You can test this feature by adding the following to your config.cson: ``` signatures: NAMESPACEID: "<br/><br/><div id=\"Signature\"><div id=\"divtagdefaultwrapper\" style=\"font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif\"><p></p><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"450\" style=\"font-family:'Times New Roman'; table-layout:fixed\"><tbody><tr><td class=\"logo-td\" align=\"left\" valign=\"top\" width=\"76\"><p style=\"margin-bottom:10px; margin-right:10px; font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px\"><a href=\"http://www.nylas.com/\" class=\"clink logo-container\" style=\"text-decoration:none\"><img alt=\"Nylas\" border=\"0\" class=\"sig-logo\" height=\"80\" width=\"66\" style=\"-webkit-user-select: none;\" src=\"https://s3-us-west-2.amazonaws.com/nylas-static-assets/nylas-email-signature.png\"></a></p><p class=\"social-list\" style=\"font-size:0px; line-height:0; font-family:Helvetica,Arial,sans-serif\"></p></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"spacer-td\" width=\"16\" style=\"border-left-width:2px; border-left-style:solid; border-left-color:rgb(30,162,162)\"><img width=\"10\" style=\"-webkit-user-select: none;\" src=\"https://s3.amazonaws.com/htmlsig-assets/spacer.gif\"></td><td align=\"left\" valign=\"top\" nowrap=\"nowrap\" class=\"content-td\" width=\"368\"><div class=\"content-pad\"><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; color:rgb(33,33,33); margin-bottom:10px\"><span class=\"txt signature_name-target sig-hide\" style=\"font-weight:bold; display:inline\">Gleb Polyakov</span>&nbsp;<span class=\"email-sep break\" style=\"display:inline\"><br></span><a class=\"link email signature_email-target sig-hide\" href=\"mailto:gleb@nylas.com\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">gleb@nylas.com</a><span class=\"signature_email-sep sep\" style=\"display:inline\">&nbsp;/&nbsp;</span><span class=\"txt signature_mobilephone-target sig-hide\" style=\"display:inline\">404-786-4100</span></p><p style=\"font-family:Helvetica,Arial,sans-serif; font-size:14px; line-height:16px; margin-bottom:10px\"><span class=\"txt signature_companyname-target sig-hide\" style=\"font-weight:bold; color:rgb(33,33,33); display:inline\">Nylas</span>&nbsp;<span class=\"company-sep break\" style=\"display:inline\"><br></span><span class=\"address-sep break\"></span><span class=\"address2-sep break\"></span><span class=\"website-sep break\"></span><a class=\"link signature_website-target sig-hide\" href=\"http://www.nylas.com/\" style=\"color:rgb(30,162,162); text-decoration:none; display:inline\">http://www.nylas.com</a></p></div></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"><p class=\"txt signature_disclaimer-target\" style=\"font-family:Helvetica,Arial,sans-serif; color:rgb(33,33,33); font-size:9px; line-height:12px; margin-top:10px\"></p></td></tr></tbody></table><p></p></div></div>" ``` specs for draft store extension hooks, some draft store refactoring Test Plan: Run a few new specs that make sure extensions are run Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1741
2015-07-15 03:20:06 +08:00
describe "extensions", ->
beforeEach ->
DraftStore.registerExtension(TestExtension)
afterEach ->
DraftStore.unregisterExtension(TestExtension)
it "should give extensions a chance to customize the draft via ext.prepareNewDraft", ->
received = null
spyOn(DatabaseStore, 'persistModel').andCallFake (draft) ->
received = draft
Promise.resolve()
DraftStore._onHandleMailtoLink('mailto:bengotow@gmail.com')
expect(received.body.indexOf("Edited by TestExtension!")).toBe(0)
it "should be case-insensitive towards subject keys", ->
received = null
spyOn(DraftStore, '_finalizeAndPersistNewMessage').andCallFake (draft) ->
received = draft
Promise.resolve({draftLocalId: 123})
expected = "EmailSubjectLOLOL"
DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?subject=' + expected)
expect(received.subject).toBe(expected)
DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?Subject=' + expected)
expect(received.subject).toBe(expected)
DraftStore._onHandleMailtoLink('mailto:asdf@asdf.com?SUBJECT=' + expected)
expect(received.subject).toBe(expected)
it "should correctly instantiate drafts for a wide range of mailto URLs", ->
received = null
spyOn(DatabaseStore, 'persistModel').andCallFake (draft) ->
received = draft
Promise.resolve()
links = [
'mailto:'
'mailto://bengotow@gmail.com'
'mailto:bengotow@gmail.com'
'mailto:?subject=%1z2a', # fails uriDecode
'mailto:?subject=%52z2a', # passes uriDecode
'mailto:?subject=Martha Stewart',
'mailto:?subject=Martha Stewart&cc=cc@nylas.com',
'mailto:bengotow@gmail.com?subject=Martha%20Stewart&cc=cc@nylas.com&bcc=bcc@nylas.com',
'mailto:bengotow@gmail.com?subject=Martha%20Stewart&cc=cc@nylas.com&bcc=Ben <bcc@nylas.com>',
'mailto:Ben Gotow <bengotow@gmail.com>,Shawn <shawn@nylas.com>?subject=Yes this is really valid'
'mailto:Ben%20Gotow%20<bengotow@gmail.com>,Shawn%20<shawn@nylas.com>?subject=Yes%20this%20is%20really%20valid'
'mailto:Reply <d+AORGpRdj0KXKUPBE1LoI0a30F10Ahj3wu3olS-aDk5_7K5Wu6WqqqG8t1HxxhlZ4KEEw3WmrSdtobgUq57SkwsYAH6tG57IrNqcQR0K6XaqLM2nGNZ22D2k@docs.google.com>?subject=Nilas%20Message%20to%20Customers',
]
expected = [
new Message(),
new Message(
to: [new Contact(name: 'bengotow@gmail.com', email: 'bengotow@gmail.com')]
),
new Message(
to: [new Contact(name: 'bengotow@gmail.com', email: 'bengotow@gmail.com')]
),
new Message(
subject: '%1z2a'
),
new Message(
subject: 'Rz2a'
),
new Message(
subject: 'Martha Stewart'
),
new Message(
cc: [new Contact(name: 'cc@nylas.com', email: 'cc@nylas.com')],
subject: 'Martha Stewart'
),
new Message(
to: [new Contact(name: 'bengotow@gmail.com', email: 'bengotow@gmail.com')],
cc: [new Contact(name: 'cc@nylas.com', email: 'cc@nylas.com')],
bcc: [new Contact(name: 'bcc@nylas.com', email: 'bcc@nylas.com')],
subject: 'Martha Stewart'
),
new Message(
to: [new Contact(name: 'bengotow@gmail.com', email: 'bengotow@gmail.com')],
cc: [new Contact(name: 'cc@nylas.com', email: 'cc@nylas.com')],
bcc: [new Contact(name: 'Ben', email: 'bcc@nylas.com')],
subject: 'Martha Stewart'
),
new Message(
to: [new Contact(name: 'Ben Gotow', email: 'bengotow@gmail.com'), new Contact(name: 'Shawn', email: 'shawn@nylas.com')],
subject: 'Yes this is really valid'
),
new Message(
to: [new Contact(name: 'Ben Gotow', email: 'bengotow@gmail.com'), new Contact(name: 'Shawn', email: 'shawn@nylas.com')],
subject: 'Yes this is really valid'
),
new Message(
to: [new Contact(name: 'Reply', email: 'd+AORGpRdj0KXKUPBE1LoI0a30F10Ahj3wu3olS-aDk5_7K5Wu6WqqqG8t1HxxhlZ4KEEw3WmrSdtobgUq57SkwsYAH6tG57IrNqcQR0K6XaqLM2nGNZ22D2k@docs.google.com')],
subject: 'Nilas Message to Customers'
)
]
for link, idx in links
DraftStore._onHandleMailtoLink(link)
expectedDraft = expected[idx]
expect(received['subject']).toEqual(expectedDraft['subject'])
for attr in ['to', 'cc', 'bcc', 'subject']
for contact, jdx in received[attr]
expectedContact = expectedDraft[attr][jdx]
expect(contact.email).toEqual(expectedContact.email)
expect(contact.name).toEqual(expectedContact.name)