2015-05-20 07:06:59 +08:00
|
|
|
_ = require 'underscore'
|
2015-02-07 06:46:30 +08:00
|
|
|
React = require 'react/addons'
|
|
|
|
ReactTestUtils = React.addons.TestUtils
|
|
|
|
|
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
|
|
|
Account,
|
|
|
|
AccountStore,
|
2015-02-07 06:46:30 +08:00
|
|
|
Contact,
|
2015-05-15 08:08:30 +08:00
|
|
|
} = require 'nylas-exports'
|
|
|
|
{TokenizingTextField, Menu} = require 'nylas-component-kit'
|
2015-02-07 06:46:30 +08:00
|
|
|
|
|
|
|
CustomToken = React.createClass
|
|
|
|
render: ->
|
|
|
|
<span>{@props.item.email}</span>
|
|
|
|
|
|
|
|
CustomSuggestion = React.createClass
|
|
|
|
render: ->
|
|
|
|
<span>{@props.item.email}</span>
|
|
|
|
|
|
|
|
participant1 = new Contact
|
2015-08-27 01:07:23 +08:00
|
|
|
id: '1'
|
2015-05-15 08:08:30 +08:00
|
|
|
email: 'ben@nylas.com'
|
2015-02-07 06:46:30 +08:00
|
|
|
participant2 = new Contact
|
2015-08-27 01:07:23 +08:00
|
|
|
id: '2'
|
2015-05-20 07:06:59 +08:00
|
|
|
email: 'burgers@nylas.com'
|
2015-05-19 10:21:54 +08:00
|
|
|
name: 'Nylas Burger Basket'
|
2015-02-07 06:46:30 +08:00
|
|
|
participant3 = new Contact
|
2015-08-27 01:07:23 +08:00
|
|
|
id: '3'
|
2015-05-20 07:06:59 +08:00
|
|
|
email: 'evan@nylas.com'
|
2015-05-15 08:08:30 +08:00
|
|
|
name: 'Evan'
|
2015-02-07 06:46:30 +08:00
|
|
|
participant4 = new Contact
|
2015-08-27 01:07:23 +08:00
|
|
|
id: '4'
|
2015-05-15 08:08:30 +08:00
|
|
|
email: 'tester@elsewhere.com',
|
|
|
|
name: 'Tester'
|
2015-02-07 06:46:30 +08:00
|
|
|
participant5 = new Contact
|
2015-08-27 01:07:23 +08:00
|
|
|
id: '5'
|
2015-05-15 08:08:30 +08:00
|
|
|
email: 'michael@elsewhere.com',
|
|
|
|
name: 'Michael'
|
2015-02-07 06:46:30 +08:00
|
|
|
|
2015-02-07 07:09:51 +08:00
|
|
|
describe 'TokenizingTextField', ->
|
2015-02-07 06:46:30 +08:00
|
|
|
beforeEach ->
|
|
|
|
@completions = []
|
|
|
|
@propAdd = jasmine.createSpy 'add'
|
2015-08-04 04:06:28 +08:00
|
|
|
@propEdit = jasmine.createSpy 'edit'
|
2015-02-07 06:46:30 +08:00
|
|
|
@propRemove = jasmine.createSpy 'remove'
|
2015-04-25 00:36:19 +08:00
|
|
|
@propEmptied = jasmine.createSpy 'emptied'
|
|
|
|
@propTokenKey = jasmine.createSpy("tokenKey").andCallFake (p) -> p.email
|
2015-08-04 04:06:28 +08:00
|
|
|
@propTokenIsValid = jasmine.createSpy("tokenIsValid").andReturn(true)
|
2015-04-25 00:36:19 +08:00
|
|
|
@propTokenNode = (p) -> <CustomToken item={p} />
|
|
|
|
@propOnTokenAction = jasmine.createSpy 'tokenAction'
|
|
|
|
@propCompletionNode = (p) -> <CustomSuggestion item={p} />
|
2015-02-07 06:46:30 +08:00
|
|
|
@propCompletionsForInput = (input) => @completions
|
|
|
|
|
2015-04-25 00:36:19 +08:00
|
|
|
spyOn(@, 'propCompletionNode').andCallThrough()
|
2015-02-07 06:46:30 +08:00
|
|
|
spyOn(@, 'propCompletionsForInput').andCallThrough()
|
|
|
|
|
|
|
|
@tabIndex = 100
|
|
|
|
@tokens = [participant1, participant2, participant3]
|
|
|
|
|
2015-08-27 01:07:23 +08:00
|
|
|
@rebuildRenderedField = (tokens) =>
|
|
|
|
tokens ?= @tokens
|
2015-08-04 04:06:28 +08:00
|
|
|
@renderedField = ReactTestUtils.renderIntoDocument(
|
|
|
|
<TokenizingTextField
|
|
|
|
tokens={@tokens}
|
|
|
|
tokenKey={@propTokenKey}
|
|
|
|
tokenNode={@propTokenNode}
|
|
|
|
tokenIsValid={@propTokenIsValid}
|
|
|
|
onRequestCompletions={@propCompletionsForInput}
|
|
|
|
completionNode={@propCompletionNode}
|
|
|
|
onAdd={@propAdd}
|
|
|
|
onEdit={@propEdit}
|
|
|
|
onRemove={@propRemove}
|
|
|
|
onEmptied={@propEmptied}
|
|
|
|
onTokenAction={@propOnTokenAction}
|
|
|
|
tabIndex={@tabIndex}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
@renderedInput = React.findDOMNode(ReactTestUtils.findRenderedDOMComponentWithTag(@renderedField, 'input'))
|
2015-08-27 01:07:23 +08:00
|
|
|
return @renderedField
|
|
|
|
|
2015-08-04 04:06:28 +08:00
|
|
|
@rebuildRenderedField()
|
2015-02-07 06:46:30 +08:00
|
|
|
|
|
|
|
it 'renders into the document', ->
|
|
|
|
expect(ReactTestUtils.isCompositeComponentWithType @renderedField, TokenizingTextField).toBe(true)
|
|
|
|
|
2015-08-04 04:06:28 +08:00
|
|
|
it 'should render an input field', ->
|
|
|
|
expect(@renderedInput).toBeDefined()
|
|
|
|
|
2015-02-07 06:46:30 +08:00
|
|
|
it 'applies the tabIndex provided to the inner input', ->
|
|
|
|
expect(@renderedInput.tabIndex).toBe(@tabIndex)
|
|
|
|
|
2015-04-25 00:36:19 +08:00
|
|
|
it 'shows the tokens provided by the tokenNode method', ->
|
2015-02-07 06:46:30 +08:00
|
|
|
@renderedTokens = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, CustomToken)
|
|
|
|
expect(@renderedTokens.length).toBe(@tokens.length)
|
|
|
|
|
|
|
|
it 'shows the tokens in the correct order', ->
|
|
|
|
@renderedTokens = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, CustomToken)
|
|
|
|
for i in [0..@tokens.length-1]
|
|
|
|
expect(@renderedTokens[i].props.item).toBe(@tokens[i])
|
|
|
|
|
2015-08-04 04:06:28 +08:00
|
|
|
describe "prop: tokenIsValid", ->
|
|
|
|
it "should be evaluated for each token when it's provided", ->
|
|
|
|
@propTokenIsValid = jasmine.createSpy("tokenIsValid").andCallFake (p) =>
|
|
|
|
if p is participant2 then true else false
|
|
|
|
|
|
|
|
@rebuildRenderedField()
|
|
|
|
@tokens = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, TokenizingTextField.Token)
|
|
|
|
expect(@tokens[0].props.valid).toBe(false)
|
|
|
|
expect(@tokens[1].props.valid).toBe(true)
|
|
|
|
expect(@tokens[2].props.valid).toBe(false)
|
|
|
|
|
|
|
|
it "should default to true when not provided", ->
|
|
|
|
@propTokenIsValid = null
|
|
|
|
@rebuildRenderedField()
|
|
|
|
@tokens = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, TokenizingTextField.Token)
|
|
|
|
expect(@tokens[0].props.valid).toBe(true)
|
|
|
|
expect(@tokens[1].props.valid).toBe(true)
|
|
|
|
expect(@tokens[2].props.valid).toBe(true)
|
|
|
|
|
2015-08-27 01:07:23 +08:00
|
|
|
describe "when the user drags and drops a token between two fields", ->
|
|
|
|
it "should work properly", ->
|
2015-08-29 02:12:53 +08:00
|
|
|
participant2.clientId = '123'
|
|
|
|
|
2015-08-27 01:07:23 +08:00
|
|
|
tokensA = [participant1, participant2, participant3]
|
|
|
|
fieldA = @rebuildRenderedField(tokensA)
|
|
|
|
|
|
|
|
tokensB = []
|
|
|
|
fieldB = @rebuildRenderedField(tokensB)
|
|
|
|
|
|
|
|
tokenIndexToDrag = 1
|
|
|
|
token = ReactTestUtils.scryRenderedDOMComponentsWithClass(fieldA, 'token')[tokenIndexToDrag]
|
|
|
|
|
|
|
|
dragStartEventData = {}
|
|
|
|
dragStartEvent =
|
|
|
|
dataTransfer:
|
|
|
|
setData: (type, val) ->
|
|
|
|
dragStartEventData[type] = val
|
|
|
|
ReactTestUtils.Simulate.dragStart(token, dragStartEvent)
|
|
|
|
|
|
|
|
expect(dragStartEventData).toEqual({
|
2015-09-25 10:07:50 +08:00
|
|
|
'nylas-token-item': '{"client_id":"123","server_id":"2","name":"Nylas Burger Basket","email":"burgers@nylas.com","thirdPartyData":{},"id":"2","__constructorName":"Contact"}'
|
2015-08-27 01:07:23 +08:00
|
|
|
'text/plain': 'Nylas Burger Basket <burgers@nylas.com>'
|
|
|
|
})
|
|
|
|
|
|
|
|
dropEvent =
|
|
|
|
dataTransfer:
|
|
|
|
types: Object.keys(dragStartEventData)
|
|
|
|
getData: (type) -> dragStartEventData[type]
|
|
|
|
ReactTestUtils.Simulate.drop(fieldB.refs['field-drop-target'], dropEvent)
|
|
|
|
|
|
|
|
expect(@propAdd).toHaveBeenCalledWith([tokensA[tokenIndexToDrag]])
|
|
|
|
|
2015-04-25 00:36:19 +08:00
|
|
|
describe "When the user selects a token", ->
|
|
|
|
beforeEach ->
|
|
|
|
token = ReactTestUtils.scryRenderedDOMComponentsWithClass(@renderedField, 'token')[0]
|
|
|
|
ReactTestUtils.Simulate.click(token)
|
|
|
|
|
|
|
|
it "should mark the token as focused", ->
|
|
|
|
expect(@propTokenKey).toHaveBeenCalledWith(participant1)
|
|
|
|
|
|
|
|
it "should set the selectedTokenKeyState", ->
|
|
|
|
expect(@renderedField.state.selectedTokenKey).toBe participant1.email
|
|
|
|
|
|
|
|
it "should return the appropriate token objet", ->
|
|
|
|
expect(@renderedField._selectedToken()).toBe participant1
|
|
|
|
|
2015-02-07 06:46:30 +08:00
|
|
|
describe "when focused", ->
|
|
|
|
it 'should receive the `focused` class', ->
|
|
|
|
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(@renderedField, 'focused').length).toBe(0)
|
|
|
|
ReactTestUtils.Simulate.focus(@renderedInput)
|
|
|
|
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(@renderedField, 'focused').length).toBe(1)
|
|
|
|
|
|
|
|
describe "when the user types in the input", ->
|
|
|
|
it 'should fetch completions for the text', ->
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc'}})
|
2015-05-02 00:58:51 +08:00
|
|
|
advanceClock(1000)
|
2015-04-25 00:36:19 +08:00
|
|
|
expect(@propCompletionsForInput.calls[0].args[0]).toBe('abc')
|
|
|
|
|
|
|
|
it 'should fetch completions on focus', ->
|
|
|
|
@renderedField.setState inputValue: "abc"
|
|
|
|
ReactTestUtils.Simulate.focus(@renderedInput)
|
2015-05-02 00:58:51 +08:00
|
|
|
advanceClock(1000)
|
2015-04-25 00:36:19 +08:00
|
|
|
expect(@propCompletionsForInput.calls[0].args[0]).toBe('abc')
|
2015-02-07 06:46:30 +08:00
|
|
|
|
|
|
|
it 'should display the completions', ->
|
|
|
|
@completions = [participant4, participant5]
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc'}})
|
|
|
|
|
|
|
|
components = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, CustomSuggestion)
|
|
|
|
expect(components.length).toBe(2)
|
|
|
|
expect(components[0].props.item).toBe(participant4)
|
|
|
|
expect(components[1].props.item).toBe(participant5)
|
|
|
|
|
|
|
|
it 'should not display items with keys matching items already in the token field', ->
|
|
|
|
@completions = [participant2, participant4, participant1]
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc'}})
|
2015-02-23 10:08:04 +08:00
|
|
|
|
2015-02-07 06:46:30 +08:00
|
|
|
components = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, CustomSuggestion)
|
|
|
|
expect(components.length).toBe(1)
|
|
|
|
expect(components[0].props.item).toBe(participant4)
|
2015-02-23 10:08:04 +08:00
|
|
|
|
|
|
|
it 'should highlight the first completion', ->
|
|
|
|
@completions = [participant4, participant5]
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc'}})
|
|
|
|
components = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, Menu.Item)
|
|
|
|
menuItem = components[0]
|
|
|
|
expect(menuItem.props.selected).toBe true
|
|
|
|
|
|
|
|
it 'select the clicked element', ->
|
|
|
|
@completions = [participant4, participant5]
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc'}})
|
|
|
|
components = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, Menu.Item)
|
|
|
|
menuItem = components[0]
|
2015-04-25 02:33:10 +08:00
|
|
|
ReactTestUtils.Simulate.mouseDown(React.findDOMNode(menuItem))
|
2015-03-11 03:06:47 +08:00
|
|
|
expect(@propAdd).toHaveBeenCalledWith([participant4])
|
2015-02-23 10:08:04 +08:00
|
|
|
|
2015-07-13 22:25:30 +08:00
|
|
|
it "manually enters whatever's in the field when the user presses the space bar as long as it looks like an email", ->
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc@foo.com '}})
|
|
|
|
advanceClock(10)
|
|
|
|
expect(@propAdd).toHaveBeenCalledWith("abc@foo.com", skipNameLookup: true)
|
|
|
|
|
|
|
|
it "doesn't sumbmit if it looks like an email but has no space at the end", ->
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc@foo.com'}})
|
|
|
|
advanceClock(10)
|
|
|
|
expect(@propCompletionsForInput.calls[0].args[0]).toBe('abc@foo.com')
|
|
|
|
expect(@propAdd).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "allows spaces if what's currently being entered doesn't look like an email", ->
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'ab'}})
|
|
|
|
advanceClock(10)
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'ab '}})
|
|
|
|
advanceClock(10)
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'ab c'}})
|
|
|
|
advanceClock(10)
|
|
|
|
expect(@propCompletionsForInput.calls[2].args[0]).toBe('ab c')
|
|
|
|
expect(@propAdd).not.toHaveBeenCalled()
|
|
|
|
|
2015-08-04 04:06:28 +08:00
|
|
|
[{key:'Enter', keyCode:13}, {key:',', keyCode: 188}].forEach ({key, keyCode}) ->
|
2015-02-07 06:46:30 +08:00
|
|
|
describe "when the user presses #{key}", ->
|
|
|
|
describe "and there is an completion available", ->
|
|
|
|
it "should call add with the first completion", ->
|
|
|
|
@completions = [participant4]
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc'}})
|
2015-08-04 04:06:28 +08:00
|
|
|
ReactTestUtils.Simulate.keyDown(@renderedInput, {key: key, keyCode: keyCode})
|
2015-03-11 03:06:47 +08:00
|
|
|
expect(@propAdd).toHaveBeenCalledWith([participant4])
|
2015-02-07 06:46:30 +08:00
|
|
|
|
|
|
|
describe "and there is NO completion available", ->
|
|
|
|
it 'should call add, allowing the parent to (optionally) turn the text into a token', ->
|
|
|
|
@completions = []
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc'}})
|
2015-08-04 04:06:28 +08:00
|
|
|
ReactTestUtils.Simulate.keyDown(@renderedInput, {key: key, keyCode: keyCode})
|
2015-07-13 22:25:30 +08:00
|
|
|
expect(@propAdd).toHaveBeenCalledWith('abc', {})
|
2015-02-07 06:46:30 +08:00
|
|
|
|
|
|
|
describe "when the user presses tab", ->
|
2015-09-26 04:21:39 +08:00
|
|
|
beforeEach ->
|
|
|
|
@tabDownEvent =
|
|
|
|
key: "Tab"
|
|
|
|
keyCode: 9
|
|
|
|
preventDefault: jasmine.createSpy('preventDefault')
|
|
|
|
stopPropagation: jasmine.createSpy('stopPropagation')
|
|
|
|
|
2015-02-07 06:46:30 +08:00
|
|
|
describe "and there is an completion available", ->
|
|
|
|
it "should call add with the first completion", ->
|
|
|
|
@completions = [participant4]
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc'}})
|
2015-09-26 04:21:39 +08:00
|
|
|
ReactTestUtils.Simulate.keyDown(@renderedInput, @tabDownEvent)
|
2015-03-11 03:06:47 +08:00
|
|
|
expect(@propAdd).toHaveBeenCalledWith([participant4])
|
2015-09-26 04:21:39 +08:00
|
|
|
expect(@tabDownEvent.preventDefault).toHaveBeenCalled()
|
|
|
|
expect(@tabDownEvent.stopPropagation).toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "shouldn't handle the event in the input is empty", ->
|
|
|
|
# We ignore on empty input values
|
2015-09-29 00:55:45 +08:00
|
|
|
# NOTE, we still preventDefault
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: ' '}})
|
|
|
|
ReactTestUtils.Simulate.keyDown(@renderedInput, @tabDownEvent)
|
|
|
|
expect(@propAdd).not.toHaveBeenCalled()
|
|
|
|
expect(@tabDownEvent.preventDefault).toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "should NOT stop the propagation if the input is empty.", ->
|
|
|
|
# This is to allow tabs to propagate up to controls that might want
|
|
|
|
# to change the focus later.
|
2015-09-26 04:21:39 +08:00
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: ' '}})
|
|
|
|
ReactTestUtils.Simulate.keyDown(@renderedInput, @tabDownEvent)
|
|
|
|
expect(@propAdd).not.toHaveBeenCalled()
|
|
|
|
expect(@tabDownEvent.stopPropagation).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "should add the raw input value if there are no completions", ->
|
|
|
|
@completions = []
|
|
|
|
spyOn(@renderedField, "_addInputValue").andCallThrough()
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'abc'}})
|
|
|
|
ReactTestUtils.Simulate.keyDown(@renderedInput, @tabDownEvent)
|
|
|
|
expect(@renderedField._addInputValue).toHaveBeenCalled()
|
|
|
|
expect(@propAdd).toHaveBeenCalledWith('abc', {})
|
|
|
|
expect(@tabDownEvent.preventDefault).toHaveBeenCalled()
|
|
|
|
expect(@tabDownEvent.stopPropagation).toHaveBeenCalled()
|
2015-02-07 06:46:30 +08:00
|
|
|
|
|
|
|
describe "when blurred", ->
|
|
|
|
it 'should call add, allowing the parent component to (optionally) turn the entered text into a token', ->
|
|
|
|
ReactTestUtils.Simulate.focus(@renderedInput)
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'text'}})
|
|
|
|
ReactTestUtils.Simulate.blur(@renderedInput)
|
2015-07-13 22:25:30 +08:00
|
|
|
expect(@propAdd).toHaveBeenCalledWith('text', {})
|
2015-02-07 06:46:30 +08:00
|
|
|
|
|
|
|
it 'should clear the entered text', ->
|
|
|
|
ReactTestUtils.Simulate.focus(@renderedInput)
|
|
|
|
ReactTestUtils.Simulate.change(@renderedInput, {target: {value: 'text'}})
|
|
|
|
ReactTestUtils.Simulate.blur(@renderedInput)
|
|
|
|
expect(@renderedInput.value).toBe('')
|
|
|
|
|
|
|
|
it 'should no longer have the `focused` class', ->
|
|
|
|
ReactTestUtils.Simulate.focus(@renderedInput)
|
|
|
|
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(@renderedField, 'focused').length).toBe(1)
|
|
|
|
ReactTestUtils.Simulate.blur(@renderedInput)
|
|
|
|
expect(ReactTestUtils.scryRenderedDOMComponentsWithClass(@renderedField, 'focused').length).toBe(0)
|
|
|
|
|
2015-08-04 04:06:28 +08:00
|
|
|
describe "when the user double-clicks a token", ->
|
|
|
|
describe "when an onEdit prop has been provided", ->
|
|
|
|
beforeEach ->
|
|
|
|
@propEdit = jasmine.createSpy('onEdit')
|
|
|
|
@rebuildRenderedField()
|
|
|
|
|
|
|
|
it "should enter editing mode", ->
|
|
|
|
tokens = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, TokenizingTextField.Token)
|
|
|
|
expect(tokens[0].state.editing).toBe(false)
|
|
|
|
ReactTestUtils.Simulate.doubleClick(React.findDOMNode(tokens[0]), {})
|
|
|
|
expect(tokens[0].state.editing).toBe(true)
|
|
|
|
|
|
|
|
it "should call onEdit to commit the new token value when the edit field is blurred", ->
|
|
|
|
tokens = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, TokenizingTextField.Token)
|
|
|
|
token = tokens[0]
|
|
|
|
tokenEl = React.findDOMNode(token)
|
|
|
|
|
|
|
|
expect(token.state.editing).toBe(false)
|
|
|
|
ReactTestUtils.Simulate.doubleClick(tokenEl, {})
|
|
|
|
tokenEditInput = ReactTestUtils.findRenderedDOMComponentWithTag(token, 'input')
|
|
|
|
ReactTestUtils.Simulate.change(tokenEditInput, {target: {value: 'new tag content'}})
|
|
|
|
ReactTestUtils.Simulate.blur(tokenEditInput)
|
|
|
|
expect(@propEdit).toHaveBeenCalledWith(participant1, 'new tag content')
|
|
|
|
|
|
|
|
describe "when no onEdit prop has been provided", ->
|
|
|
|
it "should not enter editing mode", ->
|
|
|
|
@propEdit = undefined
|
|
|
|
@rebuildRenderedField()
|
|
|
|
tokens = ReactTestUtils.scryRenderedComponentsWithType(@renderedField, TokenizingTextField.Token)
|
|
|
|
expect(tokens[0].state.editing).toBe(false)
|
|
|
|
ReactTestUtils.Simulate.doubleClick(React.findDOMNode(tokens[0]), {})
|
|
|
|
expect(tokens[0].state.editing).toBe(false)
|
2015-04-25 00:36:19 +08:00
|
|
|
|
|
|
|
describe "When the user removes a token", ->
|
|
|
|
it "deletes with the backspace key", ->
|
|
|
|
spyOn(@renderedField, "_removeToken")
|
2015-08-04 04:06:28 +08:00
|
|
|
ReactTestUtils.Simulate.keyDown(@renderedInput, {key: 'Backspace', keyCode: 8})
|
2015-04-25 00:36:19 +08:00
|
|
|
expect(@renderedField._removeToken).toHaveBeenCalled()
|
|
|
|
|
|
|
|
describe "when removal is passed in a token object", ->
|
|
|
|
it "asks to removes that participant", ->
|
|
|
|
@renderedField._removeToken(participant1)
|
|
|
|
expect(@propRemove).toHaveBeenCalledWith([participant1])
|
|
|
|
expect(@propEmptied).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
describe "when no token is selected", ->
|
|
|
|
it "selects the last token first and doesn't remove", ->
|
|
|
|
@renderedField._removeToken()
|
|
|
|
expect(@renderedField._selectedToken()).toBe participant3
|
|
|
|
expect(@propRemove).not.toHaveBeenCalled()
|
|
|
|
expect(@propEmptied).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
describe "when a token is selected", ->
|
|
|
|
beforeEach ->
|
|
|
|
@renderedField.setState selectedTokenKey: participant1.email
|
|
|
|
|
|
|
|
it "removes that token and deselects", ->
|
|
|
|
@renderedField._removeToken()
|
|
|
|
expect(@propRemove).toHaveBeenCalledWith([participant1])
|
|
|
|
expect(@renderedField._selectedToken()).toBeUndefined()
|
|
|
|
expect(@propEmptied).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "removes on cut when a token is selected", ->
|
|
|
|
@renderedField._onCut({preventDefault: -> })
|
|
|
|
expect(@propRemove).toHaveBeenCalledWith([participant1])
|
|
|
|
expect(@renderedField._selectedToken()).toBeUndefined()
|
|
|
|
expect(@propEmptied).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
describe "when there are no tokens left", ->
|
|
|
|
it "fires onEmptied", ->
|
|
|
|
newProps = _.clone @renderedField.props
|
|
|
|
newProps.tokens = []
|
|
|
|
emptyField = ReactTestUtils.renderIntoDocument(
|
|
|
|
React.createElement(TokenizingTextField, newProps)
|
|
|
|
)
|
|
|
|
emptyField._removeToken()
|
|
|
|
expect(@propEmptied).toHaveBeenCalled()
|