import Editor from '@toast-ui/editor'; import { registerHTMLToMarkdownRenderer } from '~/vue_shared/components/rich_content_editor/services/editor_service'; import buildMarkdownToHTMLRenderer from '~/vue_shared/components/rich_content_editor/services/build_custom_renderer'; describe('vue_shared/components/rich_content_editor', () => { let editor; const buildEditor = () => { editor = new Editor({ el: document.body, customHTMLRenderer: buildMarkdownToHTMLRenderer(), }); registerHTMLToMarkdownRenderer(editor); }; beforeEach(() => { buildEditor(); }); describe('HTML to Markdown', () => { it('uses "-" character list marker in unordered lists', () => { editor.setHtml(''); const markdown = editor.getMarkdown(); expect(markdown).toBe('- List item 1\n- List item 2'); }); it('does not increment the list marker in ordered lists', () => { editor.setHtml('
  1. List item 1
  2. List item 2
'); const markdown = editor.getMarkdown(); expect(markdown).toBe('1. List item 1\n1. List item 2'); }); it('indents lists using four spaces', () => { editor.setHtml(''); const markdown = editor.getMarkdown(); expect(markdown).toBe('- List item 1\n - List item 2'); }); it('uses * for strong and _ for emphasis text', () => { editor.setHtml('strong textemphasis text'); const markdown = editor.getMarkdown(); expect(markdown).toBe('**strong text**_emphasis text_'); }); }); describe('Markdown to HTML', () => { it.each` input | output ${'markdown with _emphasized\ntext_'} | ${'

markdown with emphasized text

\n'} ${'markdown with **strong\ntext**'} | ${'

markdown with strong text

\n'} `( 'does not transform softbreaks inside (_) and strong (**) nodes into
tags', ({ input, output }) => { editor.setMarkdown(input); expect(editor.getHtml()).toBe(output); }, ); }); });