diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/frontend/lib/gfm/index_spec.js | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/frontend/lib/gfm/index_spec.js')
-rw-r--r-- | spec/frontend/lib/gfm/index_spec.js | 90 |
1 files changed, 69 insertions, 21 deletions
diff --git a/spec/frontend/lib/gfm/index_spec.js b/spec/frontend/lib/gfm/index_spec.js index c9a480e9943..7aab0072364 100644 --- a/spec/frontend/lib/gfm/index_spec.js +++ b/spec/frontend/lib/gfm/index_spec.js @@ -1,35 +1,48 @@ import { render } from '~/lib/gfm'; describe('gfm', () => { + const markdownToAST = async (markdown) => { + let result; + + await render({ + markdown, + renderer: (tree) => { + result = tree; + }, + }); + + return result; + }; + + const expectInRoot = (result, ...nodes) => { + expect(result).toEqual( + expect.objectContaining({ + children: expect.arrayContaining(nodes), + }), + ); + }; + describe('render', () => { it('processes Commonmark and provides an ast to the renderer function', async () => { - let result; - - await render({ - markdown: 'This is text', - renderer: (tree) => { - result = tree; - }, - }); + const result = await markdownToAST('This is text'); expect(result.type).toBe('root'); }); it('transforms raw HTML into individual nodes in the AST', async () => { - let result; - - await render({ - markdown: '<strong>This is bold text</strong>', - renderer: (tree) => { - result = tree; - }, - }); + const result = await markdownToAST('<strong>This is bold text</strong>'); - expect(result.children[0].children[0]).toMatchObject({ - type: 'element', - tagName: 'strong', - properties: {}, - }); + expectInRoot( + result, + expect.objectContaining({ + children: expect.arrayContaining([ + expect.objectContaining({ + type: 'element', + tagName: 'strong', + }), + ]), + }), + ); }); it('returns the result of executing the renderer function', async () => { @@ -44,5 +57,40 @@ describe('gfm', () => { expect(result).toEqual(rendered); }); + + it('transforms footnotes into footnotedefinition and footnotereference tags', async () => { + const result = await markdownToAST( + `footnote reference [^footnote] + +[^footnote]: Footnote definition`, + ); + + expectInRoot( + result, + expect.objectContaining({ + children: expect.arrayContaining([ + expect.objectContaining({ + type: 'element', + tagName: 'footnotereference', + properties: { + identifier: 'footnote', + label: 'footnote', + }, + }), + ]), + }), + ); + + expectInRoot( + result, + expect.objectContaining({ + tagName: 'footnotedefinition', + properties: { + identifier: 'footnote', + label: 'footnote', + }, + }), + ); + }); }); }); |