diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/frontend/content_editor/extensions | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/frontend/content_editor/extensions')
-rw-r--r-- | spec/frontend/content_editor/extensions/code_block_highlight_spec.js | 37 | ||||
-rw-r--r-- | spec/frontend/content_editor/extensions/link_spec.js | 61 |
2 files changed, 98 insertions, 0 deletions
diff --git a/spec/frontend/content_editor/extensions/code_block_highlight_spec.js b/spec/frontend/content_editor/extensions/code_block_highlight_spec.js new file mode 100644 index 00000000000..cc695ffe241 --- /dev/null +++ b/spec/frontend/content_editor/extensions/code_block_highlight_spec.js @@ -0,0 +1,37 @@ +import { tiptapExtension as CodeBlockHighlight } from '~/content_editor/extensions/code_block_highlight'; +import { loadMarkdownApiResult } from '../markdown_processing_examples'; +import { createTestEditor } from '../test_utils'; + +describe('content_editor/extensions/code_block_highlight', () => { + let codeBlockHtmlFixture; + let parsedCodeBlockHtmlFixture; + let tiptapEditor; + + const parseHTML = (html) => new DOMParser().parseFromString(html, 'text/html'); + const preElement = () => parsedCodeBlockHtmlFixture.querySelector('pre'); + + beforeEach(() => { + const { html } = loadMarkdownApiResult('code_block'); + + tiptapEditor = createTestEditor({ extensions: [CodeBlockHighlight] }); + codeBlockHtmlFixture = html; + parsedCodeBlockHtmlFixture = parseHTML(codeBlockHtmlFixture); + + tiptapEditor.commands.setContent(codeBlockHtmlFixture); + }); + + it('extracts language and params attributes from Markdown API output', () => { + const language = preElement().getAttribute('lang'); + + expect(tiptapEditor.getJSON().content[0].attrs).toMatchObject({ + language, + params: language, + }); + }); + + it('adds code, highlight, and js-syntax-highlight to code block element', () => { + const editorHtmlOutput = parseHTML(tiptapEditor.getHTML()).querySelector('pre'); + + expect(editorHtmlOutput.classList.toString()).toContain('code highlight js-syntax-highlight'); + }); +}); diff --git a/spec/frontend/content_editor/extensions/link_spec.js b/spec/frontend/content_editor/extensions/link_spec.js new file mode 100644 index 00000000000..026b2a06df3 --- /dev/null +++ b/spec/frontend/content_editor/extensions/link_spec.js @@ -0,0 +1,61 @@ +import { + markdownLinkSyntaxInputRuleRegExp, + urlSyntaxRegExp, + extractHrefFromMarkdownLink, +} from '~/content_editor/extensions/link'; + +describe('content_editor/extensions/link', () => { + describe.each` + input | matches + ${'[gitlab](https://gitlab.com)'} | ${true} + ${'[documentation](readme.md)'} | ${true} + ${'[link 123](readme.md)'} | ${true} + ${'[link 123](read me.md)'} | ${true} + ${'text'} | ${false} + ${'documentation](readme.md'} | ${false} + ${'https://www.google.com'} | ${false} + `('markdownLinkSyntaxInputRuleRegExp', ({ input, matches }) => { + it(`${matches ? 'matches' : 'does not match'} ${input}`, () => { + const match = new RegExp(markdownLinkSyntaxInputRuleRegExp).exec(input); + + expect(Boolean(match?.groups.href)).toBe(matches); + }); + }); + + describe.each` + input | matches + ${'http://example.com '} | ${true} + ${'https://example.com '} | ${true} + ${'www.example.com '} | ${true} + ${'example.com/ab.html '} | ${false} + ${'text'} | ${false} + ${' http://example.com '} | ${true} + ${'https://www.google.com '} | ${true} + `('urlSyntaxRegExp', ({ input, matches }) => { + it(`${matches ? 'matches' : 'does not match'} ${input}`, () => { + const match = new RegExp(urlSyntaxRegExp).exec(input); + + expect(Boolean(match?.groups.href)).toBe(matches); + }); + }); + + describe('extractHrefFromMarkdownLink', () => { + const input = '[gitlab](https://gitlab.com)'; + const href = 'https://gitlab.com'; + let match; + let result; + + beforeEach(() => { + match = new RegExp(markdownLinkSyntaxInputRuleRegExp).exec(input); + result = extractHrefFromMarkdownLink(match); + }); + + it('extracts the url from a markdown link captured by markdownLinkSyntaxInputRuleRegExp', () => { + expect(result).toEqual({ href }); + }); + + it('makes sure that url text is the last capture group', () => { + expect(match[match.length - 1]).toEqual('gitlab'); + }); + }); +}); |