2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-04-01 06:54:16 +08:00
|
|
|
React = require 'react/addons'
|
|
|
|
ReactTestUtils = React.addons.TestUtils
|
|
|
|
proxyquire = require 'proxyquire'
|
|
|
|
|
2015-05-20 07:06:59 +08:00
|
|
|
{NylasTestUtils,
|
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
|
|
|
AccountStore,
|
2015-04-01 06:54:16 +08:00
|
|
|
ContactStore,
|
|
|
|
Contact,
|
|
|
|
Utils,
|
2015-05-15 08:08:30 +08:00
|
|
|
} = require 'nylas-exports'
|
2015-04-01 06:54:16 +08:00
|
|
|
|
|
|
|
ParticipantsTextField = proxyquire '../lib/participants-text-field',
|
2015-05-15 08:08:30 +08:00
|
|
|
'nylas-exports': {Contact, ContactStore}
|
2015-04-01 06:54:16 +08:00
|
|
|
|
|
|
|
participant1 = new Contact
|
2015-08-29 02:12:53 +08:00
|
|
|
id: 'local-1'
|
2015-05-15 08:08:30 +08:00
|
|
|
email: 'ben@nylas.com'
|
2015-04-01 06:54:16 +08:00
|
|
|
participant2 = new Contact
|
2015-08-29 02:12:53 +08:00
|
|
|
id: 'local-2'
|
2015-04-01 06:54:16 +08:00
|
|
|
email: 'ben@example.com'
|
2015-05-15 08:08:30 +08:00
|
|
|
name: 'Ben Gotow'
|
2015-04-01 06:54:16 +08:00
|
|
|
participant3 = new Contact
|
2015-08-29 02:12:53 +08:00
|
|
|
id: 'local-3'
|
2015-05-20 07:06:59 +08:00
|
|
|
email: 'evan@nylas.com'
|
|
|
|
name: 'Evan Morikawa'
|
2015-04-01 06:54:16 +08:00
|
|
|
participant4 = new Contact
|
2015-08-29 02:12:53 +08:00
|
|
|
id: 'local-4',
|
2015-04-01 06:54:16 +08:00
|
|
|
email: 'ben@elsewhere.com',
|
2015-05-15 08:08:30 +08:00
|
|
|
name: 'ben Again'
|
2015-04-01 06:54:16 +08:00
|
|
|
participant5 = new Contact
|
2015-08-29 02:12:53 +08:00
|
|
|
id: 'local-5',
|
2015-04-01 06:54:16 +08:00
|
|
|
email: 'evan@elsewhere.com',
|
|
|
|
name: 'EVAN'
|
|
|
|
|
|
|
|
describe 'ParticipantsTextField', ->
|
|
|
|
beforeEach ->
|
2015-11-12 02:25:11 +08:00
|
|
|
spyOn(NylasEnv, "isMainWindow").andReturn true
|
2015-04-01 06:54:16 +08:00
|
|
|
@propChange = jasmine.createSpy('change')
|
|
|
|
|
|
|
|
@fieldName = 'to'
|
|
|
|
@tabIndex = '100'
|
|
|
|
@participants =
|
|
|
|
to: [participant1, participant2]
|
|
|
|
cc: [participant3]
|
|
|
|
bcc: []
|
|
|
|
|
|
|
|
@renderedField = ReactTestUtils.renderIntoDocument(
|
|
|
|
<ParticipantsTextField
|
|
|
|
field={@fieldName}
|
|
|
|
tabIndex={@tabIndex}
|
|
|
|
visible={true}
|
|
|
|
participants={@participants}
|
|
|
|
change={@propChange} />
|
|
|
|
)
|
2015-04-25 02:33:10 +08:00
|
|
|
@renderedInput = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(@renderedField, 'input'))
|
2015-04-01 06:54:16 +08:00
|
|
|
|
|
|
|
@expectInputToYield = (input, expected) ->
|
|
|
|
reviver = (k,v) ->
|
2015-08-29 02:12:53 +08:00
|
|
|
return undefined if k in ["id", "client_id", "server_id", "object"]
|
2015-04-01 06:54:16 +08:00
|
|
|
return v
|
2015-09-23 06:32:27 +08:00
|
|
|
runs =>
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: input}})
|
|
|
|
advanceClock(100)
|
|
|
|
ReactTestUtils.Simulate.keyDown(@renderedInput, {key: 'Enter', keyCode: 9})
|
|
|
|
waitsFor =>
|
|
|
|
@propChange.calls.length > 0
|
|
|
|
runs =>
|
|
|
|
found = @propChange.mostRecentCall.args[0]
|
|
|
|
found = JSON.parse(JSON.stringify(found), reviver)
|
|
|
|
expected = JSON.parse(JSON.stringify(expected), reviver)
|
|
|
|
expect(found).toEqual(expected)
|
|
|
|
|
|
|
|
# This advance clock needs to be here because our waitsFor latch
|
|
|
|
# catches the first time that propChange gets called. More stuff
|
|
|
|
# may happen after this and we need to advance the clock to
|
|
|
|
# "clear" all of that. If we don't do this it throws errors about
|
|
|
|
# `setState` being called on unmounted components :(
|
|
|
|
advanceClock(100)
|
2015-04-01 06:54:16 +08:00
|
|
|
|
|
|
|
it 'renders into the document', ->
|
|
|
|
expect(ReactTestUtils.isCompositeComponentWithType @renderedField, ParticipantsTextField).toBe(true)
|
|
|
|
|
|
|
|
it 'applies the tabIndex provided to the inner input', ->
|
|
|
|
expect(@renderedInput.tabIndex/1).toBe(@tabIndex/1)
|
|
|
|
|
|
|
|
describe "inserting participant text", ->
|
|
|
|
it "should fire onChange with an updated participants hash", ->
|
|
|
|
@expectInputToYield 'abc@abc.com',
|
|
|
|
to: [participant1, participant2, new Contact(name: 'abc@abc.com', email: 'abc@abc.com')]
|
|
|
|
cc: [participant3]
|
|
|
|
bcc: []
|
|
|
|
|
|
|
|
it "should remove added participants from other fields", ->
|
|
|
|
@expectInputToYield participant3.email,
|
|
|
|
to: [participant1, participant2, new Contact(name: participant3.email, email: participant3.email)]
|
|
|
|
cc: []
|
|
|
|
bcc: []
|
|
|
|
|
|
|
|
it "should use the name of an existing contact in the ContactStore if possible", ->
|
2015-09-23 06:32:27 +08:00
|
|
|
spyOn(ContactStore, 'searchContacts').andCallFake (val, options={}) ->
|
|
|
|
if options.noPromise
|
|
|
|
return [participant3] if val is participant3.email
|
|
|
|
return []
|
|
|
|
else
|
|
|
|
return Promise.resolve([participant3]) if val is participant3.email
|
|
|
|
return Promise.resolve([])
|
2015-04-01 06:54:16 +08:00
|
|
|
|
|
|
|
@expectInputToYield participant3.email,
|
|
|
|
to: [participant1, participant2, participant3]
|
|
|
|
cc: []
|
|
|
|
bcc: []
|
|
|
|
|
|
|
|
it "should not allow the same contact to appear multiple times", ->
|
2015-09-23 06:32:27 +08:00
|
|
|
spyOn(ContactStore, 'searchContacts').andCallFake (val, options={}) ->
|
|
|
|
if options.noPromise
|
|
|
|
return [participant2] if val is participant2.email
|
|
|
|
return []
|
|
|
|
else
|
|
|
|
return Promise.resolve([participant2]) if val is participant2.email
|
|
|
|
return Promise.resolve([])
|
2015-04-01 06:54:16 +08:00
|
|
|
|
|
|
|
@expectInputToYield participant2.email,
|
|
|
|
to: [participant1, participant2]
|
|
|
|
cc: [participant3]
|
|
|
|
bcc: []
|
|
|
|
|
|
|
|
describe "when text contains Name (Email) formatted data", ->
|
|
|
|
it "should correctly parse it into named Contact objects", ->
|
2015-08-29 02:12:53 +08:00
|
|
|
newContact1 = new Contact(id: "b1", name:'Ben Imposter', email:'imposter@nylas.com')
|
2015-05-15 08:08:30 +08:00
|
|
|
newContact2 = new Contact(name:'Nylas Team', email:'feedback@nylas.com')
|
|
|
|
|
2015-04-01 06:54:16 +08:00
|
|
|
inputs = [
|
2015-05-15 08:08:30 +08:00
|
|
|
"Ben Imposter <imposter@nylas.com>, Nylas Team <feedback@nylas.com>",
|
|
|
|
"\n\nbla\nBen Imposter (imposter@nylas.com), Nylas Team (feedback@nylas.com)",
|
|
|
|
"Hello world! I like cheese. \rBen Imposter (imposter@nylas.com)\nNylas Team (feedback@nylas.com)",
|
|
|
|
"Ben Imposter<imposter@nylas.com>Nylas Team (feedback@nylas.com)"
|
2015-04-01 06:54:16 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
for input in inputs
|
|
|
|
@expectInputToYield input,
|
|
|
|
to: [participant1, participant2, newContact1, newContact2]
|
|
|
|
cc: [participant3]
|
|
|
|
bcc: []
|
|
|
|
|
|
|
|
describe "when text contains emails mixed with garbage text", ->
|
|
|
|
it "should still parse out emails into Contact objects", ->
|
2015-08-29 02:12:53 +08:00
|
|
|
newContact1 = new Contact(id: 'gm', name:'garbage-man@nylas.com', email:'garbage-man@nylas.com')
|
|
|
|
newContact2 = new Contact(id: 'rm', name:'recycling-guy@nylas.com', email:'recycling-guy@nylas.com')
|
2015-05-15 08:08:30 +08:00
|
|
|
|
2015-04-01 06:54:16 +08:00
|
|
|
inputs = [
|
2015-05-15 08:08:30 +08:00
|
|
|
"Hello world I real. \n asd. garbage-man@nylas.com—he's cool Also 'recycling-guy@nylas.com'!",
|
|
|
|
"garbage-man@nylas.com1WHOA I REALLY HATE DATA,recycling-guy@nylas.com",
|
|
|
|
"nils.com garbage-man@nylas.com @nylas.com nope@.com nope!recycling-guy@nylas.com HOLLA AT recycling-guy@nylas."
|
2015-04-01 06:54:16 +08:00
|
|
|
]
|
|
|
|
|
|
|
|
for input in inputs
|
|
|
|
@expectInputToYield input,
|
|
|
|
to: [participant1, participant2, newContact1, newContact2]
|
|
|
|
cc: [participant3]
|
|
|
|
bcc: []
|