diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js')
-rw-r--r-- | spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js b/spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js index b492a69fb3d..21058005d29 100644 --- a/spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js +++ b/spec/frontend/vue_mr_widget/components/mr_widget_header_spec.js @@ -1,7 +1,13 @@ import Vue from 'vue'; +import Mousetrap from 'mousetrap'; import mountComponent from 'helpers/vue_mount_component_helper'; import headerComponent from '~/vue_merge_request_widget/components/mr_widget_header.vue'; +jest.mock('mousetrap', () => ({ + bind: jest.fn(), + unbind: jest.fn(), +})); + describe('MRWidgetHeader', () => { let vm; let Component; @@ -126,6 +132,35 @@ describe('MRWidgetHeader', () => { it('renders target branch', () => { expect(vm.$el.querySelector('.js-target-branch').textContent.trim()).toEqual('master'); }); + + describe('keyboard shortcuts', () => { + it('binds a keyboard shortcut handler to the "b" key', () => { + expect(Mousetrap.bind).toHaveBeenCalledWith('b', expect.any(Function)); + }); + + it('triggers a click on the "copy to clipboard" button when the handler is executed', () => { + const testClickHandler = jest.fn(); + vm.$refs.copyBranchNameButton.$el.addEventListener('click', testClickHandler); + + // Get a reference to the function that was assigned to the "b" shortcut key. + const shortcutHandler = Mousetrap.bind.mock.calls[0][1]; + + expect(testClickHandler).not.toHaveBeenCalled(); + + // Simulate Mousetrap calling the function. + shortcutHandler(); + + expect(testClickHandler).toHaveBeenCalledTimes(1); + }); + + it('unbinds the keyboard shortcut when the component is destroyed', () => { + expect(Mousetrap.unbind).not.toHaveBeenCalled(); + + vm.$destroy(); + + expect(Mousetrap.unbind).toHaveBeenCalledWith('b'); + }); + }); }); describe('with an open merge request', () => { |