diff options
Diffstat (limited to 'spec/frontend/blob_edit/edit_blob_spec.js')
-rw-r--r-- | spec/frontend/blob_edit/edit_blob_spec.js | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/spec/frontend/blob_edit/edit_blob_spec.js b/spec/frontend/blob_edit/edit_blob_spec.js index ebef0656750..9c974e79e6e 100644 --- a/spec/frontend/blob_edit/edit_blob_spec.js +++ b/spec/frontend/blob_edit/edit_blob_spec.js @@ -1,14 +1,29 @@ import waitForPromises from 'helpers/wait_for_promises'; import EditBlob from '~/blob_edit/edit_blob'; +import { SourceEditorExtension } from '~/editor/extensions/source_editor_extension_base'; import { FileTemplateExtension } from '~/editor/extensions/source_editor_file_template_ext'; import { EditorMarkdownExtension } from '~/editor/extensions/source_editor_markdown_ext'; +import { EditorMarkdownPreviewExtension } from '~/editor/extensions/source_editor_markdown_livepreview_ext'; import SourceEditor from '~/editor/source_editor'; jest.mock('~/editor/source_editor'); -jest.mock('~/editor/extensions/source_editor_markdown_ext'); +jest.mock('~/editor/extensions/source_editor_extension_base'); jest.mock('~/editor/extensions/source_editor_file_template_ext'); +jest.mock('~/editor/extensions/source_editor_markdown_ext'); +jest.mock('~/editor/extensions/source_editor_markdown_livepreview_ext'); const PREVIEW_MARKDOWN_PATH = '/foo/bar/preview_markdown'; +const defaultExtensions = [ + { definition: SourceEditorExtension }, + { definition: FileTemplateExtension }, +]; +const markdownExtensions = [ + { definition: EditorMarkdownExtension }, + { + definition: EditorMarkdownPreviewExtension, + setupOptions: { previewMarkdownPath: PREVIEW_MARKDOWN_PATH }, + }, +]; describe('Blob Editing', () => { const useMock = jest.fn(); @@ -29,7 +44,9 @@ describe('Blob Editing', () => { jest.spyOn(SourceEditor.prototype, 'createInstance').mockReturnValue(mockInstance); }); afterEach(() => { + SourceEditorExtension.mockClear(); EditorMarkdownExtension.mockClear(); + EditorMarkdownPreviewExtension.mockClear(); FileTemplateExtension.mockClear(); }); @@ -45,26 +62,22 @@ describe('Blob Editing', () => { await waitForPromises(); }; - it('loads FileTemplateExtension by default', async () => { + it('loads SourceEditorExtension and FileTemplateExtension by default', async () => { await initEditor(); - expect(useMock).toHaveBeenCalledWith(expect.any(FileTemplateExtension)); - expect(FileTemplateExtension).toHaveBeenCalledTimes(1); + expect(useMock).toHaveBeenCalledWith(defaultExtensions); }); describe('Markdown', () => { - it('does not load MarkdownExtension by default', async () => { + it('does not load MarkdownExtensions by default', async () => { await initEditor(); expect(EditorMarkdownExtension).not.toHaveBeenCalled(); + expect(EditorMarkdownPreviewExtension).not.toHaveBeenCalled(); }); it('loads MarkdownExtension only for the markdown files', async () => { await initEditor(true); - expect(useMock).toHaveBeenCalledWith(expect.any(EditorMarkdownExtension)); - expect(EditorMarkdownExtension).toHaveBeenCalledTimes(1); - expect(EditorMarkdownExtension).toHaveBeenCalledWith({ - instance: mockInstance, - previewMarkdownPath: PREVIEW_MARKDOWN_PATH, - }); + expect(useMock).toHaveBeenCalledTimes(2); + expect(useMock.mock.calls[1]).toEqual([markdownExtensions]); }); }); |