2015-12-22 03:50:52 +08:00
{ File ,
Utils ,
Thread ,
Actions ,
Contact ,
Message ,
DraftStore ,
AccountStore ,
DatabaseStore ,
SoundRegistry ,
SendDraftTask ,
2016-01-26 06:14:09 +08:00
ChangeMailTask ,
2015-12-22 03:50:52 +08:00
DestroyDraftTask ,
ComposerExtension ,
ExtensionRegistry ,
2016-01-26 06:14:09 +08:00
FocusedContentStore ,
2015-12-22 03:50:52 +08:00
DatabaseTransaction ,
SanitizeTransformer ,
InlineStyleTransformer } = require ' nylas-exports '
2015-03-26 03:41:48 +08:00
ModelQuery = require ' ../../src/flux/models/query '
2015-12-08 07:34:03 +08:00
2015-05-20 07:06:59 +08:00
_ = require ' underscore '
2015-12-22 03:50:52 +08:00
{ ipcRenderer } = require ' electron '
2015-02-25 08:19:47 +08:00
2015-12-22 03:50:52 +08:00
msgFromMe = null
2015-03-11 02:02:46 +08:00
fakeThread = null
2015-12-22 03:50:52 +08:00
fakeMessages = null
2015-03-11 02:02:46 +08:00
fakeMessage1 = null
fakeMessage2 = null
2015-05-29 09:13:46 +08:00
msgWithReplyTo = null
2015-09-02 01:11:50 +08:00
messageWithStyleTags = null
2015-09-05 03:53:17 +08:00
fakeMessageWithFiles = null
2015-12-22 03:50:52 +08:00
msgWithReplyToDuplicates = null
2016-01-12 05:23:30 +08:00
account = null
2015-02-25 08:19:47 +08:00
2015-11-28 03:49:24 +08:00
class TestExtension extends ComposerExtension
2015-12-31 00:36:47 +08:00
@prepareNewDraft: ({draft}) ->
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> <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\"> / </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> <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
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> <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\"> / </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> <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 ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , ' newWindow ' ) . andCallFake ->
2015-10-03 09:43:58 +08:00
for id , session of DraftStore . _draftSessions
if session . teardown
DraftStore . _doneWithSession ( session )
DraftStore._draftSessions = { }
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> <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\"> / </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> <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
2015-02-25 08:19:47 +08:00
describe " creating drafts " , ->
beforeEach ->
2015-12-08 07:34:03 +08:00
spyOn ( DraftStore , " _prepareBodyForQuoting " ) . andCallFake (body) ->
Promise . resolve ( body )
2015-11-24 14:09:17 +08:00
spyOn ( ipcRenderer , " send " ) . andCallFake (message, body) ->
2015-09-02 01:11:50 +08:00
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.
2015-11-24 14:09:17 +08:00
_ . defer -> DraftStore . _onInlineStylesResult ( { } , body )
2015-09-02 01:11:50 +08:00
2016-01-12 05:23:30 +08:00
account = AccountStore . accounts ( ) [ 0 ]
2015-03-11 02:02:46 +08:00
fakeThread = new Thread
id: ' fake-thread-id '
2016-01-12 05:23:30 +08:00
accountId: account . id
2015-03-11 02:02:46 +08:00
subject: ' Fake Subject '
fakeMessage1 = new Message
id: ' fake-message-1 '
2016-01-12 05:23:30 +08:00
accountId: account . id
2015-05-15 08:08:30 +08:00
to: [ new Contact ( email: ' ben@nylas.com ' ) , new Contact ( email: ' evan@nylas.com ' ) ]
2016-01-12 05:23:30 +08:00
cc: [ new Contact ( email: ' mg@nylas.com ' ) , account . me ( ) ]
2015-05-15 08:08:30 +08:00
bcc: [ new Contact ( email: ' recruiting@nylas.com ' ) ]
2015-03-11 02:02:46 +08:00
from: [ new Contact ( email: ' customer@example.com ' , name: ' Customer ' ) ]
threadId: ' fake-thread-id '
body: ' Fake Message 1 '
2015-03-12 06:55:04 +08:00
subject: ' Fake Subject '
2015-03-11 02:02:46 +08:00
date: new Date ( 1415814587 )
fakeMessage2 = new Message
id: ' fake-message-2 '
2016-01-12 05:23:30 +08:00
accountId: account . id
2015-03-11 02:02:46 +08:00
to: [ new Contact ( email: ' customer@example.com ' ) ]
2015-05-15 08:08:30 +08:00
from: [ new Contact ( email: ' ben@nylas.com ' ) ]
2015-03-11 02:02:46 +08:00
threadId: ' fake-thread-id '
body: ' Fake Message 2 '
2015-03-12 06:55:04 +08:00
subject: ' Re: Fake Subject '
2015-03-11 02:02:46 +08:00
date: new Date ( 1415814587 )
2015-09-05 03:53:17 +08:00
fakeMessageWithFiles = new Message
id: ' fake-message-with-files '
2016-01-12 05:23:30 +08:00
accountId: account . id
2015-09-05 03:53:17 +08:00
to: [ new Contact ( email: ' ben@nylas.com ' ) , new Contact ( email: ' evan@nylas.com ' ) ]
2016-01-12 05:23:30 +08:00
cc: [ new Contact ( email: ' mg@nylas.com ' ) , account . me ( ) ]
2015-09-05 03:53:17 +08:00
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 )
2015-03-27 10:07:21 +08:00
msgFromMe = new Message
id: ' fake-message-3 '
2016-01-12 05:23:30 +08:00
accountId: account . id
2015-03-27 10:07:21 +08:00
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 ' ) ]
2016-01-12 05:23:30 +08:00
from: [ account . me ( ) ]
2015-03-27 10:07:21 +08:00
threadId: ' fake-thread-id '
body: ' Fake Message 2 '
subject: ' Re: Fake Subject '
date: new Date ( 1415814587 )
2015-05-29 09:13:46 +08:00
msgWithReplyTo = new Message
id: ' fake-message-reply-to '
2016-01-12 05:23:30 +08:00
accountId: account . id
2015-05-29 09:13:46 +08:00
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 )
2015-08-05 04:57:12 +08:00
msgWithReplyToDuplicates = new Message
id: ' fake-message-reply-to-duplicates '
2016-01-12 05:23:30 +08:00
accountId: account . id
2015-08-05 04:57:12 +08:00
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 )
2015-09-02 01:11:50 +08:00
messageWithStyleTags = new Message
id: ' message-with-style-tags '
2016-01-12 05:23:30 +08:00
accountId: account . id
2015-09-02 01:11:50 +08:00
to: [ new Contact ( email: ' ben@nylas.com ' ) , new Contact ( email: ' evan@nylas.com ' ) ]
2016-01-12 05:23:30 +08:00
cc: [ new Contact ( email: ' mg@nylas.com ' ) , account . me ( ) ]
2015-09-02 01:11:50 +08:00
bcc: [ new Contact ( email: ' recruiting@nylas.com ' ) ]
from: [ new Contact ( email: ' customer@example.com ' , name: ' Customer ' ) ]
threadId: ' fake-thread-id '
body: ' <style>div {color: red;}</style><div>Fake Message 1</div> '
subject: ' Fake Subject '
date: new Date ( 1415814587 )
2015-03-11 02:02:46 +08:00
fakeMessages =
' fake-message-1 ' : fakeMessage1
2015-03-27 10:07:21 +08:00
' fake-message-3 ' : msgFromMe
2015-03-11 02:02:46 +08:00
' fake-message-2 ' : fakeMessage2
2015-05-29 09:13:46 +08:00
' fake-message-reply-to ' : msgWithReplyTo
2015-09-05 03:53:17 +08:00
' fake-message-with-files ' : fakeMessageWithFiles
2015-08-05 04:57:12 +08:00
' fake-message-reply-to-duplicates ' : msgWithReplyToDuplicates
2015-09-02 01:11:50 +08:00
' message-with-style-tags ' : messageWithStyleTags
2015-03-11 02:02:46 +08:00
2015-02-25 08:19:47 +08:00
spyOn ( DatabaseStore , ' find ' ) . andCallFake (klass, id) ->
2015-03-26 03:41:48 +08:00
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
2015-02-25 08:19:47 +08:00
spyOn ( DatabaseStore , ' run ' ) . andCallFake (query) ->
return Promise . resolve ( fakeMessage2 ) if query . _klass is Message
return Promise . reject ( new Error ( ' Not Stubbed ' ) )
2015-12-18 03:46:05 +08:00
spyOn ( DatabaseTransaction . prototype , ' persistModel ' ) . andCallFake -> Promise . resolve ( )
2015-02-25 08:19:47 +08:00
2015-06-16 09:29:59 +08:00
afterEach ->
# Have to cleanup the DraftStoreProxy objects or we'll get a memory
# leak error
for id , session of DraftStore . _draftSessions
DraftStore . _doneWithSession ( session )
2015-02-25 08:19:47 +08:00
describe " onComposeReply " , ->
beforeEach ->
runs ->
DraftStore . _onComposeReply ( { threadId: fakeThread . id , messageId: fakeMessage1 . id } )
waitsFor ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-02-25 08:19:47 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-02-25 08:19:47 +08:00
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 )
2015-09-02 01:11:50 +08:00
it " should sanitize the HTML " , ->
2015-12-08 07:34:03 +08:00
expect ( DraftStore . _prepareBodyForQuoting ) . toHaveBeenCalled ( )
2015-09-02 01:11:50 +08:00
2015-05-29 09:13:46 +08:00
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 ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-05-29 09:13:46 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-05-29 09:13:46 +08:00
expect ( @ model . to ) . toEqual ( msgWithReplyTo . replyTo )
expect ( @ model . cc . length ) . toBe 0
expect ( @ model . bcc . length ) . toBe 0
2015-03-27 10:07:21 +08:00
2015-05-29 09:13:46 +08:00
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 ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-05-29 09:13:46 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-05-29 09:13:46 +08:00
expect ( @ model . to ) . toEqual ( msgFromMe . to )
expect ( @ model . cc . length ) . toBe 0
expect ( @ model . bcc . length ) . toBe 0
2015-03-27 10:07:21 +08:00
2015-02-25 08:19:47 +08:00
describe " onComposeReplyAll " , ->
beforeEach ->
runs ->
DraftStore . _onComposeReplyAll ( { threadId: fakeThread . id , messageId: fakeMessage1 . id } )
waitsFor ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-02-25 08:19:47 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-02-25 08:19:47 +08:00
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
2015-05-15 08:08:30 +08:00
expect ( ccEmails . sort ( ) ) . toEqual ( [ ' ben@nylas.com ' , ' evan@nylas.com ' , ' mg@nylas.com ' ] )
2015-02-25 08:19:47 +08:00
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
2016-01-12 05:23:30 +08:00
expect ( ccEmails . indexOf ( account . me ( ) . email ) ) . toEqual ( - 1 )
2015-02-25 08:19:47 +08:00
it " should set the replyToMessageId to the previous message ' s ids " , ->
expect ( @ model . replyToMessageId ) . toEqual ( fakeMessage1 . id )
2015-09-02 01:11:50 +08:00
it " should sanitize the HTML " , ->
2015-12-08 07:34:03 +08:00
expect ( DraftStore . _prepareBodyForQuoting ) . toHaveBeenCalled ( )
2015-09-02 01:11:50 +08:00
2015-05-29 09:13:46 +08:00
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 ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-05-29 09:13:46 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-05-29 09:13:46 +08:00
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 )
2015-08-05 04:57:12 +08:00
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 ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-08-05 04:57:12 +08:00
runs ->
2015-12-18 03:46:05 +08:00
model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-08-05 04:57:12 +08:00
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 ' ] )
2015-05-29 09:13:46 +08:00
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 ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-05-29 09:13:46 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-05-29 09:13:46 +08:00
expect ( @ model . to ) . toEqual ( msgFromMe . to )
expect ( @ model . cc ) . toEqual ( msgFromMe . cc )
expect ( @ model . bcc . length ) . toBe 0
2015-09-05 03:53:17 +08:00
describe " forwarding with attachments " , ->
it " should include the attached files " , ->
runs ->
DraftStore . _onComposeForward ( { threadId: fakeThread . id , messageId: fakeMessageWithFiles . id } )
waitsFor ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-09-05 03:53:17 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-09-05 03:53:17 +08:00
expect ( @ model . files . length ) . toBe 2
expect ( @ model . files [ 0 ] . filename ) . toBe " test.jpg "
2015-02-25 08:19:47 +08:00
describe " onComposeForward " , ->
beforeEach ->
runs ->
DraftStore . _onComposeForward ( { threadId: fakeThread . id , messageId: fakeMessage1 . id } )
waitsFor ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-02-25 08:19:47 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-02-25 08:19:47 +08:00
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 )
2015-09-02 01:11:50 +08:00
it " should sanitize the HTML " , ->
2015-12-08 07:34:03 +08:00
expect ( DraftStore . _prepareBodyForQuoting ) . toHaveBeenCalled ( )
2015-09-02 01:11:50 +08:00
2015-09-07 05:55:06 +08:00
describe " popout drafts " , ->
beforeEach ->
spyOn ( Actions , " composePopoutDraft " )
it " can popout a reply " , ->
runs ->
DraftStore . _onComposeReply ( { threadId: fakeThread . id , messageId: fakeMessage1 . id , popout: true } ) . catch (error) -> throw new Error ( error )
waitsFor ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-09-07 05:55:06 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-09-07 05:55:06 +08:00
expect ( Actions . composePopoutDraft ) . toHaveBeenCalledWith ( @ model . clientId )
it " can popout a forward " , ->
runs ->
DraftStore . _onComposeForward ( { threadId: fakeThread . id , messageId: fakeMessage1 . id , popout: true } ) . catch (error) -> throw new Error ( error )
waitsFor ->
2015-12-18 03:46:05 +08:00
DatabaseTransaction . prototype . persistModel . callCount > 0
2015-09-07 05:55:06 +08:00
runs ->
2015-12-18 03:46:05 +08:00
@model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-09-07 05:55:06 +08:00
expect ( Actions . composePopoutDraft ) . toHaveBeenCalledWith ( @ model . clientId )
2015-02-25 08:19:47 +08:00
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) ->
2015-09-23 07:40:33 +08:00
waitsForPromise ->
DraftStore . _newMessageWithContext ( context , attributesCallback ) . then ->
2015-12-18 03:46:05 +08:00
model = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-09-23 07:40:33 +08:00
modelCallback ( model ) if modelCallback
2015-02-25 08:19:47 +08:00
it " should create a new message " , ->
@ _callNewMessageWithContext { threadId: fakeThread . id }
, (thread, message) ->
{ }
, (model) ->
expect ( model . constructor ) . toBe ( Message )
2015-08-29 02:12:53 +08:00
it " should setup a draft session for the draftClientId, so that a subsequent request for the session ' s draft resolves immediately. " , ->
2015-06-06 02:38:30 +08:00
@ _callNewMessageWithContext { threadId: fakeThread . id }
, (thread, message) ->
{ }
, (model) ->
2015-08-29 02:12:53 +08:00
session = DraftStore . sessionForClientId ( model . id ) . value ( )
expect ( session . draft ( ) ) . toBe ( model )
2015-06-06 02:38:30 +08:00
2015-03-12 06:55:04 +08:00
it " should set the subject of the new message automatically " , ->
@ _callNewMessageWithContext { threadId: fakeThread . id }
, (thread, message) ->
{ }
, (model) ->
expect ( model . subject ) . toEqual ( " Re: Fake Subject " )
2015-02-25 08:19:47 +08:00
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> <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\"> / </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> <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 ->
2015-12-14 15:32:24 +08:00
ExtensionRegistry . Composer . register ( TestExtension )
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> <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\"> / </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> <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
afterEach ->
2015-12-14 15:32:24 +08:00
ExtensionRegistry . Composer . unregister ( TestExtension )
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> <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\"> / </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> <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 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 )
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) ->
2015-03-12 06:55:04 +08:00
describe " when a reply-to message is provided by the attributesCallback " , ->
2015-02-25 08:19:47 +08:00
it " should include quoted text in the new message " , ->
@ _callNewMessageWithContext { threadId: fakeThread . id }
, (thread, message) ->
2015-03-11 09:07:40 +08:00
replyToMessage: fakeMessage1
2015-02-25 08:19:47 +08:00
, (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) ->
2015-03-11 09:07:40 +08:00
replyToMessage: fakeMessage1
2015-02-25 08:19:47 +08:00
, (model) ->
2015-03-25 05:03:30 +08:00
expect ( model . body . search ( /On .+, at .+, Customer <customer@example.com> wrote/ ) > 0 ) . toBe ( true )
2015-02-25 08:19:47 +08:00
2015-03-12 06:55:04 +08:00
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 " )
2015-02-25 08:19:47 +08:00
it " should only include the sender ' s name if it was available " , ->
@ _callNewMessageWithContext { threadId: fakeThread . id }
, (thread, message) ->
2015-03-11 09:07:40 +08:00
replyToMessage: fakeMessage2
2015-02-25 08:19:47 +08:00
, (model) ->
2015-05-15 08:08:30 +08:00
expect ( model . body . search ( /On .+, at .+, ben@nylas.com wrote:/ ) > 0 ) . toBe ( true )
2015-02-25 08:19:47 +08:00
2015-03-12 06:55:04 +08:00
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) ->
2015-05-15 08:08:30 +08:00
expect ( model . body . indexOf ( ' From: ben@nylas.com ' ) > 0 ) . toBe ( true )
2015-03-12 06:55:04 +08:00
expect ( model . body . indexOf ( ' Subject: Re: Fake Subject ' ) > 0 ) . toBe ( true )
expect ( model . body . indexOf ( ' To: customer@example.com ' ) > 0 ) . toBe ( true )
2015-02-25 08:19:47 +08:00
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 )
2015-03-10 02:17:22 +08:00
{ }
2015-05-20 03:07:08 +08:00
2015-12-08 07:34:03 +08:00
describe " sanitizing draft bodies " , ->
it " should transform inline styles and sanitize unsafe html " , ->
spyOn ( InlineStyleTransformer , ' run ' ) . andCallFake (input) => Promise . resolve ( input )
spyOn ( SanitizeTransformer , ' run ' ) . andCallFake (input) => Promise . resolve ( input )
input = " test 123 "
DraftStore . _prepareBodyForQuoting ( input )
expect ( InlineStyleTransformer . run ) . toHaveBeenCalledWith ( input )
advanceClock ( )
expect ( SanitizeTransformer . run ) . toHaveBeenCalledWith ( input , SanitizeTransformer . Preset . UnsafeOnly )
2015-03-24 07:33:28 +08:00
describe " onDestroyDraft " , ->
beforeEach ->
2015-08-07 03:22:06 +08:00
@draftSessionTeardown = jasmine . createSpy ( ' draft teardown ' )
2015-05-20 03:07:08 +08:00
@session =
2015-03-24 07:33:28 +08:00
draft: ->
pristine: false
changes:
commit: -> Promise . resolve ( )
2015-08-07 03:22:06 +08:00
teardown: ->
teardown: @ draftSessionTeardown
2015-05-20 03:07:08 +08:00
DraftStore._draftSessions = { " abc " : @ session }
spyOn ( Actions , ' queueTask ' )
2015-03-24 07:33:28 +08:00
2015-08-07 03:22:06 +08:00
it " should teardown the draft session, ensuring no more saves are made " , ->
2015-03-24 07:33:28 +08:00
DraftStore . _onDestroyDraft ( ' abc ' )
2015-08-07 03:22:06 +08:00
expect ( @ draftSessionTeardown ) . toHaveBeenCalled ( )
2015-03-24 07:33:28 +08:00
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> <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\"> / </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> <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 " , ->
2015-03-24 07:33:28 +08:00
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> <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\"> / </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> <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 ( )
2015-03-24 07:33:28 +08:00
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 " , ->
2015-05-20 03:07:08 +08:00
spyOn ( DraftStore , ' _doneWithSession ' )
DraftStore . _onDestroyDraft ( ' abc ' )
expect ( DraftStore . _doneWithSession ) . toHaveBeenCalledWith ( @ session )
it " should close the window if it ' s a popout " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , " close " )
2015-05-20 03:07:08 +08:00
spyOn ( DraftStore , " _isPopout " ) . andReturn true
2015-03-24 07:33:28 +08:00
DraftStore . _onDestroyDraft ( ' abc ' )
2015-11-12 02:25:11 +08:00
expect ( NylasEnv . close ) . toHaveBeenCalled ( )
2015-05-20 03:07:08 +08:00
it " should NOT close the window if isn ' t a popout " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , " close " )
2015-05-20 03:07:08 +08:00
spyOn ( DraftStore , " _isPopout " ) . andReturn false
DraftStore . _onDestroyDraft ( ' abc ' )
2015-11-12 02:25:11 +08:00
expect ( NylasEnv . close ) . not . toHaveBeenCalled ( )
2015-03-24 07:33:28 +08:00
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 " , ->
2016-02-05 06:14:24 +08:00
callback = jasmine . createSpy ( ' callback ' )
expect ( DraftStore . _onBeforeUnload ( callback ) ) . toBe ( false )
expect ( callback ) . not . toHaveBeenCalled ( )
2015-03-24 07:33:28 +08:00
@ resolve ( )
2015-07-18 07:36:28 +08:00
advanceClock ( 1000 )
2016-02-05 06:14:24 +08:00
expect ( callback ) . toHaveBeenCalled ( )
2015-03-24 07:33:28 +08:00
2015-07-18 07:36:28 +08:00
describe " when drafts return immediately fulfilled commit promises " , ->
2015-03-24 07:33:28 +08:00
beforeEach ->
2015-07-18 07:36:28 +08:00
DraftStore._draftSessions = { " abc " : {
2015-03-24 07:33:28 +08:00
changes:
2015-07-18 07:36:28 +08:00
commit: => Promise . resolve ( )
2015-03-24 07:33:28 +08:00
draft: ->
pristine: false
} }
2015-11-12 02:25:11 +08:00
it " should still wait one tick before firing NylasEnv.close again " , ->
2016-02-05 06:14:24 +08:00
callback = jasmine . createSpy ( ' callback ' )
expect ( DraftStore . _onBeforeUnload ( callback ) ) . toBe ( false )
expect ( callback ) . not . toHaveBeenCalled ( )
2015-07-18 07:36:28 +08:00
advanceClock ( )
2016-02-05 06:14:24 +08:00
expect ( callback ) . toHaveBeenCalled ( )
2015-07-18 07:36:28 +08:00
describe " when there are no drafts " , ->
beforeEach ->
DraftStore._draftSessions = { }
2015-03-24 07:33:28 +08:00
it " should return true and allow the window to close " , ->
expect ( DraftStore . _onBeforeUnload ( ) ) . toBe ( true )
2015-03-13 05:48:56 +08:00
describe " sending a draft " , ->
beforeEach ->
2016-01-28 02:31:54 +08:00
@draft = new Message
clientId: " local-123 " ,
threadId: " thread-123 " ,
replyToMessageId: " message-123 "
2016-01-28 16:48:45 +08:00
uploads: [ ' stub ' ]
2015-03-13 05:48:56 +08:00
DraftStore._draftSessions = { }
feat(work): Create the "Work" window, move TaskQueue, Nylas sync workers
Summary:
Move sync workers and Edgehill token checks to work window
Move the task queue and database setup to the work window
Move ContactStore background refresh to work window
Store the task queue in the database
WIP
The TaskQueue now puts tasks in the database instead of in a file, which also means it can be observed
Move all delta sync and initial sync to a package, make NylasSyncStore which exposes read-only sync state
DraftStore no longer reads task status. Once you set the "sending" bit on a draft, it never gets unset. But that's fine actually.
If your package lists windowTypes, you *only* get loaded in those windowTypes. If you specify no windowTypes, you get loaded in the root window.
This means that onboarding, worker-ui, worker-sync, etc. no longer get loaded into the main window
ActivitySidebar has a special little store that observes the task queue since it's no longer in the window
Move "toggle component regions" / "toggle react remote" to the Developer menu
Move sync worker specs, update draft store specs to not rely on TaskQueue at all
Test Plan: Run existing tests, all pass
Reviewers: dillon, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D1936
2015-08-28 07:39:40 +08:00
DraftStore._draftsSending = { }
fix(tasks): don't continue if dependent task fails
Summary:
Fixes T4291
If I made a final edit to a pre-existing draft and sent, we'd queue a
`SyncbackDraftTask` before a `SendDraftTask`. This is important because
since we have a valid draft `server_id`, the `SendDraftTask` will send by
server_id, not by POSTing the whole body.
If the `SyncbackDraftTask` fails, then we had a very serious issue whereby
the `SendDraftTask` would keep on sending. Unfortunately the server never
got the latest changes and sent the wrong version of the draft. This
incorrect version would show up later when the `/send` endpoint returned
the message that got actually sent.
The solution was to make any queued `SendDraftTask` fail if a dependent
`SyncbackDraftTask` failed.
This meant we needed to make the requirements for `shouldWaitForTask`
stricter, and block if tasks failed.
Unfortunatley there was no infrastructure in place to do this.
The first change was to change `shouldWaitForTask` to `isDependentTask`.
If we're going to fail when a dependent task fails, I wanted the method
name to reflect this.
Now, if a dependent task fails, we recursively check the dependency tree
(and check for cycles) and `dequeue` anything that needed that to succeed.
I chose `dequeue` as the default action because it seemed as though all
current uses of `shouldWaitForTask` really should bail if their
dependencies fail. It's possible you don't want your task dequeued in this
dependency case. You can return the special `Task.DO_NOT_DEQUEUE_ME`
constant from the `onDependentTaskError` method.
When a task gets dequeued because of the reason above, the
`onDependentTaskError` callback gets fired. This gives tasks like the
`SendDraftTask` a chance to notify the user that it bailed. Not all tasks
need to notify.
The next big issue was a better way to determine if a task truely errored
to the point that we need to dequeue dependencies. In the Developer Status
area we were showing tasks that had errored as "Green" because we caught
the error and resolved with `Task.Status.Finished`. This used to be fine
since nothing life-or-death cared if a task errored or not. Now that it
might cause abortions down the line, we needed a more robust method then
this.
For one I changed `Task.Status.Finished` to a variety of finish types
including `Task.Status.Success`. The way you "error" out is to `throw` or
`Promise.reject` an `Error` object from the `performRemote` method. This
allows us to propagate API errors up, and acts as a safety net that can
catch any malformed code or unexpected responses.
The developer bar now shows a much richer set of statuses instead of a
binary one, which was REALLY helpful in debugging this. We also record
when a Task got dequeued because of the conditions introduced here.
Once all this was working we still had an issue of sending old drafts.
If after a `SyncbackDraftTask` failed, now we'd block the send and notify
the users as such. However, if we tried to send again, there was a
separate issue whereby we wouldn't queue another `SyncbackDraftTask` to
update the server with the latest information. Since our changes were
persisted to the DB, we thought we had no changes, and therefore didn't
need to queue a `SyncbackDraftTask`.
The fix to this is to always force the creation of a `SyncbackDraftTask`
before send regardless of the state of the `DraftStoreProxy`.
Test Plan: new tests. Lots of manual testing
Reviewers: bengotow
Reviewed By: bengotow
Subscribers: mg
Maniphest Tasks: T4291
Differential Revision: https://phab.nylas.com/D2156
2015-10-22 01:33:43 +08:00
@forceCommit = false
2015-05-16 01:45:18 +08:00
proxy =
prepare: -> Promise . resolve ( proxy )
2015-08-07 03:22:06 +08:00
teardown: ->
2016-01-27 11:12:46 +08:00
draft: => @ draft
2015-03-13 05:48:56 +08:00
changes:
fix(tasks): don't continue if dependent task fails
Summary:
Fixes T4291
If I made a final edit to a pre-existing draft and sent, we'd queue a
`SyncbackDraftTask` before a `SendDraftTask`. This is important because
since we have a valid draft `server_id`, the `SendDraftTask` will send by
server_id, not by POSTing the whole body.
If the `SyncbackDraftTask` fails, then we had a very serious issue whereby
the `SendDraftTask` would keep on sending. Unfortunately the server never
got the latest changes and sent the wrong version of the draft. This
incorrect version would show up later when the `/send` endpoint returned
the message that got actually sent.
The solution was to make any queued `SendDraftTask` fail if a dependent
`SyncbackDraftTask` failed.
This meant we needed to make the requirements for `shouldWaitForTask`
stricter, and block if tasks failed.
Unfortunatley there was no infrastructure in place to do this.
The first change was to change `shouldWaitForTask` to `isDependentTask`.
If we're going to fail when a dependent task fails, I wanted the method
name to reflect this.
Now, if a dependent task fails, we recursively check the dependency tree
(and check for cycles) and `dequeue` anything that needed that to succeed.
I chose `dequeue` as the default action because it seemed as though all
current uses of `shouldWaitForTask` really should bail if their
dependencies fail. It's possible you don't want your task dequeued in this
dependency case. You can return the special `Task.DO_NOT_DEQUEUE_ME`
constant from the `onDependentTaskError` method.
When a task gets dequeued because of the reason above, the
`onDependentTaskError` callback gets fired. This gives tasks like the
`SendDraftTask` a chance to notify the user that it bailed. Not all tasks
need to notify.
The next big issue was a better way to determine if a task truely errored
to the point that we need to dequeue dependencies. In the Developer Status
area we were showing tasks that had errored as "Green" because we caught
the error and resolved with `Task.Status.Finished`. This used to be fine
since nothing life-or-death cared if a task errored or not. Now that it
might cause abortions down the line, we needed a more robust method then
this.
For one I changed `Task.Status.Finished` to a variety of finish types
including `Task.Status.Success`. The way you "error" out is to `throw` or
`Promise.reject` an `Error` object from the `performRemote` method. This
allows us to propagate API errors up, and acts as a safety net that can
catch any malformed code or unexpected responses.
The developer bar now shows a much richer set of statuses instead of a
binary one, which was REALLY helpful in debugging this. We also record
when a Task got dequeued because of the conditions introduced here.
Once all this was working we still had an issue of sending old drafts.
If after a `SyncbackDraftTask` failed, now we'd block the send and notify
the users as such. However, if we tried to send again, there was a
separate issue whereby we wouldn't queue another `SyncbackDraftTask` to
update the server with the latest information. Since our changes were
persisted to the DB, we thought we had no changes, and therefore didn't
need to queue a `SyncbackDraftTask`.
The fix to this is to always force the creation of a `SyncbackDraftTask`
before send regardless of the state of the `DraftStoreProxy`.
Test Plan: new tests. Lots of manual testing
Reviewers: bengotow
Reviewed By: bengotow
Subscribers: mg
Maniphest Tasks: T4291
Differential Revision: https://phab.nylas.com/D2156
2015-10-22 01:33:43 +08:00
commit: ({force}={}) =>
@forceCommit = force
Promise . resolve ( )
2016-01-27 11:12:46 +08:00
2016-01-28 02:31:54 +08:00
DraftStore . _draftSessions [ @ draft . clientId ] = proxy
2015-05-20 03:07:08 +08:00
spyOn ( DraftStore , " _doneWithSession " ) . andCallThrough ( )
2015-03-13 05:48:56 +08:00
spyOn ( DraftStore , " trigger " )
2015-10-03 08:04:15 +08:00
spyOn ( SoundRegistry , " playSound " )
feat(tasks): add Create, Update, Destroy tasks plus spec & lint fixes
Summary:
1. **Generic CUD Tasks**: There is now a generic `CreateModelTask`,
`UpdateModelTask`, and `DestroyModelTask`. These can either be used as-is
or trivially overridden to easily update simple objects. Hopefully all of
the boilerplate rollback, error handling, and undo logic won't have to be
re-duplicated on every task. There are also tests for these tasks. We use
them to perform mutating actions on `Metadata` objects.
1. **Failing on Promise Rejects**: Turns out that if a Promise rejected
due to an error or `Promise.reject` we were ignoring it and letting tests
pass. Now, tests will Fail if any unhandled promise rejects. This
uncovered a variety of errors throughout the test suite that had to be
fixed. The most significant one was during the `theme-manager` tests when
all packages (and their stores with async DB requests) was loaded. Long
after the `theme-manager` specs finished, those DB requests were
(somtimes) silently failing.
1. **Globally stub `DatabaseStore._query`**: All tests shouldn't actually
make queries on the database. Furthremore, the `inTransaction` block
doesn't resolve at all unless `_query` is stubbed. Instead of manually
remembering to do this in every test that touches the DB, it's now mocked
in `spec_helper`. This broke a handful of tests that needed to be manually
fixed.
1. **ESLint Fixes**: Some minor fixes to the linter config to prevent
yelling about minor ES6 things and ensuring we have the correct parser.
Test Plan: new tests
Reviewers: bengotow, juan, drew
Differential Revision: https://phab.nylas.com/D2419
Remove cloudState and N1-Send-Later
2016-01-05 08:39:14 +08:00
spyOn ( Actions , " queueTask " )
2015-10-03 08:04:15 +08:00
it " plays a sound immediately when sending draft " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv . config , " get " ) . andReturn true
2016-01-28 02:31:54 +08:00
DraftStore . _onSendDraft ( @ draft . clientId )
2015-11-12 02:25:11 +08:00
expect ( NylasEnv . config . get ) . toHaveBeenCalledWith ( " core.sending.sounds " )
2015-10-03 08:04:15 +08:00
expect ( SoundRegistry . playSound ) . toHaveBeenCalledWith ( " hit-send " )
it " doesn ' t plays a sound if the setting is off " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv . config , " get " ) . andReturn false
2016-01-28 02:31:54 +08:00
DraftStore . _onSendDraft ( @ draft . clientId )
2015-11-12 02:25:11 +08:00
expect ( NylasEnv . config . get ) . toHaveBeenCalledWith ( " core.sending.sounds " )
2015-10-03 08:04:15 +08:00
expect ( SoundRegistry . playSound ) . not . toHaveBeenCalled ( )
2015-03-13 05:48:56 +08:00
it " sets the sending state when sending " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , " isMainWindow " ) . andReturn true
2016-01-28 02:31:54 +08:00
DraftStore . _onSendDraft ( @ draft . clientId )
expect ( DraftStore . isSendingDraft ( @ draft . clientId ) ) . toBe true
2015-11-19 04:32:07 +08:00
# Since all changes haven't been applied yet, we want to ensure that
# no view of the draft renders the draft as if its sending, but with
# the wrong text.
it " does NOT trigger until the latest changes have been applied " , ->
spyOn ( NylasEnv , " isMainWindow " ) . andReturn true
runs ->
2016-01-28 02:31:54 +08:00
DraftStore . _onSendDraft ( @ draft . clientId )
2015-11-19 04:32:07 +08:00
expect ( DraftStore . trigger ) . not . toHaveBeenCalled ( )
waitsFor ->
Actions . queueTask . calls . length > 0
runs ->
# Normally, the session.changes.commit will persist to the
# Database. Since that's stubbed out, we need to manually invoke
# to database update event to get the trigger (which we want to
# test) to fire
DraftStore . _onDataChanged
objectClass: " Message "
objects: [ draft: true ]
2016-01-28 02:31:54 +08:00
expect ( DraftStore . isSendingDraft ( @ draft . clientId ) ) . toBe true
2015-05-20 03:07:08 +08:00
expect ( DraftStore . trigger ) . toHaveBeenCalled ( )
2015-11-19 04:32:07 +08:00
expect ( DraftStore . trigger . calls . length ) . toBe 1
2015-03-13 05:48:56 +08:00
it " returns false if the draft hasn ' t been seen " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , " isMainWindow " ) . andReturn true
2016-01-28 02:31:54 +08:00
expect ( DraftStore . isSendingDraft ( @ draft . clientId ) ) . toBe false
2015-03-13 05:48:56 +08:00
it " closes the window if it ' s a popout " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , " getWindowType " ) . andReturn " composer "
spyOn ( NylasEnv , " isMainWindow " ) . andReturn false
spyOn ( NylasEnv , " close " )
2015-05-02 00:58:51 +08:00
runs ->
2016-01-28 02:31:54 +08:00
DraftStore . _onSendDraft ( @ draft . clientId )
2015-11-12 02:25:11 +08:00
waitsFor " N1 to close " , ->
NylasEnv . close . calls . length > 0
2015-03-13 05:48:56 +08:00
it " doesn ' t close the window if it ' s inline " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , " getWindowType " ) . andReturn " other "
spyOn ( NylasEnv , " isMainWindow " ) . andReturn false
spyOn ( NylasEnv , " close " )
2015-05-20 03:07:08 +08:00
spyOn ( DraftStore , " _isPopout " ) . andCallThrough ( )
runs ->
2016-01-28 02:31:54 +08:00
DraftStore . _onSendDraft ( @ draft . clientId )
2015-05-20 03:07:08 +08:00
waitsFor ->
DraftStore . _isPopout . calls . length > 0
runs ->
2015-11-12 02:25:11 +08:00
expect ( NylasEnv . close ) . not . toHaveBeenCalled ( )
2015-03-13 05:48:56 +08:00
2016-01-27 11:12:46 +08:00
it " queues the correct SendDraftTask " , ->
2015-05-20 03:07:08 +08:00
runs ->
2016-01-28 02:31:54 +08:00
DraftStore . _onSendDraft ( @ draft . clientId )
2015-05-20 03:07:08 +08:00
waitsFor ->
DraftStore . _doneWithSession . calls . length > 0
runs ->
expect ( Actions . queueTask ) . toHaveBeenCalled ( )
task = Actions . queueTask . calls [ 0 ] . args [ 0 ]
2016-01-26 06:14:09 +08:00
expect ( task instanceof SendDraftTask ) . toBe true
2016-01-27 11:12:46 +08:00
expect ( task . draft ) . toBe @ draft
2016-01-26 06:14:09 +08:00
it " queues a SendDraftTask " , ->
2015-05-20 03:07:08 +08:00
runs ->
2016-01-28 02:31:54 +08:00
DraftStore . _onSendDraft ( @ draft . clientId )
2015-05-20 03:07:08 +08:00
waitsFor ->
DraftStore . _doneWithSession . calls . length > 0
runs ->
expect ( Actions . queueTask ) . toHaveBeenCalled ( )
task = Actions . queueTask . calls [ 0 ] . args [ 0 ]
2016-01-26 06:14:09 +08:00
expect ( task instanceof SendDraftTask ) . toBe true
2016-01-28 02:31:54 +08:00
expect ( task . draft ) . toBe ( @ draft )
2015-03-24 07:33:28 +08:00
2015-09-04 07:29:33 +08:00
it " resets the sending state if there ' s an error " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , " isMainWindow " ) . andReturn false
2016-01-28 02:31:54 +08:00
DraftStore . _draftsSending [ @ draft . clientId ] = true
Actions . draftSendingFailed ( { errorMessage: " boohoo " , draftClientId: @ draft . clientId } )
expect ( DraftStore . isSendingDraft ( @ draft . clientId ) ) . toBe false
expect ( DraftStore . trigger ) . toHaveBeenCalledWith ( @ draft . clientId )
2015-09-04 07:29:33 +08:00
it " displays a popup in the main window if there ' s an error " , ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , " isMainWindow " ) . andReturn true
2016-01-26 06:14:09 +08:00
spyOn ( FocusedContentStore , " focused " ) . andReturn ( id: " t1 " )
2016-01-30 06:23:52 +08:00
{ remote } = require ( ' electron ' )
2015-09-04 07:29:33 +08:00
dialog = remote . require ( ' dialog ' )
spyOn ( dialog , " showMessageBox " )
2016-01-26 06:14:09 +08:00
spyOn ( Actions , " composePopoutDraft " )
2016-01-28 02:31:54 +08:00
DraftStore . _draftsSending [ @ draft . clientId ] = true
Actions . draftSendingFailed ( { threadId: ' t1 ' , errorMessage: " boohoo " , draftClientId: @ draft . clientId } )
fix(tasks): don't continue if dependent task fails
Summary:
Fixes T4291
If I made a final edit to a pre-existing draft and sent, we'd queue a
`SyncbackDraftTask` before a `SendDraftTask`. This is important because
since we have a valid draft `server_id`, the `SendDraftTask` will send by
server_id, not by POSTing the whole body.
If the `SyncbackDraftTask` fails, then we had a very serious issue whereby
the `SendDraftTask` would keep on sending. Unfortunately the server never
got the latest changes and sent the wrong version of the draft. This
incorrect version would show up later when the `/send` endpoint returned
the message that got actually sent.
The solution was to make any queued `SendDraftTask` fail if a dependent
`SyncbackDraftTask` failed.
This meant we needed to make the requirements for `shouldWaitForTask`
stricter, and block if tasks failed.
Unfortunatley there was no infrastructure in place to do this.
The first change was to change `shouldWaitForTask` to `isDependentTask`.
If we're going to fail when a dependent task fails, I wanted the method
name to reflect this.
Now, if a dependent task fails, we recursively check the dependency tree
(and check for cycles) and `dequeue` anything that needed that to succeed.
I chose `dequeue` as the default action because it seemed as though all
current uses of `shouldWaitForTask` really should bail if their
dependencies fail. It's possible you don't want your task dequeued in this
dependency case. You can return the special `Task.DO_NOT_DEQUEUE_ME`
constant from the `onDependentTaskError` method.
When a task gets dequeued because of the reason above, the
`onDependentTaskError` callback gets fired. This gives tasks like the
`SendDraftTask` a chance to notify the user that it bailed. Not all tasks
need to notify.
The next big issue was a better way to determine if a task truely errored
to the point that we need to dequeue dependencies. In the Developer Status
area we were showing tasks that had errored as "Green" because we caught
the error and resolved with `Task.Status.Finished`. This used to be fine
since nothing life-or-death cared if a task errored or not. Now that it
might cause abortions down the line, we needed a more robust method then
this.
For one I changed `Task.Status.Finished` to a variety of finish types
including `Task.Status.Success`. The way you "error" out is to `throw` or
`Promise.reject` an `Error` object from the `performRemote` method. This
allows us to propagate API errors up, and acts as a safety net that can
catch any malformed code or unexpected responses.
The developer bar now shows a much richer set of statuses instead of a
binary one, which was REALLY helpful in debugging this. We also record
when a Task got dequeued because of the conditions introduced here.
Once all this was working we still had an issue of sending old drafts.
If after a `SyncbackDraftTask` failed, now we'd block the send and notify
the users as such. However, if we tried to send again, there was a
separate issue whereby we wouldn't queue another `SyncbackDraftTask` to
update the server with the latest information. Since our changes were
persisted to the DB, we thought we had no changes, and therefore didn't
need to queue a `SyncbackDraftTask`.
The fix to this is to always force the creation of a `SyncbackDraftTask`
before send regardless of the state of the `DraftStoreProxy`.
Test Plan: new tests. Lots of manual testing
Reviewers: bengotow
Reviewed By: bengotow
Subscribers: mg
Maniphest Tasks: T4291
Differential Revision: https://phab.nylas.com/D2156
2015-10-22 01:33:43 +08:00
advanceClock ( 200 )
2016-01-28 02:31:54 +08:00
expect ( DraftStore . isSendingDraft ( @ draft . clientId ) ) . toBe false
expect ( DraftStore . trigger ) . toHaveBeenCalledWith ( @ draft . clientId )
2015-09-04 07:29:33 +08:00
expect ( dialog . showMessageBox ) . toHaveBeenCalled ( )
dialogArgs = dialog . showMessageBox . mostRecentCall . args [ 1 ]
expect ( dialogArgs . detail ) . toEqual ( " boohoo " )
2016-01-26 06:14:09 +08:00
expect ( Actions . composePopoutDraft ) . not . toHaveBeenCalled
it " re-opens the draft if you ' re not looking at the thread " , ->
spyOn ( NylasEnv , " isMainWindow " ) . andReturn true
spyOn ( FocusedContentStore , " focused " ) . andReturn ( id: " t1 " )
spyOn ( Actions , " composePopoutDraft " )
2016-01-28 02:31:54 +08:00
DraftStore . _draftsSending [ @ draft . clientId ] = true
Actions . draftSendingFailed ( { threadId: ' t2 ' , errorMessage: " boohoo " , draftClientId: @ draft . clientId } )
2016-01-26 06:14:09 +08:00
advanceClock ( 200 )
expect ( Actions . composePopoutDraft ) . toHaveBeenCalled
call = Actions . composePopoutDraft . calls [ 0 ]
2016-01-28 02:31:54 +08:00
expect ( call . args [ 0 ] ) . toBe @ draft . clientId
2016-01-26 06:14:09 +08:00
expect ( call . args [ 1 ] ) . toEqual { errorMessage: " boohoo " }
it " re-opens the draft if there is no thread id " , ->
spyOn ( NylasEnv , " isMainWindow " ) . andReturn true
spyOn ( Actions , " composePopoutDraft " )
2016-01-28 02:31:54 +08:00
DraftStore . _draftsSending [ @ draft . clientId ] = true
2016-01-26 06:14:09 +08:00
spyOn ( FocusedContentStore , " focused " ) . andReturn ( null )
2016-01-28 02:31:54 +08:00
Actions . draftSendingFailed ( { errorMessage: " boohoo " , draftClientId: @ draft . clientId } )
2016-01-26 06:14:09 +08:00
advanceClock ( 200 )
expect ( Actions . composePopoutDraft ) . toHaveBeenCalled
call = Actions . composePopoutDraft . calls [ 0 ]
2016-01-28 02:31:54 +08:00
expect ( call . args [ 0 ] ) . toBe @ draft . clientId
2016-01-26 06:14:09 +08:00
expect ( call . args [ 1 ] ) . toEqual { errorMessage: " boohoo " }
2015-09-04 07:29:33 +08:00
2015-08-07 03:22:06 +08:00
describe " session teardown " , ->
2015-05-20 03:07:08 +08:00
beforeEach ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , ' isMainWindow ' ) . andReturn true
2015-08-07 03:22:06 +08:00
@draftTeardown = jasmine . createSpy ( ' draft teardown ' )
2015-05-20 03:07:08 +08:00
@session =
2015-08-29 02:12:53 +08:00
draftClientId: " abc "
2015-05-20 03:07:08 +08:00
draft: ->
pristine: false
changes:
commit: -> Promise . resolve ( )
reset: ->
2015-08-07 03:22:06 +08:00
teardown: @ draftTeardown
2015-05-20 03:07:08 +08:00
DraftStore._draftSessions = { " abc " : @ session }
DraftStore . _doneWithSession ( @ session )
2015-03-24 07:33:28 +08:00
2015-05-20 03:07:08 +08:00
it " removes from the list of draftSessions " , ->
expect ( DraftStore . _draftSessions [ " abc " ] ) . toBeUndefined ( )
2015-03-24 07:33:28 +08:00
2015-08-07 03:22:06 +08:00
it " Calls teardown on the session " , ->
expect ( @ draftTeardown ) . toHaveBeenCalled
2015-06-19 02:58:07 +08:00
describe " mailto handling " , ->
2015-09-23 07:40:33 +08:00
beforeEach ->
2015-11-12 02:25:11 +08:00
spyOn ( NylasEnv , ' isMainWindow ' ) . andReturn true
2015-09-23 07:40:33 +08:00
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> <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\"> / </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> <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 ->
2015-12-14 15:32:24 +08:00
ExtensionRegistry . Composer . register ( TestExtension )
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> <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\"> / </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> <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
afterEach ->
2015-12-14 15:32:24 +08:00
ExtensionRegistry . Composer . unregister ( TestExtension )
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> <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\"> / </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> <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 give extensions a chance to customize the draft via ext.prepareNewDraft " , ->
received = null
2015-12-18 03:46:05 +08:00
spyOn ( DatabaseTransaction . prototype , ' persistModel ' ) . andCallFake (draft) ->
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> <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\"> / </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> <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
received = draft
Promise . resolve ( )
2015-09-23 07:40:33 +08:00
waitsForPromise ->
2015-11-24 14:09:17 +08:00
DraftStore . _onHandleMailtoLink ( { } , ' mailto:bengotow@gmail.com ' ) . then ->
2015-09-23 07:40:33 +08:00
expect ( received . body . indexOf ( " Edited by TestExtension! " ) ) . toBe ( 0 )
2015-08-12 02:22:35 +08:00
2015-09-23 07:40:33 +08:00
describe " when testing subject keys " , ->
beforeEach ->
spyOn ( DraftStore , ' _finalizeAndPersistNewMessage ' ) . andCallFake (draft) ->
Promise . resolve ( { draftClientId: 123 } )
@expected = " EmailSubjectLOLOL "
it " works for lowercase " , ->
waitsForPromise =>
2015-11-24 14:09:17 +08:00
DraftStore . _onHandleMailtoLink ( { } , ' mailto:asdf@asdf.com?subject= ' + @ expected ) . then =>
2015-09-23 07:40:33 +08:00
received = DraftStore . _finalizeAndPersistNewMessage . mostRecentCall . args [ 0 ]
expect ( received . subject ) . toBe ( @ expected )
it " works for title case " , ->
waitsForPromise =>
2015-11-24 14:09:17 +08:00
DraftStore . _onHandleMailtoLink ( { } , ' mailto:asdf@asdf.com?Subject= ' + @ expected ) . then =>
2015-09-23 07:40:33 +08:00
received = DraftStore . _finalizeAndPersistNewMessage . mostRecentCall . args [ 0 ]
expect ( received . subject ) . toBe ( @ expected )
it " works for uppercase " , ->
waitsForPromise =>
2015-11-24 14:09:17 +08:00
DraftStore . _onHandleMailtoLink ( { } , ' mailto:asdf@asdf.com?SUBJECT= ' + @ expected ) . then =>
2015-09-23 07:40:33 +08:00
received = DraftStore . _finalizeAndPersistNewMessage . mostRecentCall . args [ 0 ]
expect ( received . subject ) . toBe ( @ expected )
describe " should correctly instantiate drafts for a wide range of mailto URLs " , ->
beforeEach ->
2015-12-18 03:46:05 +08:00
spyOn ( DatabaseTransaction . prototype , ' persistModel ' ) . andCallFake (draft) ->
2015-09-23 07:40:33 +08:00
Promise . resolve ( )
2015-06-19 02:58:07 +08:00
links = [
2016-01-29 07:47:59 +08:00
' mailto: '
' mailto://bengotow@gmail.com '
2015-06-19 02:58:07 +08:00
' mailto:bengotow@gmail.com '
2016-02-02 03:22:23 +08:00
' mailto:mg%40nylas.com '
2016-01-29 07:47:59 +08:00
' 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 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 ' ,
' mailto:email@address.com?&subject=test&body=type%20your%0Amessage%20here '
' mailto:?body=type%20your%0D%0Amessage%0D%0Ahere '
' mailto:?subject=Issues%20%C2%B7%20atom/electron%20%C2%B7%20GitHub&body=https://github.com/atom/electron/issues?utf8=&q=is%253Aissue+is%253Aopen+123%0A%0A '
2015-06-19 02:58:07 +08:00
]
expected = [
2016-01-29 07:47:59 +08:00
new Message ( ) ,
2015-06-19 02:58:07 +08:00
new Message (
to: [ new Contact ( name: ' bengotow@gmail.com ' , email: ' bengotow@gmail.com ' ) ]
) ,
2016-01-29 07:47:59 +08:00
new Message (
to: [ new Contact ( name: ' bengotow@gmail.com ' , email: ' bengotow@gmail.com ' ) ]
) ,
2016-02-02 03:22:23 +08:00
new Message (
to: [ new Contact ( name: ' mg@nylas.com ' , email: ' mg@nylas.com ' ) ]
) ,
2016-01-29 07:47:59 +08:00
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 ' ) ] ,
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 '
) ,
new Message (
to: [ new Contact ( name: ' email@address.com ' , email: ' email@address.com ' ) ] ,
subject: ' test '
body: ' type your \n message here '
) ,
new Message (
to: [ ] ,
body: ' type your \r \n message \r \n here '
) ,
new Message (
to: [ ] ,
subject: ' Issues · atom/electron · GitHub '
body: ' https://github.com/atom/electron/issues?utf8=&q=is%3Aissue+is%3Aopen+123 \n \n '
)
2015-06-19 02:58:07 +08:00
]
2015-09-23 07:40:33 +08:00
links . forEach (link, idx) ->
it " works for #{ link } " , ->
waitsForPromise ->
2015-11-24 14:09:17 +08:00
DraftStore . _onHandleMailtoLink ( { } , link ) . then ->
2015-09-23 07:40:33 +08:00
expectedDraft = expected [ idx ]
2015-12-18 03:46:05 +08:00
received = DatabaseTransaction . prototype . persistModel . mostRecentCall . args [ 0 ]
2015-09-23 07:40:33 +08:00
expect ( received [ ' subject ' ] ) . toEqual ( expectedDraft [ ' subject ' ] )
2015-11-14 02:58:42 +08:00
expect ( received [ ' body ' ] ) . toEqual ( expectedDraft [ ' body ' ] ) if expectedDraft [ ' body ' ]
2016-01-29 06:56:11 +08:00
[ ' to ' , ' cc ' , ' bcc ' ] . forEach (attr) ->
2016-02-02 03:22:23 +08:00
expectedDraft [ attr ] . forEach (expected, jdx) ->
actual = received [ attr ] [ jdx ]
expect ( actual instanceof Contact ) . toBe ( true )
expect ( actual . email ) . toEqual ( expected . email )
expect ( actual . name ) . toEqual ( expected . name )