From 05f403cf046912b53c4b4f4dae48d4b8cc375812 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Thu, 13 Sep 2018 16:59:09 -0500 Subject: Move search autocomplete from dispatcher to main.js --- spec/javascripts/search_autocomplete_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/javascripts/search_autocomplete_spec.js b/spec/javascripts/search_autocomplete_spec.js index 86c001678c5..646d843162c 100644 --- a/spec/javascripts/search_autocomplete_spec.js +++ b/spec/javascripts/search_autocomplete_spec.js @@ -2,7 +2,7 @@ import $ from 'jquery'; import '~/gl_dropdown'; -import SearchAutocomplete from '~/search_autocomplete'; +import initSearchAutocomplete from '~/search_autocomplete'; import '~/lib/utils/common_utils'; describe('Search autocomplete dropdown', () => { @@ -132,7 +132,7 @@ describe('Search autocomplete dropdown', () => { window.gon.current_user_id = userId; window.gon.current_username = userName; - return (widget = new SearchAutocomplete()); + return (widget = initSearchAutocomplete()); }); afterEach(function() { -- cgit v1.2.1 From 08c3920ce14628e90244fba5f580ca4d7bdabdbd Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Tue, 18 Sep 2018 14:43:46 -0500 Subject: Move findAndFollowLink to lib/utils --- .../lib/utils/navigation_utility_spec.js | 23 ++++++++++++++++++++++ .../shortcuts_dashboard_navigation_spec.js | 23 ---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 spec/javascripts/lib/utils/navigation_utility_spec.js delete mode 100644 spec/javascripts/shortcuts_dashboard_navigation_spec.js (limited to 'spec') diff --git a/spec/javascripts/lib/utils/navigation_utility_spec.js b/spec/javascripts/lib/utils/navigation_utility_spec.js new file mode 100644 index 00000000000..be620e4a27c --- /dev/null +++ b/spec/javascripts/lib/utils/navigation_utility_spec.js @@ -0,0 +1,23 @@ +import findAndFollowLink from '~/lib/utils/navigation_utility'; + +describe('findAndFollowLink', () => { + it('visits a link when the selector exists', () => { + const href = '/some/path'; + const visitUrl = spyOnDependency(findAndFollowLink, 'visitUrl'); + + setFixtures(`link`); + + findAndFollowLink('.my-shortcut'); + + expect(visitUrl).toHaveBeenCalledWith(href); + }); + + it('does not throw an exception when the selector does not exist', () => { + const visitUrl = spyOnDependency(findAndFollowLink, 'visitUrl'); + + // this should not throw an exception + findAndFollowLink('.this-selector-does-not-exist'); + + expect(visitUrl).not.toHaveBeenCalled(); + }); +}); diff --git a/spec/javascripts/shortcuts_dashboard_navigation_spec.js b/spec/javascripts/shortcuts_dashboard_navigation_spec.js deleted file mode 100644 index 7cb201e01d8..00000000000 --- a/spec/javascripts/shortcuts_dashboard_navigation_spec.js +++ /dev/null @@ -1,23 +0,0 @@ -import findAndFollowLink from '~/shortcuts_dashboard_navigation'; - -describe('findAndFollowLink', () => { - it('visits a link when the selector exists', () => { - const href = '/some/path'; - const visitUrl = spyOnDependency(findAndFollowLink, 'visitUrl'); - - setFixtures(`link`); - - findAndFollowLink('.my-shortcut'); - - expect(visitUrl).toHaveBeenCalledWith(href); - }); - - it('does not throw an exception when the selector does not exist', () => { - const visitUrl = spyOnDependency(findAndFollowLink, 'visitUrl'); - - // this should not throw an exception - findAndFollowLink('.this-selector-does-not-exist'); - - expect(visitUrl).not.toHaveBeenCalled(); - }); -}); -- cgit v1.2.1 From 196dfd2627fec6c0ede1d7df0dd49881b2bbd898 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Tue, 18 Sep 2018 15:34:14 -0500 Subject: Move shortcuts classes into behaviors/shortcuts --- .../behaviors/shortcuts/shortcuts_issuable_spec.js | 106 +++++++++++++++++++++ spec/javascripts/shortcuts_issuable_spec.js | 106 --------------------- spec/javascripts/shortcuts_spec.js | 2 +- 3 files changed, 107 insertions(+), 107 deletions(-) create mode 100644 spec/javascripts/behaviors/shortcuts/shortcuts_issuable_spec.js delete mode 100644 spec/javascripts/shortcuts_issuable_spec.js (limited to 'spec') diff --git a/spec/javascripts/behaviors/shortcuts/shortcuts_issuable_spec.js b/spec/javascripts/behaviors/shortcuts/shortcuts_issuable_spec.js new file mode 100644 index 00000000000..01b5bc112b2 --- /dev/null +++ b/spec/javascripts/behaviors/shortcuts/shortcuts_issuable_spec.js @@ -0,0 +1,106 @@ +import $ from 'jquery'; +import initCopyAsGFM from '~/behaviors/markdown/copy_as_gfm'; +import ShortcutsIssuable from '~/behaviors/shortcuts/shortcuts_issuable'; + +initCopyAsGFM(); + +const FORM_SELECTOR = '.js-main-target-form .js-vue-comment-form'; + +describe('ShortcutsIssuable', function() { + const fixtureName = 'snippets/show.html.raw'; + preloadFixtures(fixtureName); + + beforeEach(() => { + loadFixtures(fixtureName); + $('body').append( + `
+ +
`, + ); + document.querySelector('.js-new-note-form').classList.add('js-main-target-form'); + this.shortcut = new ShortcutsIssuable(true); + }); + + afterEach(() => { + $(FORM_SELECTOR).remove(); + }); + + describe('replyWithSelectedText', () => { + // Stub window.gl.utils.getSelectedFragment to return a node with the provided HTML. + const stubSelection = html => { + window.gl.utils.getSelectedFragment = () => { + const node = document.createElement('div'); + node.innerHTML = html; + + return node; + }; + }; + describe('with empty selection', () => { + it('does not return an error', () => { + ShortcutsIssuable.replyWithSelectedText(true); + + expect($(FORM_SELECTOR).val()).toBe(''); + }); + + it('triggers `focus`', () => { + const spy = spyOn(document.querySelector(FORM_SELECTOR), 'focus'); + ShortcutsIssuable.replyWithSelectedText(true); + + expect(spy).toHaveBeenCalled(); + }); + }); + + describe('with any selection', () => { + beforeEach(() => { + stubSelection('

Selected text.

'); + }); + + it('leaves existing input intact', () => { + $(FORM_SELECTOR).val('This text was already here.'); + expect($(FORM_SELECTOR).val()).toBe('This text was already here.'); + + ShortcutsIssuable.replyWithSelectedText(true); + expect($(FORM_SELECTOR).val()).toBe('This text was already here.\n\n> Selected text.\n\n'); + }); + + it('triggers `input`', () => { + let triggered = false; + $(FORM_SELECTOR).on('input', () => { + triggered = true; + }); + + ShortcutsIssuable.replyWithSelectedText(true); + expect(triggered).toBe(true); + }); + + it('triggers `focus`', () => { + const spy = spyOn(document.querySelector(FORM_SELECTOR), 'focus'); + ShortcutsIssuable.replyWithSelectedText(true); + + expect(spy).toHaveBeenCalled(); + }); + }); + + describe('with a one-line selection', () => { + it('quotes the selection', () => { + stubSelection('

This text has been selected.

'); + ShortcutsIssuable.replyWithSelectedText(true); + + expect($(FORM_SELECTOR).val()).toBe('> This text has been selected.\n\n'); + }); + }); + + describe('with a multi-line selection', () => { + it('quotes the selected lines as a group', () => { + stubSelection( + '

Selected line one.

\n

Selected line two.

\n

Selected line three.

', + ); + ShortcutsIssuable.replyWithSelectedText(true); + + expect($(FORM_SELECTOR).val()).toBe( + '> Selected line one.\n>\n> Selected line two.\n>\n> Selected line three.\n\n', + ); + }); + }); + }); +}); diff --git a/spec/javascripts/shortcuts_issuable_spec.js b/spec/javascripts/shortcuts_issuable_spec.js deleted file mode 100644 index a4753ab7cde..00000000000 --- a/spec/javascripts/shortcuts_issuable_spec.js +++ /dev/null @@ -1,106 +0,0 @@ -import $ from 'jquery'; -import initCopyAsGFM from '~/behaviors/markdown/copy_as_gfm'; -import ShortcutsIssuable from '~/shortcuts_issuable'; - -initCopyAsGFM(); - -const FORM_SELECTOR = '.js-main-target-form .js-vue-comment-form'; - -describe('ShortcutsIssuable', function() { - const fixtureName = 'snippets/show.html.raw'; - preloadFixtures(fixtureName); - - beforeEach(() => { - loadFixtures(fixtureName); - $('body').append( - `
- -
`, - ); - document.querySelector('.js-new-note-form').classList.add('js-main-target-form'); - this.shortcut = new ShortcutsIssuable(true); - }); - - afterEach(() => { - $(FORM_SELECTOR).remove(); - }); - - describe('replyWithSelectedText', () => { - // Stub window.gl.utils.getSelectedFragment to return a node with the provided HTML. - const stubSelection = html => { - window.gl.utils.getSelectedFragment = () => { - const node = document.createElement('div'); - node.innerHTML = html; - - return node; - }; - }; - describe('with empty selection', () => { - it('does not return an error', () => { - ShortcutsIssuable.replyWithSelectedText(true); - - expect($(FORM_SELECTOR).val()).toBe(''); - }); - - it('triggers `focus`', () => { - const spy = spyOn(document.querySelector(FORM_SELECTOR), 'focus'); - ShortcutsIssuable.replyWithSelectedText(true); - - expect(spy).toHaveBeenCalled(); - }); - }); - - describe('with any selection', () => { - beforeEach(() => { - stubSelection('

Selected text.

'); - }); - - it('leaves existing input intact', () => { - $(FORM_SELECTOR).val('This text was already here.'); - expect($(FORM_SELECTOR).val()).toBe('This text was already here.'); - - ShortcutsIssuable.replyWithSelectedText(true); - expect($(FORM_SELECTOR).val()).toBe('This text was already here.\n\n> Selected text.\n\n'); - }); - - it('triggers `input`', () => { - let triggered = false; - $(FORM_SELECTOR).on('input', () => { - triggered = true; - }); - - ShortcutsIssuable.replyWithSelectedText(true); - expect(triggered).toBe(true); - }); - - it('triggers `focus`', () => { - const spy = spyOn(document.querySelector(FORM_SELECTOR), 'focus'); - ShortcutsIssuable.replyWithSelectedText(true); - - expect(spy).toHaveBeenCalled(); - }); - }); - - describe('with a one-line selection', () => { - it('quotes the selection', () => { - stubSelection('

This text has been selected.

'); - ShortcutsIssuable.replyWithSelectedText(true); - - expect($(FORM_SELECTOR).val()).toBe('> This text has been selected.\n\n'); - }); - }); - - describe('with a multi-line selection', () => { - it('quotes the selected lines as a group', () => { - stubSelection( - '

Selected line one.

\n

Selected line two.

\n

Selected line three.

', - ); - ShortcutsIssuable.replyWithSelectedText(true); - - expect($(FORM_SELECTOR).val()).toBe( - '> Selected line one.\n>\n> Selected line two.\n>\n> Selected line three.\n\n', - ); - }); - }); - }); -}); diff --git a/spec/javascripts/shortcuts_spec.js b/spec/javascripts/shortcuts_spec.js index 94cded7ee37..3ca6ecaa938 100644 --- a/spec/javascripts/shortcuts_spec.js +++ b/spec/javascripts/shortcuts_spec.js @@ -1,5 +1,5 @@ import $ from 'jquery'; -import Shortcuts from '~/shortcuts'; +import Shortcuts from '~/behaviors/shortcuts/shortcuts'; describe('Shortcuts', () => { const fixtureName = 'snippets/show.html.raw'; -- cgit v1.2.1