-
-
Notifications
You must be signed in to change notification settings - Fork 8k
/
normalization.test.ts
120 lines (113 loc) · 3.68 KB
/
normalization.test.ts
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {normalizeSidebars} from '../normalization';
describe('normalization', () => {
it('normalizes shorthands', () => {
expect(
normalizeSidebars({
sidebar: {
Category: ['doc1', 'doc2'],
'Category 2': {
'Subcategory 1': ['doc3', 'doc4'],
'Subcategory 2': ['doc5', 'doc6'],
},
},
}),
).toMatchSnapshot();
expect(
normalizeSidebars({
sidebar: [
{
type: 'link',
label: 'Google',
href: 'https://google.com',
},
{
'Category 1': ['doc1', 'doc2'],
'Category 2': ['doc3', 'doc4'],
},
],
}),
).toMatchSnapshot();
});
it('rejects some invalid cases', () => {
expect(() =>
normalizeSidebars({
sidebar: {
// @ts-expect-error: test
Category: {type: 'autogenerated', dirName: 'foo'},
// @ts-expect-error: test
Category2: {type: 'autogenerated', dirName: 'bar'},
},
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`{"type":"autogenerated","dirName":"foo"}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
expect(() =>
normalizeSidebars({
sidebar: [
'foo',
{
Category: {
// @ts-expect-error: test
type: 'category',
items: ['bar', 'baz'],
},
},
],
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`{"type":"category","items":["bar","baz"]}\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
expect(() =>
normalizeSidebars({
sidebar: [
'foo',
{
// @ts-expect-error: test
Category: 'bar',
},
],
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`"bar"\` in \`items\` of the category Category: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
expect(() =>
normalizeSidebars({
// @ts-expect-error: test
sidebar: 'item',
}),
).toThrowErrorMatchingInlineSnapshot(
`"Invalid sidebar items collection \`"item"\` in sidebar sidebar: it must either be an array of sidebar items or a shorthand notation (which doesn't contain a \`type\` property). See https://docusaurus.io/docs/sidebar/items for all valid syntaxes."`,
);
});
it('adds a translatable marker for labels defined in sidebars.js', () => {
expect(
normalizeSidebars({
sidebar: [
{
type: 'doc',
id: 'google',
label: 'Google',
},
{
'Category 1': ['doc1', 'doc2'],
'Category 2': [
'doc3',
'doc4',
{
type: 'ref',
id: 'msft',
label: 'Microsoft',
},
],
},
],
}),
).toMatchSnapshot();
});
});