From 215dbbd3f329c4c899deaf063e40507b3dedcf59 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Mon, 1 Jun 2015 15:12:18 -0700 Subject: [PATCH] fix(focus): When composing a forward, focus on the To field. Summary: fix specs This functionality used to work but `component` isn't defined and focus: was failing. Added specs to make sure this doesn't happen again. Test Plan: Run new specs Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D1583 --- .../composer/lib/composer-view.cjsx | 2 +- .../spec/inbox-composer-view-spec.cjsx | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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