mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 00:06:06 +08:00
Fixes T1928: don't lose focus on cc and bcc fields
Summary: Fixes T1928 Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Maniphest Tasks: T1928 Differential Revision: https://phab.nylas.com/D1622
This commit is contained in:
parent
912cb4634e
commit
dba73561d6
|
@ -221,7 +221,7 @@ class ComposerView extends React.Component
|
|||
key="cc"
|
||||
field='cc'
|
||||
change={@_onChangeParticipants}
|
||||
onEmptied={=> @setState showcc: false}
|
||||
onEmptied={@_onEmptyCc}
|
||||
participants={to: @state['to'], cc: @state['cc'], bcc: @state['bcc']}
|
||||
tabIndex='103'/>
|
||||
)
|
||||
|
@ -233,7 +233,7 @@ class ComposerView extends React.Component
|
|||
key="bcc"
|
||||
field='bcc'
|
||||
change={@_onChangeParticipants}
|
||||
onEmptied={=> @setState showbcc: false}
|
||||
onEmptied={@_onEmptyBcc}
|
||||
participants={to: @state['to'], cc: @state['cc'], bcc: @state['bcc']}
|
||||
tabIndex='104'/>
|
||||
)
|
||||
|
@ -365,9 +365,7 @@ class ComposerView extends React.Component
|
|||
else
|
||||
field ?= "contentBody"
|
||||
|
||||
_.delay =>
|
||||
@refs[field]?.focus?()
|
||||
, 150
|
||||
@refs[field]?.focus?()
|
||||
|
||||
isForwardedMessage: =>
|
||||
return false if not @_proxy
|
||||
|
@ -525,6 +523,16 @@ class ComposerView extends React.Component
|
|||
_onSendingStateChanged: =>
|
||||
@setState isSending: DraftStore.isSendingDraft(@props.localId)
|
||||
|
||||
_onEmptyCc: =>
|
||||
@setState showcc: false
|
||||
@focus "textFieldTo"
|
||||
|
||||
_onEmptyBcc: =>
|
||||
@setState showbcc: false
|
||||
if @state.showcc
|
||||
@focus "textFieldCc"
|
||||
else
|
||||
@focus "textFieldTo"
|
||||
|
||||
undo: (event) =>
|
||||
event.preventDefault()
|
||||
|
|
|
@ -17,6 +17,8 @@ ReactTestUtils = React.addons.TestUtils
|
|||
|
||||
{InjectedComponent} = require 'nylas-component-kit'
|
||||
|
||||
ParticipantsTextField = require '../lib/participants-text-field'
|
||||
|
||||
u1 = new Contact(name: "Christine Spang", email: "spang@nylas.com")
|
||||
u2 = new Contact(name: "Michael Grinich", email: "mg@nylas.com")
|
||||
u3 = new Contact(name: "Evan Morikawa", email: "evan@nylas.com")
|
||||
|
@ -53,7 +55,6 @@ searchContactStub = (email) ->
|
|||
ComposerView = proxyquire "../lib/composer-view",
|
||||
"./file-upload": reactStub("file-upload")
|
||||
"./image-file-upload": reactStub("image-file-upload")
|
||||
"./participants-text-field": textFieldStub("")
|
||||
"nylas-exports":
|
||||
ContactStore:
|
||||
searchContacts: (email) -> searchContactStub
|
||||
|
@ -215,6 +216,55 @@ describe "populated composer", ->
|
|||
advanceClock(1000)
|
||||
expect(@composer.refs['contentBody'].focus).toHaveBeenCalled()
|
||||
|
||||
describe "when emptying cc fields", ->
|
||||
|
||||
it "focuses on to when bcc is emptied and there's no cc field", ->
|
||||
useDraft.call(@, bcc: [u1])
|
||||
makeComposer.call(@)
|
||||
spyOn(@composer.refs['textFieldTo'], 'focus')
|
||||
spyOn(@composer.refs['textFieldBcc'], 'focus')
|
||||
|
||||
bcc = ReactTestUtils.scryRenderedComponentsWithTypeAndProps(@composer, ParticipantsTextField, field: "bcc")[0]
|
||||
bcc.props.onEmptied()
|
||||
|
||||
expect(@composer.state.showbcc).toBe false
|
||||
advanceClock(1000)
|
||||
expect(@composer.refs['textFieldTo'].focus).toHaveBeenCalled()
|
||||
expect(@composer.refs['textFieldCc']).not.toBeDefined()
|
||||
expect(@composer.refs['textFieldBcc']).not.toBeDefined()
|
||||
|
||||
it "focuses on cc when bcc is emptied and cc field is available", ->
|
||||
useDraft.call(@, cc: [u2], bcc: [u1])
|
||||
makeComposer.call(@)
|
||||
spyOn(@composer.refs['textFieldTo'], 'focus')
|
||||
spyOn(@composer.refs['textFieldCc'], 'focus')
|
||||
spyOn(@composer.refs['textFieldBcc'], 'focus')
|
||||
|
||||
bcc = ReactTestUtils.scryRenderedComponentsWithTypeAndProps(@composer, ParticipantsTextField, field: "bcc")[0]
|
||||
|
||||
bcc.props.onEmptied()
|
||||
expect(@composer.state.showbcc).toBe false
|
||||
advanceClock(1000)
|
||||
expect(@composer.refs['textFieldTo'].focus).not.toHaveBeenCalled()
|
||||
expect(@composer.refs['textFieldCc'].focus).toHaveBeenCalled()
|
||||
expect(@composer.refs['textFieldBcc']).not.toBeDefined()
|
||||
|
||||
it "focuses on to when cc is emptied", ->
|
||||
useDraft.call(@, cc: [u1], bcc: [u2])
|
||||
makeComposer.call(@)
|
||||
spyOn(@composer.refs['textFieldTo'], 'focus')
|
||||
spyOn(@composer.refs['textFieldCc'], 'focus')
|
||||
spyOn(@composer.refs['textFieldBcc'], 'focus')
|
||||
|
||||
cc = ReactTestUtils.scryRenderedComponentsWithTypeAndProps(@composer, ParticipantsTextField, field: "cc")[0]
|
||||
cc.props.onEmptied()
|
||||
|
||||
expect(@composer.state.showcc).toBe false
|
||||
advanceClock(1000)
|
||||
expect(@composer.refs['textFieldTo'].focus).toHaveBeenCalled()
|
||||
expect(@composer.refs['textFieldCc']).not.toBeDefined()
|
||||
expect(@composer.refs['textFieldBcc'].focus).not.toHaveBeenCalled()
|
||||
|
||||
describe "When sending a message", ->
|
||||
beforeEach ->
|
||||
spyOn(atom, "isMainWindow").andReturn true
|
||||
|
|
Loading…
Reference in a new issue