diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/frontend/behaviors/shortcuts | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/frontend/behaviors/shortcuts')
-rw-r--r-- | spec/frontend/behaviors/shortcuts/shortcuts_issuable_spec.js | 94 |
1 files changed, 73 insertions, 21 deletions
diff --git a/spec/frontend/behaviors/shortcuts/shortcuts_issuable_spec.js b/spec/frontend/behaviors/shortcuts/shortcuts_issuable_spec.js index baedbf5771a..77dcc28dd48 100644 --- a/spec/frontend/behaviors/shortcuts/shortcuts_issuable_spec.js +++ b/spec/frontend/behaviors/shortcuts/shortcuts_issuable_spec.js @@ -1,20 +1,19 @@ import $ from 'jquery'; -import 'mousetrap'; +import Mousetrap from 'mousetrap'; import initCopyAsGFM, { CopyAsGFM } from '~/behaviors/markdown/copy_as_gfm'; import ShortcutsIssuable from '~/behaviors/shortcuts/shortcuts_issuable'; import { getSelectedFragment } from '~/lib/utils/common_utils'; -const FORM_SELECTOR = '.js-main-target-form .js-vue-comment-form'; - jest.mock('~/lib/utils/common_utils', () => ({ ...jest.requireActual('~/lib/utils/common_utils'), getSelectedFragment: jest.fn().mockName('getSelectedFragment'), })); describe('ShortcutsIssuable', () => { - const fixtureName = 'snippets/show.html'; + const snippetShowFixtureName = 'snippets/show.html'; + const mrShowFixtureName = 'merge_requests/merge_request_of_current_user.html'; - preloadFixtures(fixtureName); + preloadFixtures(snippetShowFixtureName, mrShowFixtureName); beforeAll(done => { initCopyAsGFM(); @@ -27,25 +26,27 @@ describe('ShortcutsIssuable', () => { .catch(done.fail); }); - beforeEach(() => { - loadFixtures(fixtureName); - $('body').append( - `<div class="js-main-target-form"> - <textarea class="js-vue-comment-form"></textarea> - </div>`, - ); - document.querySelector('.js-new-note-form').classList.add('js-main-target-form'); - - window.shortcut = new ShortcutsIssuable(true); - }); + describe('replyWithSelectedText', () => { + const FORM_SELECTOR = '.js-main-target-form .js-vue-comment-form'; + + beforeEach(() => { + loadFixtures(snippetShowFixtureName); + $('body').append( + `<div class="js-main-target-form"> + <textarea class="js-vue-comment-form"></textarea> + </div>`, + ); + document.querySelector('.js-new-note-form').classList.add('js-main-target-form'); + + window.shortcut = new ShortcutsIssuable(true); + }); - afterEach(() => { - $(FORM_SELECTOR).remove(); + afterEach(() => { + $(FORM_SELECTOR).remove(); - delete window.shortcut; - }); + delete window.shortcut; + }); - describe('replyWithSelectedText', () => { // Stub getSelectedFragment to return a node with the provided HTML. const stubSelection = (html, invalidNode) => { getSelectedFragment.mockImplementation(() => { @@ -319,4 +320,55 @@ describe('ShortcutsIssuable', () => { }); }); }); + + describe('copyBranchName', () => { + let sidebarCollapsedBtn; + let sidebarExpandedBtn; + + beforeEach(() => { + loadFixtures(mrShowFixtureName); + + window.shortcut = new ShortcutsIssuable(); + + [sidebarCollapsedBtn, sidebarExpandedBtn] = document.querySelectorAll( + '.sidebar-source-branch button', + ); + + [sidebarCollapsedBtn, sidebarExpandedBtn].forEach(btn => jest.spyOn(btn, 'click')); + }); + + afterEach(() => { + delete window.shortcut; + }); + + describe('when the sidebar is expanded', () => { + beforeEach(() => { + // simulate the applied CSS styles when the + // sidebar is expanded + sidebarCollapsedBtn.style.display = 'none'; + + Mousetrap.trigger('b'); + }); + + it('clicks the "expanded" version of the copy source branch button', () => { + expect(sidebarExpandedBtn.click).toHaveBeenCalled(); + expect(sidebarCollapsedBtn.click).not.toHaveBeenCalled(); + }); + }); + + describe('when the sidebar is collapsed', () => { + beforeEach(() => { + // simulate the applied CSS styles when the + // sidebar is collapsed + sidebarExpandedBtn.style.display = 'none'; + + Mousetrap.trigger('b'); + }); + + it('clicks the "collapsed" version of the copy source branch button', () => { + expect(sidebarCollapsedBtn.click).toHaveBeenCalled(); + expect(sidebarExpandedBtn.click).not.toHaveBeenCalled(); + }); + }); + }); }); |