diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-27 15:08:39 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-27 15:08:39 +0000 |
commit | 2b1e7f7dac0fa5d7bb3bdf415cec1b3c67ed77b0 (patch) | |
tree | 725ae8200573957bff6fa03aee237f738dadf1d7 /spec/frontend/behaviors | |
parent | eb004dc626d3a1c9497e8b9dc0f3f578afd05fd9 (diff) | |
download | gitlab-ce-2b1e7f7dac0fa5d7bb3bdf415cec1b3c67ed77b0.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/behaviors')
-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(); + }); + }); + }); }); |