diff options
Diffstat (limited to 'spec/frontend/content_editor/services/markdown_serializer_spec.js')
-rw-r--r-- | spec/frontend/content_editor/services/markdown_serializer_spec.js | 86 |
1 files changed, 54 insertions, 32 deletions
diff --git a/spec/frontend/content_editor/services/markdown_serializer_spec.js b/spec/frontend/content_editor/services/markdown_serializer_spec.js index 25b7483f234..13e9efaea59 100644 --- a/spec/frontend/content_editor/services/markdown_serializer_spec.js +++ b/spec/frontend/content_editor/services/markdown_serializer_spec.js @@ -13,7 +13,6 @@ import Figure from '~/content_editor/extensions/figure'; import FigureCaption from '~/content_editor/extensions/figure_caption'; import FootnoteDefinition from '~/content_editor/extensions/footnote_definition'; import FootnoteReference from '~/content_editor/extensions/footnote_reference'; -import FootnotesSection from '~/content_editor/extensions/footnotes_section'; import HardBreak from '~/content_editor/extensions/hard_break'; import Heading from '~/content_editor/extensions/heading'; import HorizontalRule from '~/content_editor/extensions/horizontal_rule'; @@ -53,7 +52,6 @@ const tiptapEditor = createTestEditor({ Emoji, FootnoteDefinition, FootnoteReference, - FootnotesSection, Figure, FigureCaption, HardBreak, @@ -92,7 +90,6 @@ const { emoji, footnoteDefinition, footnoteReference, - footnotesSection, figure, figureCaption, heading, @@ -131,7 +128,6 @@ const { figureCaption: { nodeType: FigureCaption.name }, footnoteDefinition: { nodeType: FootnoteDefinition.name }, footnoteReference: { nodeType: FootnoteReference.name }, - footnotesSection: { nodeType: FootnotesSection.name }, hardBreak: { nodeType: HardBreak.name }, heading: { nodeType: Heading.name }, horizontalRule: { nodeType: HorizontalRule.name }, @@ -200,7 +196,7 @@ describe('markdownSerializer', () => { it('correctly serializes a plain URL link', () => { expect(serialize(paragraph(link({ href: 'https://example.com' }, 'https://example.com')))).toBe( - '<https://example.com>', + 'https://example.com', ); }); @@ -1147,49 +1143,75 @@ there it('correctly serializes footnotes', () => { expect( serialize( - paragraph( - 'Oranges are orange ', - footnoteReference({ footnoteId: '1', footnoteNumber: '1' }), - ), - footnotesSection(footnoteDefinition(paragraph('Oranges are fruits'))), + paragraph('Oranges are orange ', footnoteReference({ label: '1', identifier: '1' })), + footnoteDefinition({ label: '1', identifier: '1' }, 'Oranges are fruits'), ), ).toBe( ` Oranges are orange [^1] [^1]: Oranges are fruits - `.trim(), +`.trimLeft(), ); }); + const defaultEditAction = (initialContent) => { + tiptapEditor.chain().setContent(initialContent.toJSON()).insertContent(' modified').run(); + }; + + const prependContentEditAction = (initialContent) => { + tiptapEditor + .chain() + .setContent(initialContent.toJSON()) + .setTextSelection(0) + .insertContent('modified ') + .run(); + }; + it.each` - mark | content | modifiedContent - ${'bold'} | ${'**bold**'} | ${'**bold modified**'} - ${'bold'} | ${'__bold__'} | ${'__bold modified__'} - ${'bold'} | ${'<strong>bold</strong>'} | ${'<strong>bold modified</strong>'} - ${'bold'} | ${'<b>bold</b>'} | ${'<b>bold modified</b>'} - ${'italic'} | ${'_italic_'} | ${'_italic modified_'} - ${'italic'} | ${'*italic*'} | ${'*italic modified*'} - ${'italic'} | ${'<em>italic</em>'} | ${'<em>italic modified</em>'} - ${'italic'} | ${'<i>italic</i>'} | ${'<i>italic modified</i>'} - ${'link'} | ${'[gitlab](https://gitlab.com)'} | ${'[gitlab modified](https://gitlab.com)'} - ${'link'} | ${'<a href="https://gitlab.com">link</a>'} | ${'<a href="https://gitlab.com">link modified</a>'} - ${'code'} | ${'`code`'} | ${'`code modified`'} - ${'code'} | ${'<code>code</code>'} | ${'<code>code modified</code>'} + mark | content | modifiedContent | editAction + ${'bold'} | ${'**bold**'} | ${'**bold modified**'} | ${defaultEditAction} + ${'bold'} | ${'__bold__'} | ${'__bold modified__'} | ${defaultEditAction} + ${'bold'} | ${'<strong>bold</strong>'} | ${'<strong>bold modified</strong>'} | ${defaultEditAction} + ${'bold'} | ${'<b>bold</b>'} | ${'<b>bold modified</b>'} | ${defaultEditAction} + ${'italic'} | ${'_italic_'} | ${'_italic modified_'} | ${defaultEditAction} + ${'italic'} | ${'*italic*'} | ${'*italic modified*'} | ${defaultEditAction} + ${'italic'} | ${'<em>italic</em>'} | ${'<em>italic modified</em>'} | ${defaultEditAction} + ${'italic'} | ${'<i>italic</i>'} | ${'<i>italic modified</i>'} | ${defaultEditAction} + ${'link'} | ${'[gitlab](https://gitlab.com)'} | ${'[gitlab modified](https://gitlab.com)'} | ${defaultEditAction} + ${'link'} | ${'<a href="https://gitlab.com">link</a>'} | ${'<a href="https://gitlab.com">link modified</a>'} | ${defaultEditAction} + ${'link'} | ${'link www.gitlab.com'} | ${'modified link www.gitlab.com'} | ${prependContentEditAction} + ${'link'} | ${'link https://www.gitlab.com'} | ${'modified link https://www.gitlab.com'} | ${prependContentEditAction} + ${'link'} | ${'link(https://www.gitlab.com)'} | ${'modified link(https://www.gitlab.com)'} | ${prependContentEditAction} + ${'link'} | ${'link(engineering@gitlab.com)'} | ${'modified link(engineering@gitlab.com)'} | ${prependContentEditAction} + ${'link'} | ${'link <https://www.gitlab.com>'} | ${'modified link <https://www.gitlab.com>'} | ${prependContentEditAction} + ${'link'} | ${'link [https://www.gitlab.com>'} | ${'modified link \\[https://www.gitlab.com>'} | ${prependContentEditAction} + ${'link'} | ${'link <https://www.gitlab.com'} | ${'modified link <https://www.gitlab.com'} | ${prependContentEditAction} + ${'link'} | ${'link https://www.gitlab.com>'} | ${'modified link https://www.gitlab.com>'} | ${prependContentEditAction} + ${'link'} | ${'link **https://www.gitlab.com]**'} | ${'modified link [**https://www.gitlab.com\\]**](https://www.gitlab.com%5D)'} | ${prependContentEditAction} + ${'code'} | ${'`code`'} | ${'`code modified`'} | ${defaultEditAction} + ${'code'} | ${'<code>code</code>'} | ${'<code>code modified</code>'} | ${defaultEditAction} + ${'strike'} | ${'~~striked~~'} | ${'~~striked modified~~'} | ${defaultEditAction} + ${'strike'} | ${'<del>striked</del>'} | ${'<del>striked modified</del>'} | ${defaultEditAction} + ${'strike'} | ${'<strike>striked</strike>'} | ${'<strike>striked modified</strike>'} | ${defaultEditAction} + ${'strike'} | ${'<s>striked</s>'} | ${'<s>striked modified</s>'} | ${defaultEditAction} + ${'list'} | ${'- list item'} | ${'- list item modified'} | ${defaultEditAction} + ${'list'} | ${'* list item'} | ${'* list item modified'} | ${defaultEditAction} + ${'list'} | ${'+ list item'} | ${'+ list item modified'} | ${defaultEditAction} + ${'list'} | ${'- list item 1\n- list item 2'} | ${'- list item 1\n- list item 2 modified'} | ${defaultEditAction} + ${'list'} | ${'2) list item'} | ${'2) list item modified'} | ${defaultEditAction} + ${'list'} | ${'1. list item'} | ${'1. list item modified'} | ${defaultEditAction} + ${'taskList'} | ${'2) [ ] task list item'} | ${'2) [ ] task list item modified'} | ${defaultEditAction} + ${'taskList'} | ${'2) [x] task list item'} | ${'2) [x] task list item modified'} | ${defaultEditAction} `( - 'preserves original $mark syntax when sourceMarkdown is available', - async ({ content, modifiedContent }) => { + 'preserves original $mark syntax when sourceMarkdown is available for $content', + async ({ content, modifiedContent, editAction }) => { const { document } = await remarkMarkdownDeserializer().deserialize({ schema: tiptapEditor.schema, content, }); - tiptapEditor - .chain() - .setContent(document.toJSON()) - // changing the document ensures that block preservation doesn’t yield false positives - .insertContent(' modified') - .run(); + editAction(document); const serialized = markdownSerializer({}).serialize({ pristineDoc: document, |