Skip to content

Commit 97a73de

Browse files
committed
Specs for advancing and retreating focus within CommitView
1 parent 665b8f7 commit 97a73de

1 file changed

Lines changed: 136 additions & 0 deletions

File tree

‎test/views/commit-view.test.js‎

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,142 @@ describe('CommitView', function() {
359359
assert.isFalse(wrapper.instance().hasFocusEditor());
360360
});
361361

362+
describe('advancing focus', function() {
363+
let wrapper, instance, event;
364+
365+
beforeEach(function() {
366+
wrapper = mount(app);
367+
instance = wrapper.instance();
368+
event = {stopPropagation: sinon.spy()};
369+
370+
sinon.spy(instance, 'setFocus');
371+
});
372+
373+
it('does nothing and returns false if the focus is not in the commit view', function() {
374+
sinon.stub(instance, 'getFocus').returns(null);
375+
assert.isFalse(instance.advanceFocus(event));
376+
assert.isFalse(instance.setFocus.called);
377+
assert.isFalse(event.stopPropagation.called);
378+
});
379+
380+
it('moves focus to the commit editor if the commit preview button is focused', function() {
381+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.COMMIT_PREVIEW_BUTTON);
382+
383+
assert.isTrue(instance.advanceFocus(event));
384+
assert.isTrue(instance.setFocus.calledWith(CommitView.focus.EDITOR));
385+
assert.isTrue(event.stopPropagation.called);
386+
});
387+
388+
it('inserts a tab if the commit editor is focused', function() {
389+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.EDITOR);
390+
391+
assert.isTrue(instance.advanceFocus(event));
392+
assert.isFalse(event.stopPropagation.called);
393+
});
394+
395+
it('moves focus to the commit button if the coauthor form is focused and no merge is in progress', function() {
396+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.COAUTHOR_INPUT);
397+
398+
assert.isTrue(instance.advanceFocus(event));
399+
assert.isTrue(instance.setFocus.calledWith(CommitView.focus.COMMIT_BUTTON));
400+
assert.isTrue(event.stopPropagation.called);
401+
});
402+
403+
it('moves focus to the abort merge button if the coauthor form is focused and a merge is in progress', function() {
404+
wrapper.setProps({isMerging: true});
405+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.COAUTHOR_INPUT);
406+
407+
assert.isTrue(instance.advanceFocus(event));
408+
assert.isTrue(instance.setFocus.calledWith(CommitView.focus.ABORT_MERGE_BUTTON));
409+
assert.isTrue(event.stopPropagation.called);
410+
});
411+
412+
it('moves focus to the commit button if the abort merge button is focused', function() {
413+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.ABORT_MERGE_BUTTON);
414+
415+
assert.isTrue(instance.advanceFocus(event));
416+
assert.isTrue(instance.setFocus.calledWith(CommitView.focus.COMMIT_BUTTON));
417+
assert.isTrue(event.stopPropagation.called);
418+
});
419+
420+
it('does nothing and returns true if the commit button is focused', function() {
421+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.COMMIT_BUTTON);
422+
423+
assert.isTrue(instance.advanceFocus(event));
424+
assert.isFalse(instance.setFocus.called);
425+
assert.isTrue(event.stopPropagation.called);
426+
});
427+
});
428+
429+
describe('retreating focus', function() {
430+
let wrapper, instance, event;
431+
432+
beforeEach(function() {
433+
wrapper = mount(app);
434+
instance = wrapper.instance();
435+
event = {stopPropagation: sinon.spy()};
436+
437+
sinon.spy(instance, 'setFocus');
438+
});
439+
440+
it('does nothing and returns false if the focus is not in the commit view', function() {
441+
sinon.stub(instance, 'getFocus').returns(null);
442+
443+
assert.isFalse(instance.retreatFocus(event));
444+
assert.isFalse(instance.setFocus.called);
445+
assert.isFalse(event.stopPropagation.called);
446+
});
447+
448+
it('moves focus to the abort merge button if the commit button is focused and a merge is in progress', function() {
449+
wrapper.setProps({isMerging: true});
450+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.COMMIT_BUTTON);
451+
452+
assert.isTrue(instance.retreatFocus(event));
453+
assert.isTrue(instance.setFocus.calledWith(CommitView.focus.ABORT_MERGE_BUTTON));
454+
assert.isTrue(event.stopPropagation.called);
455+
});
456+
457+
it('moves focus to the co-author form if the commit button is focused and no merge is in progress', function() {
458+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.COMMIT_BUTTON);
459+
460+
assert.isTrue(instance.retreatFocus(event));
461+
assert.isTrue(instance.setFocus.calledWith(CommitView.focus.COAUTHOR_INPUT));
462+
assert.isTrue(event.stopPropagation.called);
463+
});
464+
465+
it('moves focus to the co-author form if the abort merge button is in focus', function() {
466+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.ABORT_MERGE_BUTTON);
467+
468+
assert.isTrue(instance.retreatFocus(event));
469+
assert.isTrue(instance.setFocus.calledWith(CommitView.focus.COAUTHOR_INPUT));
470+
assert.isTrue(event.stopPropagation.called);
471+
});
472+
473+
it('moves focus to the commit editor if the co-author form is focused', function() {
474+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.COAUTHOR_INPUT);
475+
476+
assert.isTrue(instance.retreatFocus(event));
477+
assert.isTrue(instance.setFocus.calledWith(CommitView.focus.EDITOR));
478+
assert.isTrue(event.stopPropagation.called);
479+
});
480+
481+
it('moves focus to the commit preview button if the commit editor is focused', function() {
482+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.EDITOR);
483+
484+
assert.isTrue(instance.retreatFocus(event));
485+
assert.isTrue(instance.setFocus.calledWith(CommitView.focus.COMMIT_PREVIEW_BUTTON));
486+
assert.isTrue(event.stopPropagation.called);
487+
});
488+
489+
it('does nothing and returns false if the commit preview button is focused', function() {
490+
sinon.stub(instance, 'getFocus').returns(CommitView.focus.COMMIT_PREVIEW_BUTTON);
491+
492+
assert.isFalse(instance.retreatFocus(event));
493+
assert.isFalse(instance.setFocus.called);
494+
assert.isFalse(event.stopPropagation.called);
495+
});
496+
});
497+
362498
it('remembers the current focus', function() {
363499
const wrapper = mount(React.cloneElement(app, {isMerging: true}));
364500
wrapper.instance().toggleCoAuthorInput();

0 commit comments

Comments
 (0)