diff options
Diffstat (limited to 'spec/frontend/blob')
-rw-r--r-- | spec/frontend/blob/blob_file_dropzone_spec.js | 7 | ||||
-rw-r--r-- | spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap | 2 | ||||
-rw-r--r-- | spec/frontend/blob/components/table_contents_spec.js | 4 | ||||
-rw-r--r-- | spec/frontend/blob/file_template_mediator_spec.js | 7 | ||||
-rw-r--r-- | spec/frontend/blob/file_template_selector_spec.js | 29 | ||||
-rw-r--r-- | spec/frontend/blob/line_highlighter_spec.js | 8 | ||||
-rw-r--r-- | spec/frontend/blob/openapi/index_spec.js | 28 | ||||
-rw-r--r-- | spec/frontend/blob/pipeline_tour_success_modal_spec.js | 2 | ||||
-rw-r--r-- | spec/frontend/blob/sketch/index_spec.js | 50 | ||||
-rw-r--r-- | spec/frontend/blob/viewer/index_spec.js | 5 |
10 files changed, 97 insertions, 45 deletions
diff --git a/spec/frontend/blob/blob_file_dropzone_spec.js b/spec/frontend/blob/blob_file_dropzone_spec.js index 47c90030e18..d6fc824258b 100644 --- a/spec/frontend/blob/blob_file_dropzone_spec.js +++ b/spec/frontend/blob/blob_file_dropzone_spec.js @@ -1,4 +1,5 @@ import $ from 'jquery'; +import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import BlobFileDropzone from '~/blob/blob_file_dropzone'; describe('BlobFileDropzone', () => { @@ -6,7 +7,7 @@ describe('BlobFileDropzone', () => { let replaceFileButton; beforeEach(() => { - loadFixtures('blob/show.html'); + loadHTMLFixture('blob/show.html'); const form = $('.js-upload-blob-form'); // eslint-disable-next-line no-new new BlobFileDropzone(form, 'POST'); @@ -15,6 +16,10 @@ describe('BlobFileDropzone', () => { replaceFileButton = $('#submit-all'); }); + afterEach(() => { + resetHTMLFixture(); + }); + describe('submit button', () => { it('requires file', () => { jest.spyOn(window, 'alert').mockImplementation(() => {}); diff --git a/spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap b/spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap index 5926836d9c1..b430dc15557 100644 --- a/spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap +++ b/spec/frontend/blob/components/__snapshots__/blob_header_spec.js.snap @@ -18,7 +18,7 @@ exports[`Blob Header Default Actions rendering matches the snapshot 1`] = ` </div> <div - class="gl-sm-display-flex file-actions" + class="gl-display-flex gl-flex-wrap file-actions" > <viewer-switcher-stub docicon="document" diff --git a/spec/frontend/blob/components/table_contents_spec.js b/spec/frontend/blob/components/table_contents_spec.js index ade35d39b4f..358ac31819c 100644 --- a/spec/frontend/blob/components/table_contents_spec.js +++ b/spec/frontend/blob/components/table_contents_spec.js @@ -1,6 +1,7 @@ import { GlDropdownItem } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import { nextTick } from 'vue'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import TableContents from '~/blob/components/table_contents.vue'; let wrapper; @@ -17,7 +18,7 @@ async function setLoaded(loaded) { describe('Markdown table of contents component', () => { beforeEach(() => { - setFixtures(` + setHTMLFixture(` <div class="blob-viewer" data-type="rich" data-loaded="false"> <h1><a href="#1"></a>Hello</h1> <h2><a href="#2"></a>World</h2> @@ -29,6 +30,7 @@ describe('Markdown table of contents component', () => { afterEach(() => { wrapper.destroy(); + resetHTMLFixture(); }); describe('not loaded', () => { diff --git a/spec/frontend/blob/file_template_mediator_spec.js b/spec/frontend/blob/file_template_mediator_spec.js index 44e12deb564..907a3c97799 100644 --- a/spec/frontend/blob/file_template_mediator_spec.js +++ b/spec/frontend/blob/file_template_mediator_spec.js @@ -1,3 +1,4 @@ +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import TemplateSelectorMediator from '~/blob/file_template_mediator'; describe('Template Selector Mediator', () => { @@ -11,7 +12,7 @@ describe('Template Selector Mediator', () => { }))(); beforeEach(() => { - setFixtures('<div class="file-editor"><input class="js-file-path-name-input" /></div>'); + setHTMLFixture('<div class="file-editor"><input class="js-file-path-name-input" /></div>'); input = document.querySelector('.js-file-path-name-input'); mediator = new TemplateSelectorMediator({ editor, @@ -20,6 +21,10 @@ describe('Template Selector Mediator', () => { }); }); + afterEach(() => { + resetHTMLFixture(); + }); + it('fills out the input field', () => { expect(input.value).toBe(''); mediator.setFilename(newFileName); diff --git a/spec/frontend/blob/file_template_selector_spec.js b/spec/frontend/blob/file_template_selector_spec.js index 2ab3b3ebc82..65444e86efd 100644 --- a/spec/frontend/blob/file_template_selector_spec.js +++ b/spec/frontend/blob/file_template_selector_spec.js @@ -1,10 +1,11 @@ -import $ from 'jquery'; import FileTemplateSelector from '~/blob/file_template_selector'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; describe('FileTemplateSelector', () => { let subject; - let dropdown; - let wrapper; + + const dropdown = '.dropdown'; + const wrapper = '.wrapper'; const createSubject = () => { subject = new FileTemplateSelector({}); @@ -17,13 +18,16 @@ describe('FileTemplateSelector', () => { afterEach(() => { subject = null; + resetHTMLFixture(); }); describe('show method', () => { beforeEach(() => { - dropdown = document.createElement('div'); - wrapper = document.createElement('div'); - wrapper.classList.add('hidden'); + setHTMLFixture(` + <div class="wrapper hidden"> + <div class="dropdown"></div> + </div> + `); createSubject(); }); @@ -37,25 +41,24 @@ describe('FileTemplateSelector', () => { it('does not call init on subsequent calls', () => { jest.spyOn(subject, 'init'); subject.show(); - subject.show(); expect(subject.init).toHaveBeenCalledTimes(1); }); - it('removes hidden class from $wrapper', () => { - expect($(wrapper).hasClass('hidden')).toBe(true); + it('removes hidden class from wrapper', () => { + subject.init(); + expect(subject.wrapper.classList.contains('hidden')).toBe(true); subject.show(); - - expect($(wrapper).hasClass('hidden')).toBe(false); + expect(subject.wrapper.classList.contains('hidden')).toBe(false); }); it('sets the focus on the dropdown', async () => { subject.show(); - jest.spyOn(subject.$dropdown, 'focus'); + jest.spyOn(subject.dropdown, 'focus'); jest.runAllTimers(); - expect(subject.$dropdown.focus).toHaveBeenCalled(); + expect(subject.dropdown.focus).toHaveBeenCalled(); }); }); }); diff --git a/spec/frontend/blob/line_highlighter_spec.js b/spec/frontend/blob/line_highlighter_spec.js index 330f1f3137e..21d4e8db503 100644 --- a/spec/frontend/blob/line_highlighter_spec.js +++ b/spec/frontend/blob/line_highlighter_spec.js @@ -1,6 +1,7 @@ /* eslint-disable no-return-assign, no-new, no-underscore-dangle */ import $ from 'jquery'; +import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import LineHighlighter from '~/blob/line_highlighter'; import * as utils from '~/lib/utils/common_utils'; @@ -14,8 +15,9 @@ describe('LineHighlighter', () => { const e = $.Event('click', eventData); return $(`#L${number}`).trigger(e); }; + beforeEach(() => { - loadFixtures('static/line_highlighter.html'); + loadHTMLFixture('static/line_highlighter.html'); testContext.class = new LineHighlighter(); testContext.css = testContext.class.highlightLineClass; return (testContext.spies = { @@ -25,6 +27,10 @@ describe('LineHighlighter', () => { }); }); + afterEach(() => { + resetHTMLFixture(); + }); + describe('behavior', () => { it('highlights one line given in the URL hash', () => { new LineHighlighter({ hash: '#L13' }); diff --git a/spec/frontend/blob/openapi/index_spec.js b/spec/frontend/blob/openapi/index_spec.js new file mode 100644 index 00000000000..53220809f80 --- /dev/null +++ b/spec/frontend/blob/openapi/index_spec.js @@ -0,0 +1,28 @@ +import { SwaggerUIBundle } from 'swagger-ui-dist'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import renderOpenApi from '~/blob/openapi'; + +jest.mock('swagger-ui-dist'); + +describe('OpenAPI blob viewer', () => { + const id = 'js-openapi-viewer'; + const mockEndpoint = 'some/endpoint'; + + beforeEach(() => { + setHTMLFixture(`<div id="${id}" data-endpoint="${mockEndpoint}"></div>`); + renderOpenApi(); + }); + + afterEach(() => { + resetHTMLFixture(); + }); + + it('initializes SwaggerUI with the correct configuration', () => { + expect(SwaggerUIBundle).toHaveBeenCalledWith({ + url: mockEndpoint, + dom_id: `#${id}`, + deepLinking: true, + displayOperationId: true, + }); + }); +}); diff --git a/spec/frontend/blob/pipeline_tour_success_modal_spec.js b/spec/frontend/blob/pipeline_tour_success_modal_spec.js index f4af57de41f..750dd8f0a72 100644 --- a/spec/frontend/blob/pipeline_tour_success_modal_spec.js +++ b/spec/frontend/blob/pipeline_tour_success_modal_spec.js @@ -1,6 +1,6 @@ import { GlSprintf, GlModal, GlLink } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; -import Cookies from 'js-cookie'; +import Cookies from '~/lib/utils/cookies'; import { stubComponent } from 'helpers/stub_component'; import { mockTracking, triggerEvent, unmockTracking } from 'helpers/tracking_helper'; import pipelineTourSuccess from '~/blob/pipeline_tour_success_modal.vue'; diff --git a/spec/frontend/blob/sketch/index_spec.js b/spec/frontend/blob/sketch/index_spec.js index 7424897b22c..5e1922a24f4 100644 --- a/spec/frontend/blob/sketch/index_spec.js +++ b/spec/frontend/blob/sketch/index_spec.js @@ -1,20 +1,34 @@ -import JSZip from 'jszip'; import SketchLoader from '~/blob/sketch'; - -jest.mock('jszip'); +import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import waitForPromises from 'helpers/wait_for_promises'; + +jest.mock('jszip', () => { + return { + loadAsync: jest.fn().mockResolvedValue({ + files: { + 'previews/preview.png': { + async: jest.fn().mockResolvedValue('foo'), + }, + }, + }), + }; +}); describe('Sketch viewer', () => { beforeEach(() => { - loadFixtures('static/sketch_viewer.html'); + loadHTMLFixture('static/sketch_viewer.html'); + }); + + afterEach(() => { + resetHTMLFixture(); }); describe('with error message', () => { - beforeEach((done) => { + beforeEach(() => { jest.spyOn(SketchLoader.prototype, 'getZipFile').mockImplementation( () => new Promise((resolve, reject) => { reject(); - done(); }), ); @@ -35,26 +49,12 @@ describe('Sketch viewer', () => { }); describe('success', () => { - beforeEach((done) => { - const loadAsyncMock = { - files: { - 'previews/preview.png': { - async: jest.fn(), - }, - }, - }; - - loadAsyncMock.files['previews/preview.png'].async.mockImplementation( - () => - new Promise((resolve) => { - resolve('foo'); - done(); - }), - ); - + beforeEach(() => { jest.spyOn(SketchLoader.prototype, 'getZipFile').mockResolvedValue(); - jest.spyOn(JSZip, 'loadAsync').mockResolvedValue(loadAsyncMock); - return new SketchLoader(document.getElementById('js-sketch-viewer')); + // eslint-disable-next-line no-new + new SketchLoader(document.getElementById('js-sketch-viewer')); + + return waitForPromises(); }); it('does not render error message', () => { diff --git a/spec/frontend/blob/viewer/index_spec.js b/spec/frontend/blob/viewer/index_spec.js index fe55a537b89..5f6baf3f63d 100644 --- a/spec/frontend/blob/viewer/index_spec.js +++ b/spec/frontend/blob/viewer/index_spec.js @@ -2,6 +2,7 @@ import MockAdapter from 'axios-mock-adapter'; import $ from 'jquery'; +import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import { setTestTimeout } from 'helpers/timeout'; import { BlobViewer } from '~/blob/viewer/index'; import axios from '~/lib/utils/axios_utils'; @@ -26,7 +27,7 @@ describe('Blob viewer', () => { $.fn.extend(jQueryMock); mock = new MockAdapter(axios); - loadFixtures('blob/show_readme.html'); + loadHTMLFixture('blob/show_readme.html'); $('#modal-upload-blob').remove(); mock.onGet(/blob\/.+\/README\.md/).reply(200, { @@ -39,6 +40,8 @@ describe('Blob viewer', () => { afterEach(() => { mock.restore(); window.location.hash = ''; + + resetHTMLFixture(); }); it('loads source file after switching views', async () => { |