Mailspring/internal_packages/composer/spec/participants-text-field-spec.cjsx
Ben Gotow 68343ec472 feat(docs): New docs tasks and React 0.13.2
Summary:
This diff moves us up to React 0.13.2 and transitions some of the core React components to the new
syntax based on plain Javascript objects. `setInitialState` is now just code in the constructor,
`getDOMNode(@)` is now `React.findDOMNode(@)`, and `isMounted` is no longer necessary or available.

This diff also adds `RegisteredComponent` to match `RegisteredRegion`. In another diff,
I think we should change the names of these to be `DynamicComponent` and `DynamicComponentSet`.

This diff also includes preliminary API Reference docs for Menu.cjsx and Popover.cjsx. You can build the docs
using `grunt docs` from the build folder. It produces a simple html format now, but it's easy
to customize.

Also we now ignore "Unnecessary fat arrow"

Test Plan: Run tests

Reviewers: evan

Reviewed By: evan

Differential Revision: https://review.inboxapp.com/D1437
2015-04-24 11:33:10 -07:00

141 lines
5 KiB
CoffeeScript

_ = require 'underscore-plus'
React = require 'react/addons'
ReactTestUtils = React.addons.TestUtils
proxyquire = require 'proxyquire'
{InboxTestUtils,
Namespace,
NamespaceStore,
ContactStore,
Contact,
Utils,
} = require 'inbox-exports'
ParticipantsTextField = proxyquire '../lib/participants-text-field',
'inbox-exports': {Contact, ContactStore}
participant1 = new Contact
email: 'ben@nilas.com'
participant2 = new Contact
email: 'ben@example.com'
name: 'ben'
participant3 = new Contact
email: 'ben@inboxapp.com'
name: 'Duplicate email'
participant4 = new Contact
email: 'ben@elsewhere.com',
name: 'ben again'
participant5 = new Contact
email: 'evan@elsewhere.com',
name: 'EVAN'
describe 'ParticipantsTextField', ->
InboxTestUtils.loadKeymap()
beforeEach ->
@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} />
)
@renderedInput = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(@renderedField, 'input'))
@expectInputToYield = (input, expected) ->
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: input}})
InboxTestUtils.keyPress('enter', @renderedInput)
reviver = (k,v) ->
return undefined if k in ["id", "object"]
return v
found = @propChange.mostRecentCall.args[0]
found = JSON.parse(JSON.stringify(found), reviver)
expected = JSON.parse(JSON.stringify(expected), reviver)
expect(found).toEqual(expected)
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", ->
spyOn(ContactStore, 'searchContacts').andCallFake (val, options) ->
return [participant3] if val is participant3.email
return []
@expectInputToYield participant3.email,
to: [participant1, participant2, participant3]
cc: []
bcc: []
it "should not allow the same contact to appear multiple times", ->
spyOn(ContactStore, 'searchContacts').andCallFake (val, options) ->
return [participant2] if val is participant2.email
return []
@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", ->
newContact1 = new Contact(name:'Ben Imposter', email:'imposter@nilas.com')
newContact2 = new Contact(name:'Nilas Team', email:'feedback@nilas.com')
inputs = [
"Ben Imposter <imposter@nilas.com>, Nilas Team <feedback@nilas.com>",
"\n\nbla\nBen Imposter (imposter@nilas.com), Nilas Team (feedback@nilas.com)",
"Hello world! I like cheese. \rBen Imposter (imposter@nilas.com)\nNilas Team (feedback@nilas.com)",
"Ben Imposter<imposter@nilas.com>Nilas Team (feedback@nilas.com)"
]
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", ->
newContact1 = new Contact(name:'garbage-man@nilas.com', email:'garbage-man@nilas.com')
newContact2 = new Contact(name:'recycling-guy@nilas.com', email:'recycling-guy@nilas.com')
inputs = [
"Hello world I real. \n asd. garbage-man@nilas.com—he's cool Also 'recycling-guy@nilas.com'!",
"garbage-man@nilas.com|recycling-guy@nilas.com",
"garbage-man@nilas.com1WHOA I REALLY HATE DATA,recycling-guy@nilas.com",
"nils.com garbage-man@nilas.com @nilas.com nope@.com nope!recycling-guy@nilas.com HOLLA AT recycling-guy@nilas."
]
for input in inputs
@expectInputToYield input,
to: [participant1, participant2, newContact1, newContact2]
cc: [participant3]
bcc: []