diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-08 18:08:27 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-08 18:08:27 +0000 |
commit | 99c01aa6867b91b8d2279eb8d32794ea90d5dcdc (patch) | |
tree | ae36b06dd962230381080d9e2a31385cea5f8609 /spec/javascripts | |
parent | 5693fb6ba7d21ba7b79775543a3f195eb989664b (diff) | |
download | gitlab-ce-99c01aa6867b91b8d2279eb8d32794ea90d5dcdc.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts')
6 files changed, 0 insertions, 629 deletions
diff --git a/spec/javascripts/behaviors/autosize_spec.js b/spec/javascripts/behaviors/autosize_spec.js deleted file mode 100644 index 59abae479d4..00000000000 --- a/spec/javascripts/behaviors/autosize_spec.js +++ /dev/null @@ -1,20 +0,0 @@ -import $ from 'jquery'; -import '~/behaviors/autosize'; - -function load() { - $(document).trigger('load'); -} - -describe('Autosize behavior', () => { - beforeEach(() => { - setFixtures('<textarea class="js-autosize" style="resize: vertical"></textarea>'); - }); - - it('does not overwrite the resize property', () => { - load(); - - expect($('textarea')).toHaveCss({ - resize: 'vertical', - }); - }); -}); diff --git a/spec/javascripts/behaviors/copy_as_gfm_spec.js b/spec/javascripts/behaviors/copy_as_gfm_spec.js deleted file mode 100644 index d653fca0988..00000000000 --- a/spec/javascripts/behaviors/copy_as_gfm_spec.js +++ /dev/null @@ -1,125 +0,0 @@ -import initCopyAsGFM, { CopyAsGFM } from '~/behaviors/markdown/copy_as_gfm'; - -describe('CopyAsGFM', () => { - describe('CopyAsGFM.pasteGFM', () => { - function callPasteGFM() { - const e = { - originalEvent: { - clipboardData: { - getData(mimeType) { - // When GFM code is copied, we put the regular plain text - // on the clipboard as `text/plain`, and the GFM as `text/x-gfm`. - // This emulates the behavior of `getData` with that data. - if (mimeType === 'text/plain') { - return 'code'; - } - if (mimeType === 'text/x-gfm') { - return '`code`'; - } - return null; - }, - }, - }, - preventDefault() {}, - }; - - CopyAsGFM.pasteGFM(e); - } - - it('wraps pasted code when not already in code tags', () => { - spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => { - const insertedText = textFunc('This is code: ', ''); - - expect(insertedText).toEqual('`code`'); - }); - - callPasteGFM(); - }); - - it('does not wrap pasted code when already in code tags', () => { - spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => { - const insertedText = textFunc('This is code: `', '`'); - - expect(insertedText).toEqual('code'); - }); - - callPasteGFM(); - }); - }); - - describe('CopyAsGFM.copyGFM', () => { - // Stub getSelection to return a purpose-built object. - const stubSelection = (html, parentNode) => ({ - getRangeAt: () => ({ - commonAncestorContainer: { tagName: parentNode }, - cloneContents: () => { - const fragment = document.createDocumentFragment(); - const node = document.createElement('div'); - node.innerHTML = html; - Array.from(node.childNodes).forEach(item => fragment.appendChild(item)); - return fragment; - }, - }), - rangeCount: 1, - }); - - const clipboardData = { - setData() {}, - }; - - const simulateCopy = () => { - const e = { - originalEvent: { - clipboardData, - }, - preventDefault() {}, - stopPropagation() {}, - }; - CopyAsGFM.copyAsGFM(e, CopyAsGFM.transformGFMSelection); - return clipboardData; - }; - - beforeAll(done => { - initCopyAsGFM(); - - // Fake call to nodeToGfm so the import of lazy bundle happened - CopyAsGFM.nodeToGFM(document.createElement('div')) - .then(() => { - done(); - }) - .catch(done.fail); - }); - - beforeEach(() => spyOn(clipboardData, 'setData')); - - describe('list handling', () => { - it('uses correct gfm for unordered lists', done => { - const selection = stubSelection('<li>List Item1</li><li>List Item2</li>\n', 'UL'); - - spyOn(window, 'getSelection').and.returnValue(selection); - simulateCopy(); - - setTimeout(() => { - const expectedGFM = '* List Item1\n* List Item2'; - - expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM); - done(); - }); - }); - - it('uses correct gfm for ordered lists', done => { - const selection = stubSelection('<li>List Item1</li><li>List Item2</li>\n', 'OL'); - - spyOn(window, 'getSelection').and.returnValue(selection); - simulateCopy(); - - setTimeout(() => { - const expectedGFM = '1. List Item1\n1. List Item2'; - - expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM); - done(); - }); - }); - }); - }); -}); diff --git a/spec/javascripts/behaviors/gl_emoji/unicode_support_map_spec.js b/spec/javascripts/behaviors/gl_emoji/unicode_support_map_spec.js deleted file mode 100644 index f656b97fec2..00000000000 --- a/spec/javascripts/behaviors/gl_emoji/unicode_support_map_spec.js +++ /dev/null @@ -1,52 +0,0 @@ -import getUnicodeSupportMap from '~/emoji/support/unicode_support_map'; -import AccessorUtilities from '~/lib/utils/accessor'; - -describe('Unicode Support Map', () => { - describe('getUnicodeSupportMap', () => { - const stringSupportMap = 'stringSupportMap'; - - beforeEach(() => { - spyOn(AccessorUtilities, 'isLocalStorageAccessSafe'); - spyOn(window.localStorage, 'getItem'); - spyOn(window.localStorage, 'setItem'); - spyOn(JSON, 'parse'); - spyOn(JSON, 'stringify').and.returnValue(stringSupportMap); - }); - - describe('if isLocalStorageAvailable is `true`', function() { - beforeEach(() => { - AccessorUtilities.isLocalStorageAccessSafe.and.returnValue(true); - - getUnicodeSupportMap(); - }); - - it('should call .getItem and .setItem', () => { - const getArgs = window.localStorage.getItem.calls.allArgs(); - const setArgs = window.localStorage.setItem.calls.allArgs(); - - expect(getArgs[0][0]).toBe('gl-emoji-version'); - expect(getArgs[1][0]).toBe('gl-emoji-user-agent'); - - expect(setArgs[0][0]).toBe('gl-emoji-version'); - expect(setArgs[0][1]).toBe('0.2.0'); - expect(setArgs[1][0]).toBe('gl-emoji-user-agent'); - expect(setArgs[1][1]).toBe(navigator.userAgent); - expect(setArgs[2][0]).toBe('gl-emoji-unicode-support-map'); - expect(setArgs[2][1]).toBe(stringSupportMap); - }); - }); - - describe('if isLocalStorageAvailable is `false`', function() { - beforeEach(() => { - AccessorUtilities.isLocalStorageAccessSafe.and.returnValue(false); - - getUnicodeSupportMap(); - }); - - it('should not call .getItem or .setItem', () => { - expect(window.localStorage.getItem.calls.count()).toBe(1); - expect(window.localStorage.setItem).not.toHaveBeenCalled(); - }); - }); - }); -}); diff --git a/spec/javascripts/behaviors/markdown/highlight_current_user_spec.js b/spec/javascripts/behaviors/markdown/highlight_current_user_spec.js deleted file mode 100644 index 3305ddc412d..00000000000 --- a/spec/javascripts/behaviors/markdown/highlight_current_user_spec.js +++ /dev/null @@ -1,55 +0,0 @@ -import highlightCurrentUser from '~/behaviors/markdown/highlight_current_user'; - -describe('highlightCurrentUser', () => { - let rootElement; - let elements; - - beforeEach(() => { - setFixtures(` - <div id="dummy-root-element"> - <div data-user="1">@first</div> - <div data-user="2">@second</div> - </div> - `); - rootElement = document.getElementById('dummy-root-element'); - elements = rootElement.querySelectorAll('[data-user]'); - }); - - describe('without current user', () => { - beforeEach(() => { - window.gon = window.gon || {}; - window.gon.current_user_id = null; - }); - - afterEach(() => { - delete window.gon.current_user_id; - }); - - it('does not highlight the user', () => { - const initialHtml = rootElement.outerHTML; - - highlightCurrentUser(elements); - - expect(rootElement.outerHTML).toBe(initialHtml); - }); - }); - - describe('with current user', () => { - beforeEach(() => { - window.gon = window.gon || {}; - window.gon.current_user_id = 2; - }); - - afterEach(() => { - delete window.gon.current_user_id; - }); - - it('highlights current user', () => { - highlightCurrentUser(elements); - - expect(elements.length).toBe(2); - expect(elements[0]).not.toHaveClass('current-user'); - expect(elements[1]).toHaveClass('current-user'); - }); - }); -}); diff --git a/spec/javascripts/behaviors/requires_input_spec.js b/spec/javascripts/behaviors/requires_input_spec.js deleted file mode 100644 index 617fe49b059..00000000000 --- a/spec/javascripts/behaviors/requires_input_spec.js +++ /dev/null @@ -1,62 +0,0 @@ -import $ from 'jquery'; -import '~/behaviors/requires_input'; - -describe('requiresInput', () => { - let submitButton; - preloadFixtures('branches/new_branch.html'); - - beforeEach(() => { - loadFixtures('branches/new_branch.html'); - submitButton = $('button[type="submit"]'); - }); - - it('disables submit when any field is required', () => { - $('.js-requires-input').requiresInput(); - - expect(submitButton).toBeDisabled(); - }); - - it('enables submit when no field is required', () => { - $('*[required=required]').prop('required', false); - $('.js-requires-input').requiresInput(); - - expect(submitButton).not.toBeDisabled(); - }); - - it('enables submit when all required fields are pre-filled', () => { - $('*[required=required]').remove(); - $('.js-requires-input').requiresInput(); - - expect($('.submit')).not.toBeDisabled(); - }); - - it('enables submit when all required fields receive input', () => { - $('.js-requires-input').requiresInput(); - $('#required1') - .val('input1') - .change(); - - expect(submitButton).toBeDisabled(); - - $('#optional1') - .val('input1') - .change(); - - expect(submitButton).toBeDisabled(); - - $('#required2') - .val('input2') - .change(); - $('#required3') - .val('input3') - .change(); - $('#required4') - .val('input4') - .change(); - $('#required5') - .val('1') - .change(); - - expect($('.submit')).not.toBeDisabled(); - }); -}); diff --git a/spec/javascripts/behaviors/shortcuts/shortcuts_issuable_spec.js b/spec/javascripts/behaviors/shortcuts/shortcuts_issuable_spec.js deleted file mode 100644 index f6232026915..00000000000 --- a/spec/javascripts/behaviors/shortcuts/shortcuts_issuable_spec.js +++ /dev/null @@ -1,315 +0,0 @@ -/* eslint-disable - no-underscore-dangle -*/ - -import $ from 'jquery'; -import initCopyAsGFM, { CopyAsGFM } from '~/behaviors/markdown/copy_as_gfm'; -import ShortcutsIssuable from '~/behaviors/shortcuts/shortcuts_issuable'; - -const FORM_SELECTOR = '.js-main-target-form .js-vue-comment-form'; - -describe('ShortcutsIssuable', function() { - const fixtureName = 'snippets/show.html'; - preloadFixtures(fixtureName); - - beforeAll(done => { - initCopyAsGFM(); - - // Fake call to nodeToGfm so the import of lazy bundle happened - CopyAsGFM.nodeToGFM(document.createElement('div')) - .then(() => { - done(); - }) - .catch(done.fail); - }); - - beforeEach(() => { - loadFixtures(fixtureName); - $('body').append( - `<div class="js-main-target-form"> - <textare class="js-vue-comment-form"></textare> - </div>`, - ); - 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, invalidNode) => { - ShortcutsIssuable.__Rewire__('getSelectedFragment', () => { - const documentFragment = document.createDocumentFragment(); - const node = document.createElement('div'); - - node.innerHTML = html; - if (!invalidNode) node.className = 'md'; - - documentFragment.appendChild(node); - return documentFragment; - }); - }; - - 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('<p>Selected text.</p>'); - }); - - it('leaves existing input intact', done => { - $(FORM_SELECTOR).val('This text was already here.'); - - expect($(FORM_SELECTOR).val()).toBe('This text was already here.'); - - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect($(FORM_SELECTOR).val()).toBe( - 'This text was already here.\n\n> Selected text.\n\n', - ); - done(); - }); - }); - - it('triggers `input`', done => { - let triggered = false; - $(FORM_SELECTOR).on('input', () => { - triggered = true; - }); - - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect(triggered).toBe(true); - done(); - }); - }); - - it('triggers `focus`', done => { - const spy = spyOn(document.querySelector(FORM_SELECTOR), 'focus'); - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect(spy).toHaveBeenCalled(); - done(); - }); - }); - }); - - describe('with a one-line selection', () => { - it('quotes the selection', done => { - stubSelection('<p>This text has been selected.</p>'); - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect($(FORM_SELECTOR).val()).toBe('> This text has been selected.\n\n'); - done(); - }); - }); - }); - - describe('with a multi-line selection', () => { - it('quotes the selected lines as a group', done => { - stubSelection( - '<p>Selected line one.</p>\n<p>Selected line two.</p>\n<p>Selected line three.</p>', - ); - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect($(FORM_SELECTOR).val()).toBe( - '> Selected line one.\n>\n> Selected line two.\n>\n> Selected line three.\n\n', - ); - done(); - }); - }); - }); - - describe('with an invalid selection', () => { - beforeEach(() => { - stubSelection('<p>Selected text.</p>', true); - }); - - it('does not add anything to the input', done => { - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect($(FORM_SELECTOR).val()).toBe(''); - done(); - }); - }); - - it('triggers `focus`', done => { - const spy = spyOn(document.querySelector(FORM_SELECTOR), 'focus'); - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect(spy).toHaveBeenCalled(); - done(); - }); - }); - }); - - describe('with a semi-valid selection', () => { - beforeEach(() => { - stubSelection('<div class="md">Selected text.</div><p>Invalid selected text.</p>', true); - }); - - it('only adds the valid part to the input', done => { - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect($(FORM_SELECTOR).val()).toBe('> Selected text.\n\n'); - done(); - }); - }); - - it('triggers `focus`', done => { - const spy = spyOn(document.querySelector(FORM_SELECTOR), 'focus'); - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect(spy).toHaveBeenCalled(); - done(); - }); - }); - - it('triggers `input`', done => { - let triggered = false; - $(FORM_SELECTOR).on('input', () => { - triggered = true; - }); - - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect(triggered).toBe(true); - done(); - }); - }); - }); - - describe('with a selection in a valid block', () => { - beforeEach(() => { - ShortcutsIssuable.__Rewire__('getSelectedFragment', () => { - const documentFragment = document.createDocumentFragment(); - const node = document.createElement('div'); - const originalNode = document.createElement('body'); - originalNode.innerHTML = `<div class="issue"> - <div class="otherElem">Text...</div> - <div class="md"><p><em>Selected text.</em></p></div> - </div>`; - documentFragment.originalNodes = [originalNode.querySelector('em')]; - - node.innerHTML = '<em>Selected text.</em>'; - - documentFragment.appendChild(node); - - return documentFragment; - }); - }); - - it('adds the quoted selection to the input', done => { - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect($(FORM_SELECTOR).val()).toBe('> *Selected text.*\n\n'); - done(); - }); - }); - - it('triggers `focus`', done => { - const spy = spyOn(document.querySelector(FORM_SELECTOR), 'focus'); - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect(spy).toHaveBeenCalled(); - done(); - }); - }); - - it('triggers `input`', done => { - let triggered = false; - $(FORM_SELECTOR).on('input', () => { - triggered = true; - }); - - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect(triggered).toBe(true); - done(); - }); - }); - }); - - describe('with a selection in an invalid block', () => { - beforeEach(() => { - ShortcutsIssuable.__Rewire__('getSelectedFragment', () => { - const documentFragment = document.createDocumentFragment(); - const node = document.createElement('div'); - const originalNode = document.createElement('body'); - originalNode.innerHTML = `<div class="issue"> - <div class="otherElem"><div><b>Selected text.</b></div></div> - <div class="md"><p><em>Valid text</em></p></div> - </div>`; - documentFragment.originalNodes = [originalNode.querySelector('b')]; - - node.innerHTML = '<b>Selected text.</b>'; - - documentFragment.appendChild(node); - - return documentFragment; - }); - }); - - it('does not add anything to the input', done => { - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect($(FORM_SELECTOR).val()).toBe(''); - done(); - }); - }); - - it('triggers `focus`', done => { - const spy = spyOn(document.querySelector(FORM_SELECTOR), 'focus'); - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect(spy).toHaveBeenCalled(); - done(); - }); - }); - }); - - describe('with a valid selection with no text content', () => { - it('returns the proper markdown', done => { - stubSelection('<img src="foo" alt="image" />'); - ShortcutsIssuable.replyWithSelectedText(true); - - setTimeout(() => { - expect($(FORM_SELECTOR).val()).toBe('> ![image](http://localhost:9876/foo)\n\n'); - - done(); - }); - }); - }); - }); -}); |