diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/frontend/snippet | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/frontend/snippet')
-rw-r--r-- | spec/frontend/snippet/snippet_bundle_spec.js | 87 | ||||
-rw-r--r-- | spec/frontend/snippet/snippet_edit_spec.js | 44 |
2 files changed, 0 insertions, 131 deletions
diff --git a/spec/frontend/snippet/snippet_bundle_spec.js b/spec/frontend/snippet/snippet_bundle_spec.js deleted file mode 100644 index 208d2fea804..00000000000 --- a/spec/frontend/snippet/snippet_bundle_spec.js +++ /dev/null @@ -1,87 +0,0 @@ -import { setHTMLFixture } from 'helpers/fixtures'; -import Editor from '~/editor/editor_lite'; -import initEditor from '~/snippet/snippet_bundle'; - -jest.mock('~/editor/editor_lite', () => jest.fn()); - -describe('Snippet editor', () => { - let editorEl; - let contentEl; - let fileNameEl; - let form; - - const mockName = 'foo.bar'; - const mockContent = 'Foo Bar'; - const updatedMockContent = 'New Foo Bar'; - - const mockEditor = { - updateModelLanguage: jest.fn(), - getValue: jest.fn().mockReturnValueOnce(updatedMockContent), - }; - const createInstance = jest.fn().mockImplementation(() => ({ ...mockEditor })); - Editor.mockImplementation(() => ({ - createInstance, - })); - - function setUpFixture(name, content) { - setHTMLFixture(` - <div class="snippet-form-holder"> - <form> - <input class="js-snippet-file-name" type="text" value="${name}"> - <input class="snippet-file-content" type="hidden" value="${content}"> - <pre id="editor"></pre> - </form> - </div> - `); - } - - function bootstrap(name = '', content = '') { - setUpFixture(name, content); - editorEl = document.getElementById('editor'); - contentEl = document.querySelector('.snippet-file-content'); - fileNameEl = document.querySelector('.js-snippet-file-name'); - form = document.querySelector('.snippet-form-holder form'); - - initEditor(); - } - - function createEvent(name) { - return new Event(name, { - view: window, - bubbles: true, - cancelable: true, - }); - } - - beforeEach(() => { - bootstrap(mockName, mockContent); - }); - - it('correctly initializes Editor', () => { - expect(createInstance).toHaveBeenCalledWith({ - el: editorEl, - blobPath: mockName, - blobContent: mockContent, - }); - }); - - it('listens to file name changes and updates syntax highlighting of code', () => { - expect(mockEditor.updateModelLanguage).not.toHaveBeenCalled(); - - const event = createEvent('change'); - - fileNameEl.value = updatedMockContent; - fileNameEl.dispatchEvent(event); - - expect(mockEditor.updateModelLanguage).toHaveBeenCalledWith(updatedMockContent); - }); - - it('listens to form submit event and populates the hidden field with most recent version of the content', () => { - expect(contentEl.value).toBe(mockContent); - - const event = createEvent('submit'); - - form.dispatchEvent(event); - expect(contentEl.value).toBe(updatedMockContent); - }); -}); diff --git a/spec/frontend/snippet/snippet_edit_spec.js b/spec/frontend/snippet/snippet_edit_spec.js deleted file mode 100644 index 7c12c0cac03..00000000000 --- a/spec/frontend/snippet/snippet_edit_spec.js +++ /dev/null @@ -1,44 +0,0 @@ -import '~/snippet/snippet_edit'; -import { triggerDOMEvent } from 'jest/helpers/dom_events_helper'; -import { SnippetEditInit } from '~/snippets'; -import initSnippet from '~/snippet/snippet_bundle'; - -jest.mock('~/snippet/snippet_bundle'); -jest.mock('~/snippets'); - -describe('Snippet edit form initialization', () => { - const setFF = flag => { - gon.features = { snippetsEditVue: flag }; - }; - let features; - - beforeEach(() => { - features = gon.features; - setFixtures('<div class="snippet-form"></div>'); - }); - - afterEach(() => { - gon.features = features; - }); - - it.each` - name | flag | isVue - ${'Regular'} | ${false} | ${false} - ${'Vue'} | ${true} | ${true} - `('correctly initializes $name Snippet Edit form', ({ flag, isVue }) => { - initSnippet.mockClear(); - SnippetEditInit.mockClear(); - - setFF(flag); - - triggerDOMEvent('DOMContentLoaded'); - - if (isVue) { - expect(initSnippet).not.toHaveBeenCalled(); - expect(SnippetEditInit).toHaveBeenCalled(); - } else { - expect(initSnippet).toHaveBeenCalled(); - expect(SnippetEditInit).not.toHaveBeenCalled(); - } - }); -}); |