Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Focus a recent commit if the commit button is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Nov 30, 2018
1 parent b720c7d commit 447c9c5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
14 changes: 11 additions & 3 deletions lib/views/commit-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,23 @@ export default class CommitView extends React.Component {
next = f.COAUTHOR_INPUT;
} else if (this.props.isMerging) {
next = f.ABORT_MERGE_BUTTON;
} else {
} else if (this.commitIsEnabled(false)) {
next = f.COMMIT_BUTTON;
} else {
next = RecentCommitsView.firstFocus;
}
break;
case f.COAUTHOR_INPUT:
next = this.props.isMerging ? f.ABORT_MERGE_BUTTON : f.COMMIT_BUTTON;
if (this.props.isMerging) {
next = f.ABORT_MERGE_BUTTON;
} else if (this.commitIsEnabled(false)) {
next = f.COMMIT_BUTTON;
} else {
next = RecentCommitsView.firstFocus;
}
break;
case f.ABORT_MERGE_BUTTON:
next = f.COMMIT_BUTTON;
next = this.commitIsEnabled(false) ? f.COMMIT_BUTTON : RecentCommitsView.firstFocus;
break;
case f.COMMIT_BUTTON:
next = RecentCommitsView.firstFocus;
Expand Down
31 changes: 28 additions & 3 deletions test/views/commit-view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,16 @@ describe('CommitView', function() {
);
});

it('moves focus to the commit button if the commit editor is focused', async function() {
it('moves focus to the RecentCommitsView if the commit editor is focused', async function() {
wrapper.setProps({isCommitting: true});
assert.strictEqual(
await instance.advanceFocusFrom(CommitView.focus.EDITOR),
RecentCommitsView.firstFocus,
);
});

it('moves focus to the commit button if the commit editor is focused and the button is enabled', async function() {
sinon.stub(instance, 'commitIsEnabled').returns(true);
assert.strictEqual(
await instance.advanceFocusFrom(CommitView.focus.EDITOR),
CommitView.focus.COMMIT_BUTTON,
Expand All @@ -391,7 +400,15 @@ describe('CommitView', function() {
);
});

it('moves focus to the commit button if the coauthor input is focused and no merge is in progress', async function() {
it('moves focus to the RecentCommitsView if the coauthor input is focused and no merge is in progress', async function() {
assert.strictEqual(
await instance.advanceFocusFrom(CommitView.focus.COAUTHOR_INPUT),
RecentCommitsView.firstFocus,
);
});

it('moves focus to the commit button if the coauthor input is focused, no merge is in progress, and the button is enabled', async function() {
sinon.stub(instance, 'commitIsEnabled').returns(true);
assert.strictEqual(
await instance.advanceFocusFrom(CommitView.focus.COAUTHOR_INPUT),
CommitView.focus.COMMIT_BUTTON,
Expand All @@ -406,7 +423,15 @@ describe('CommitView', function() {
);
});

it('moves focus to the commit button if the abort merge button is focused', async function() {
it('moves focus to the RecentCommitsView if the abort merge button is focused', async function() {
assert.strictEqual(
await instance.advanceFocusFrom(CommitView.focus.ABORT_MERGE_BUTTON),
RecentCommitsView.firstFocus,
);
});

it('moves focus to the commit button if the abort merge button is focused and the commit button is enabled', async function() {
sinon.stub(instance, 'commitIsEnabled').returns(true);
assert.strictEqual(
await instance.advanceFocusFrom(CommitView.focus.ABORT_MERGE_BUTTON),
CommitView.focus.COMMIT_BUTTON,
Expand Down

0 comments on commit 447c9c5

Please sign in to comment.