diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/frontend/content_editor/services/create_content_editor_spec.js | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/frontend/content_editor/services/create_content_editor_spec.js')
-rw-r--r-- | spec/frontend/content_editor/services/create_content_editor_spec.js | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/spec/frontend/content_editor/services/create_content_editor_spec.js b/spec/frontend/content_editor/services/create_content_editor_spec.js index 6b2f28b3306..e1a30819ac8 100644 --- a/spec/frontend/content_editor/services/create_content_editor_spec.js +++ b/spec/frontend/content_editor/services/create_content_editor_spec.js @@ -1,8 +1,12 @@ import { PROVIDE_SERIALIZER_OR_RENDERER_ERROR } from '~/content_editor/constants'; import { createContentEditor } from '~/content_editor/services/create_content_editor'; +import createGlApiMarkdownDeserializer from '~/content_editor/services/gl_api_markdown_deserializer'; +import createRemarkMarkdownDeserializer from '~/content_editor/services/remark_markdown_deserializer'; import { createTestContentEditorExtension } from '../test_utils'; jest.mock('~/emoji'); +jest.mock('~/content_editor/services/remark_markdown_deserializer'); +jest.mock('~/content_editor/services/gl_api_markdown_deserializer'); describe('content_editor/services/create_content_editor', () => { let renderMarkdown; @@ -11,9 +15,36 @@ describe('content_editor/services/create_content_editor', () => { beforeEach(() => { renderMarkdown = jest.fn(); + window.gon = { + features: { + preserveUnchangedMarkdown: false, + }, + }; editor = createContentEditor({ renderMarkdown, uploadsPath }); }); + describe('when preserveUnchangedMarkdown feature is on', () => { + beforeEach(() => { + window.gon.features.preserveUnchangedMarkdown = true; + }); + + it('provides a remark markdown deserializer to the content editor class', () => { + createContentEditor({ renderMarkdown, uploadsPath }); + expect(createRemarkMarkdownDeserializer).toHaveBeenCalled(); + }); + }); + + describe('when preserveUnchangedMarkdown feature is off', () => { + beforeEach(() => { + window.gon.features.preserveUnchangedMarkdown = false; + }); + + it('provides a gl api markdown deserializer to the content editor class', () => { + createContentEditor({ renderMarkdown, uploadsPath }); + expect(createGlApiMarkdownDeserializer).toHaveBeenCalledWith({ render: renderMarkdown }); + }); + }); + it('sets gl-outline-0! class selector to the tiptapEditor instance', () => { expect(editor.tiptapEditor.options.editorProps).toMatchObject({ attributes: { @@ -22,30 +53,19 @@ describe('content_editor/services/create_content_editor', () => { }); }); - it('provides the renderMarkdown function to the markdown serializer', async () => { - const serializedContent = '**bold text**'; - - renderMarkdown.mockReturnValueOnce('<p><b>bold text</b></p>'); - - await editor.setSerializedContent(serializedContent); - - expect(renderMarkdown).toHaveBeenCalledWith(serializedContent); - }); - it('allows providing external content editor extensions', async () => { const labelReference = 'this is a ~group::editor'; const { tiptapExtension, serializer } = createTestContentEditorExtension(); - renderMarkdown.mockReturnValueOnce( - '<p>this is a <span data-reference="label" data-label-name="group::editor">group::editor</span></p>', - ); editor = createContentEditor({ renderMarkdown, extensions: [tiptapExtension], serializerConfig: { nodes: { [tiptapExtension.name]: serializer } }, }); - await editor.setSerializedContent(labelReference); + editor.tiptapEditor.commands.setContent( + '<p>this is a <span data-reference="label" data-label-name="group::editor">group::editor</span></p>', + ); expect(editor.getSerializedContent()).toBe(labelReference); }); |