summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/rich_content_editor/services/renderers/render_identifier_paragraph_spec.js
blob: f4a06b91a10983ee6d7a5a4176e6d48ee0371b54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import renderer from '~/vue_shared/components/rich_content_editor/services/renderers/render_identifier_paragraph';
import { renderUneditableBranch } from '~/vue_shared/components/rich_content_editor/services/renderers/render_utils';

import { buildMockTextNode } from './mock_data';

const buildMockParagraphNode = literal => {
  return {
    firstChild: buildMockTextNode(literal),
    type: 'paragraph',
  };
};

const normalParagraphNode = buildMockParagraphNode(
  'This is just normal paragraph. It has multiple sentences.',
);
const identifierParagraphNode = buildMockParagraphNode(
  `[another-identifier]: https://example.com "This example has a title" [identifier]: http://example1.com [this link]: http://example2.com`,
);

describe('Render Identifier Paragraph renderer', () => {
  describe('canRender', () => {
    it.each`
      node                       | paragraph                                          | target
      ${identifierParagraphNode} | ${'[Some text]: https://link.com'}                 | ${true}
      ${normalParagraphNode}     | ${'Normal non-identifier text. Another sentence.'} | ${false}
    `(
      'should return $target when the $node matches $paragraph syntax',
      ({ node, paragraph, target }) => {
        const context = {
          entering: true,
          getChildrenText: jest.fn().mockReturnValueOnce(paragraph),
        };

        expect(renderer.canRender(node, context)).toBe(target);
      },
    );
  });

  describe('render', () => {
    it('should delegate rendering to the renderUneditableBranch util', () => {
      expect(renderer.render).toBe(renderUneditableBranch);
    });
  });
});