diff --git a/internal_packages/composer/lib/composer-view.cjsx b/internal_packages/composer/lib/composer-view.cjsx index efa5a370b..e7d6f295a 100644 --- a/internal_packages/composer/lib/composer-view.cjsx +++ b/internal_packages/composer/lib/composer-view.cjsx @@ -264,7 +264,7 @@ class ComposerView extends React.Component # focused depending on the draft type, or you can pass a field as # the first parameter. focus: (field = null) => - if component?.isForwardedMessage() + if @isForwardedMessage() field ?= "textFieldTo" else field ?= "contentBody" diff --git a/internal_packages/composer/spec/inbox-composer-view-spec.cjsx b/internal_packages/composer/spec/inbox-composer-view-spec.cjsx index 884373181..8d6887bcb 100644 --- a/internal_packages/composer/spec/inbox-composer-view-spec.cjsx +++ b/internal_packages/composer/spec/inbox-composer-view-spec.cjsx @@ -179,6 +179,34 @@ describe "populated composer", -> makeComposer.call @ expect(@composer.state.showbcc).toBe true + describe "when focus() is called", -> + describe "if a field name is provided", -> + it "should focus that field", -> + useDraft.call(@) + makeComposer.call(@) + spyOn(@composer.refs['textFieldCc'], 'focus') + @composer.focus('textFieldCc') + advanceClock(1000) + expect(@composer.refs['textFieldCc'].focus).toHaveBeenCalled() + + describe "if the draft is a forward", -> + it "should focus the to field", -> + useDraft.call(@, {subject: 'Fwd: This is a test'}) + makeComposer.call(@) + spyOn(@composer.refs['textFieldTo'], 'focus') + @composer.focus() + advanceClock(1000) + expect(@composer.refs['textFieldTo'].focus).toHaveBeenCalled() + + describe "if the draft is a normal message", -> + it "should focus on the body", -> + useDraft.call(@) + makeComposer.call(@) + spyOn(@composer.refs['contentBody'], 'focus') + @composer.focus() + advanceClock(1000) + expect(@composer.refs['contentBody'].focus).toHaveBeenCalled() + describe "When sending a message", -> beforeEach -> spyOn(atom, "isMainWindow").andReturn true