diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-01 07:13:49 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-01 07:13:49 +0000 |
commit | fb58d337f0b8b6f685c1e94a9327d8d12ebfbf81 (patch) | |
tree | a285b8beb8303a81a7af0db968822fa05595e529 /spec/frontend | |
parent | 3333112d46dd179a55295ebed754544a97b49b7f (diff) | |
download | gitlab-ce-fb58d337f0b8b6f685c1e94a9327d8d12ebfbf81.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-ee
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/blob_edit/edit_blob_spec.js | 11 | ||||
-rw-r--r-- | spec/frontend/editor/source_editor_markdown_ext_spec.js | 32 | ||||
-rw-r--r-- | spec/frontend/ide/components/repo_editor_spec.js | 7 |
3 files changed, 25 insertions, 25 deletions
diff --git a/spec/frontend/blob_edit/edit_blob_spec.js b/spec/frontend/blob_edit/edit_blob_spec.js index 2be72ded0a2..ebef0656750 100644 --- a/spec/frontend/blob_edit/edit_blob_spec.js +++ b/spec/frontend/blob_edit/edit_blob_spec.js @@ -8,6 +8,8 @@ jest.mock('~/editor/source_editor'); jest.mock('~/editor/extensions/source_editor_markdown_ext'); jest.mock('~/editor/extensions/source_editor_file_template_ext'); +const PREVIEW_MARKDOWN_PATH = '/foo/bar/preview_markdown'; + describe('Blob Editing', () => { const useMock = jest.fn(); const mockInstance = { @@ -34,6 +36,7 @@ describe('Blob Editing', () => { const editorInst = (isMarkdown) => { return new EditBlob({ isMarkdown, + previewMarkdownPath: PREVIEW_MARKDOWN_PATH, }); }; @@ -44,6 +47,7 @@ describe('Blob Editing', () => { it('loads FileTemplateExtension by default', async () => { await initEditor(); + expect(useMock).toHaveBeenCalledWith(expect.any(FileTemplateExtension)); expect(FileTemplateExtension).toHaveBeenCalledTimes(1); }); @@ -55,9 +59,12 @@ describe('Blob Editing', () => { it('loads MarkdownExtension only for the markdown files', async () => { await initEditor(true); - expect(useMock).toHaveBeenCalledTimes(2); - expect(FileTemplateExtension).toHaveBeenCalledTimes(1); + expect(useMock).toHaveBeenCalledWith(expect.any(EditorMarkdownExtension)); expect(EditorMarkdownExtension).toHaveBeenCalledTimes(1); + expect(EditorMarkdownExtension).toHaveBeenCalledWith({ + instance: mockInstance, + previewMarkdownPath: PREVIEW_MARKDOWN_PATH, + }); }); }); diff --git a/spec/frontend/editor/source_editor_markdown_ext_spec.js b/spec/frontend/editor/source_editor_markdown_ext_spec.js index 48ccc10e486..245c6c28d31 100644 --- a/spec/frontend/editor/source_editor_markdown_ext_spec.js +++ b/spec/frontend/editor/source_editor_markdown_ext_spec.js @@ -23,7 +23,7 @@ describe('Markdown Extension for Source Editor', () => { let editorEl; let panelSpy; let mockAxios; - const projectPath = 'fooGroup/barProj'; + const previewMarkdownPath = '/gitlab/fooGroup/barProj/preview_markdown'; const firstLine = 'This is a'; const secondLine = 'multiline'; const thirdLine = 'string with some **markup**'; @@ -57,7 +57,7 @@ describe('Markdown Extension for Source Editor', () => { blobPath: markdownPath, blobContent: text, }); - editor.use(new EditorMarkdownExtension({ instance, projectPath })); + editor.use(new EditorMarkdownExtension({ instance, previewMarkdownPath })); panelSpy = jest.spyOn(EditorMarkdownExtension, 'togglePreviewPanel'); }); @@ -74,7 +74,7 @@ describe('Markdown Extension for Source Editor', () => { shown: false, modelChangeListener: undefined, }); - expect(instance.projectPath).toBe(projectPath); + expect(instance.previewMarkdownPath).toBe(previewMarkdownPath); }); describe('model language changes listener', () => { @@ -223,34 +223,24 @@ describe('Markdown Extension for Source Editor', () => { }); describe('fetchPreview', () => { - const group = 'foo'; - const project = 'bar'; - const setData = (path, g, p) => { - instance.projectPath = path; - document.body.setAttribute('data-group', g); - document.body.setAttribute('data-project', p); - }; const fetchPreview = async () => { instance.fetchPreview(); await waitForPromises(); }; + let previewMarkdownSpy; + beforeEach(() => { - mockAxios.onPost().reply(200, { body: responseData }); + previewMarkdownSpy = jest.fn().mockImplementation(() => [200, { body: responseData }]); + mockAxios.onPost(previewMarkdownPath).replyOnce((req) => previewMarkdownSpy(req)); }); - it('correctly fetches preview based on projectPath', async () => { - setData(projectPath, group, project); + it('correctly fetches preview based on previewMarkdownPath', async () => { await fetchPreview(); - expect(mockAxios.history.post[0].url).toBe(`/${projectPath}/preview_markdown`); - expect(mockAxios.history.post[0].data).toEqual(JSON.stringify({ text })); - }); - it('correctly fetches preview based on group and project data attributes', async () => { - setData(undefined, group, project); - await fetchPreview(); - expect(mockAxios.history.post[0].url).toBe(`/${group}/${project}/preview_markdown`); - expect(mockAxios.history.post[0].data).toEqual(JSON.stringify({ text })); + expect(previewMarkdownSpy).toHaveBeenCalledWith( + expect.objectContaining({ data: JSON.stringify({ text }) }), + ); }); it('puts the fetched content into the preview DOM element', async () => { diff --git a/spec/frontend/ide/components/repo_editor_spec.js b/spec/frontend/ide/components/repo_editor_spec.js index b2254de706c..47bcfb59a5f 100644 --- a/spec/frontend/ide/components/repo_editor_spec.js +++ b/spec/frontend/ide/components/repo_editor_spec.js @@ -24,6 +24,8 @@ import axios from '~/lib/utils/axios_utils'; import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue'; import { file } from '../helpers'; +const PREVIEW_MARKDOWN_PATH = '/foo/bar/preview_markdown'; + const defaultFileProps = { ...file('file.txt'), content: 'hello world', @@ -77,6 +79,7 @@ const prepareStore = (state, activeFile) => { entries: { [activeFile.path]: activeFile, }, + previewMarkdownPath: PREVIEW_MARKDOWN_PATH, }; const storeOptions = createStoreOptions(); return new Vuex.Store({ @@ -278,10 +281,10 @@ describe('RepoEditor', () => { async ({ activeFile, viewer, shouldHaveMarkdownExtension } = {}) => { await createComponent({ state: { viewer }, activeFile }); if (shouldHaveMarkdownExtension) { - expect(vm.editor.projectPath).toBe(vm.currentProjectId); + expect(vm.editor.previewMarkdownPath).toBe(PREVIEW_MARKDOWN_PATH); expect(vm.editor.togglePreview).toBeDefined(); } else { - expect(vm.editor.projectPath).toBeUndefined(); + expect(vm.editor.previewMarkdownPath).toBeUndefined(); expect(vm.editor.togglePreview).toBeUndefined(); } }, |