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/code_block_highlight_spec.js | |
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/code_block_highlight_spec.js')
-rw-r--r-- | spec/frontend/content_editor/extensions/code_block_highlight_spec.js | 37 |
1 files changed, 37 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'); + }); +}); |