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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
import renderer from '~/static_site_editor/rich_content_editor/services/renderers/render_identifier_paragraph';
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('rich_content_editor/renderers_render_identifier_paragraph', () => {
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', () => {
let context;
let result;
beforeEach(() => {
const node = {
firstChild: {
type: 'text',
literal: '[Some text]: https://link.com',
next: {
type: 'linebreak',
next: {
type: 'text',
literal: '[identifier]: http://example1.com "title"',
},
},
},
};
context = { skipChildren: jest.fn() };
result = renderer.render(node, context);
});
it('renders the reference definitions as a code block', () => {
expect(result).toEqual([
{
type: 'openTag',
tagName: 'pre',
classNames: ['code-block', 'language-markdown'],
attributes: {
'data-sse-reference-definition': true,
},
},
{ type: 'openTag', tagName: 'code' },
{
type: 'text',
content: '[Some text]: https://link.com\n[identifier]: http://example1.com "title"',
},
{ type: 'closeTag', tagName: 'code' },
{ type: 'closeTag', tagName: 'pre' },
]);
});
it('skips the reference definition node children from rendering', () => {
expect(context.skipChildren).toHaveBeenCalled();
});
});
});
|