forked from keystonejs/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
84 lines (77 loc) · 3.09 KB
/
Copy pathindex.test.ts
File metadata and controls
84 lines (77 loc) · 3.09 KB
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 React, { ReactNode } from 'react';
import { RenderableTreeNode } from '@markdoc/markdoc';
import { transformDocContent } from '.';
function renderableToReactElement(node: RenderableTreeNode, key = 1): ReactNode {
if (typeof node === 'string' || node === null) {
return node;
}
return React.createElement(
node.name,
{ ...node.attributes, key },
node.children.map((child, i) => renderableToReactElement(child, i))
);
}
expect.addSnapshotSerializer({
test(val) {
return typeof val === 'object' && val !== null && '$$mdtype' in val && val.$$mdtype === 'Tag';
},
serialize(val, config, indentation, depth, refs, printer) {
return printer(renderableToReactElement(val), config, indentation, depth, refs);
},
});
test('duplicate headings without disambiguated ids error', () => {
const content = `## Heading 1
## Heading 1
`;
expect(() => transformDocContent('content.md', content)).toThrowErrorMatchingInlineSnapshot(`
"Errors in content.md:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
content.md:1: The id for this heading is "heading-1" which is the same as another heading in this file, disambiguate them with {% #some-id-here %} after a heading
content.md:2: The id for this heading is "heading-1" which is the same as another heading in this file, disambiguate them with {% #some-id-here %} after a heading
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯"
`);
});
test('duplicate headings with disambiguated ids are allowed', () => {
const content = `## Heading 1
## Heading 1 {% #some-heading %}
`;
expect(transformDocContent('content.md', content)).toMatchInlineSnapshot(`
<article>
<Heading
id="heading-1"
level={2}
>
Heading 1
</Heading>
<Heading
id="some-heading"
level={2}
>
Heading 1
</Heading>
</article>
`);
});
test("h1's are not allowed", () => {
const content = `# Heading 1`;
expect(() => transformDocContent('content.md', content)).toThrowErrorMatchingInlineSnapshot(`
"Errors in content.md:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
content.md:1: H1's are not allowed, specify the title in frontmatter at the top of the file if you're trying to specify the page title, otherwise use a different heading level
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯"
`);
});
test('empty ids on headings are not allowed', () => {
const content = `## ⭐️
###
#### Blah {% id="" %}
`;
expect(() => transformDocContent('content.md', content)).toThrowErrorMatchingInlineSnapshot(`
"Errors in content.md:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
content.md:1: This heading has an empty id, change the heading content so that a non-empty id is generated or add {% #some-id %} after the heading
content.md:2: This heading has an empty id, change the heading content so that a non-empty id is generated or add {% #some-id %} after the heading
content.md:4: This heading has an empty id, change the heading content so that a non-empty id is generated or add {% #some-id %} after the heading
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯"
`);
});