From e55c7a9a3572ad37a8b69cd2d3db9ab24b5ba5ab Mon Sep 17 00:00:00 2001 From: Paul Slaughter Date: Thu, 15 Aug 2019 10:11:36 -0500 Subject: Add key unbinds to DiscussionKeyboardNavigator Also adds comment to explain why this works on the diff-tab when it's only used in `notes-app`. https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/30144#note_204066538 --- .../discussion_keyboard_navigator_spec.js | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'spec/frontend/notes') diff --git a/spec/frontend/notes/components/discussion_keyboard_navigator_spec.js b/spec/frontend/notes/components/discussion_keyboard_navigator_spec.js index 6d50713999d..8881bedf3cc 100644 --- a/spec/frontend/notes/components/discussion_keyboard_navigator_spec.js +++ b/spec/frontend/notes/components/discussion_keyboard_navigator_spec.js @@ -74,4 +74,31 @@ describe('notes/components/discussion_keyboard_navigator', () => { expect(wrapper.vm.currentDiscussionId).toEqual(expectedPrevId); }); }); + + describe('on destroy', () => { + beforeEach(() => { + jest.spyOn(Mousetrap, 'unbind'); + + createComponent(); + + wrapper.destroy(); + }); + + it('unbinds keys', () => { + expect(Mousetrap.unbind).toHaveBeenCalledWith('n'); + expect(Mousetrap.unbind).toHaveBeenCalledWith('p'); + }); + + it('does not call jumpToNextDiscussion when pressing `n`', () => { + Mousetrap.trigger('n'); + + expect(wrapper.vm.jumpToDiscussion).not.toHaveBeenCalled(); + }); + + it('does not call jumpToNextDiscussion when pressing `p`', () => { + Mousetrap.trigger('p'); + + expect(wrapper.vm.jumpToDiscussion).not.toHaveBeenCalled(); + }); + }); }); -- cgit v1.2.3