Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/content_editor/services/markdown_serializer_spec.js')
-rw-r--r--spec/frontend/content_editor/services/markdown_serializer_spec.js95
1 files changed, 91 insertions, 4 deletions
diff --git a/spec/frontend/content_editor/services/markdown_serializer_spec.js b/spec/frontend/content_editor/services/markdown_serializer_spec.js
index 4ae39f7a5a7..aeaa63a332f 100644
--- a/spec/frontend/content_editor/services/markdown_serializer_spec.js
+++ b/spec/frontend/content_editor/services/markdown_serializer_spec.js
@@ -138,10 +138,10 @@ const {
},
});
-const serialize = (...content) =>
- new MarkdownSerializer().serialize({
- doc: doc(...content),
- });
+const serializeWithOptions = (options, ...content) =>
+ new MarkdownSerializer().serialize({ doc: doc(...content) }, options);
+
+const serialize = (...content) => new MarkdownSerializer().serialize({ doc: doc(...content) });
describe('markdownSerializer', () => {
it('correctly serializes bold', () => {
@@ -389,6 +389,16 @@ describe('markdownSerializer', () => {
expect(serialize(paragraph(strike('deleted content')))).toBe('~~deleted content~~');
});
+ it.each`
+ strikeTag
+ ${'s'}
+ ${'strike'}
+ `('correctly serializes strikethrough with "$strikeTag" tag', ({ strikeTag }) => {
+ expect(serialize(paragraph(strike({ htmlTag: strikeTag }, 'deleted content')))).toBe(
+ `<${strikeTag}>deleted content</${strikeTag}>`,
+ );
+ });
+
it('correctly serializes blockquotes with hard breaks', () => {
expect(serialize(blockquote('some text', hardBreak(), hardBreak(), 'new line'))).toBe(
`
@@ -411,6 +421,32 @@ describe('markdownSerializer', () => {
);
});
+ it('correctly serializes a blockquote with a nested blockquote', () => {
+ expect(
+ serialize(
+ blockquote(
+ paragraph('some paragraph'),
+ blockquote(paragraph('nested paragraph'), codeBlock('var x = 10;')),
+ ),
+ ),
+ ).toBe(
+ `
+> some paragraph
+>
+> > nested paragraph
+> >
+> > \`\`\`
+> > var x = 10;
+> > \`\`\`
+ `.trim(),
+ );
+ });
+
+ it('skips serializing an empty blockquote if skipEmptyNodes=true', () => {
+ expect(serializeWithOptions({ skipEmptyNodes: true }, blockquote())).toBe('');
+ expect(serializeWithOptions({ skipEmptyNodes: true }, blockquote(paragraph()))).toBe('');
+ });
+
it('correctly serializes a multiline blockquote', () => {
expect(
serialize(
@@ -451,6 +487,23 @@ this is not really json but just trying out whether this case works or not
);
});
+ it('renders a plaintext code block without a prefix', () => {
+ expect(
+ serialize(
+ codeBlock(
+ { language: 'plaintext', langParams: '' },
+ 'this is not really json but just trying out whether this case works or not',
+ ),
+ ),
+ ).toBe(
+ `
+\`\`\`
+this is not really json but just trying out whether this case works or not
+\`\`\`
+ `.trim(),
+ );
+ });
+
it('correctly serializes a code block with language parameters', () => {
expect(
serialize(
@@ -514,6 +567,10 @@ var a = 0;
);
});
+ it('skips serializing an empty code block if skipEmptyNodes=true', () => {
+ expect(serializeWithOptions({ skipEmptyNodes: true }, codeBlock())).toBe('');
+ });
+
it('correctly serializes emoji', () => {
expect(serialize(paragraph(emoji({ name: 'dog' })))).toBe(':dog:');
});
@@ -545,6 +602,20 @@ var a = 0;
);
});
+ it('skips serializing an empty heading if skipEmptyNodes=true', () => {
+ expect(
+ serializeWithOptions(
+ { skipEmptyNodes: true },
+ heading({ level: 1 }),
+ heading({ level: 2 }),
+ heading({ level: 3 }),
+ heading({ level: 4 }),
+ heading({ level: 5 }),
+ heading({ level: 6 }),
+ ),
+ ).toBe('');
+ });
+
it('correctly serializes horizontal rule', () => {
expect(serialize(horizontalRule(), horizontalRule(), horizontalRule())).toBe(
`
@@ -614,6 +685,22 @@ var a = 0;
).toBe('![this is an image](file.png "foo bar baz")');
});
+ it('does not use the canonicalSrc if options.useCanonicalSrc=false', () => {
+ expect(
+ serializeWithOptions(
+ { useCanonicalSrc: false },
+ paragraph(
+ image({
+ src: '/uploads/abcde/file.png',
+ alt: 'this is an image',
+ canonicalSrc: 'file.png',
+ title: 'foo bar baz',
+ }),
+ ),
+ ),
+ ).toBe('![this is an image](/uploads/abcde/file.png "foo bar baz")');
+ });
+
it('correctly serializes bullet list', () => {
expect(
serialize(