@docusaurus/plugin-content-docs 2.0.0-beta.8bda3b2db → 2.0.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/lib/.tsbuildinfo +1 -1
  2. package/lib/cli.d.ts +2 -2
  3. package/lib/cli.js +20 -24
  4. package/lib/client/docsClientUtils.d.ts +1 -4
  5. package/lib/client/docsClientUtils.js +12 -16
  6. package/lib/docFrontMatter.js +7 -3
  7. package/lib/docs.d.ts +4 -2
  8. package/lib/docs.js +77 -23
  9. package/lib/index.js +88 -94
  10. package/lib/lastUpdate.js +8 -8
  11. package/lib/markdown/index.d.ts +3 -6
  12. package/lib/markdown/index.js +3 -3
  13. package/lib/markdown/linkify.js +2 -2
  14. package/lib/options.d.ts +1 -1
  15. package/lib/options.js +39 -11
  16. package/lib/props.d.ts +7 -2
  17. package/lib/props.js +27 -4
  18. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +3 -1
  19. package/lib/sidebars/generator.js +174 -0
  20. package/lib/sidebars/index.d.ts +14 -0
  21. package/lib/sidebars/index.js +64 -0
  22. package/lib/sidebars/normalization.d.ts +9 -0
  23. package/lib/sidebars/normalization.js +58 -0
  24. package/lib/sidebars/processor.d.ts +16 -0
  25. package/lib/sidebars/processor.js +70 -0
  26. package/lib/sidebars/types.d.ts +87 -0
  27. package/lib/sidebars/types.js +13 -0
  28. package/lib/sidebars/utils.d.ts +22 -0
  29. package/lib/sidebars/utils.js +101 -0
  30. package/lib/sidebars/validation.d.ts +8 -0
  31. package/lib/sidebars/validation.js +102 -0
  32. package/lib/slug.js +4 -4
  33. package/lib/tags.d.ts +8 -0
  34. package/lib/tags.js +22 -0
  35. package/lib/theme/hooks/useDocs.js +24 -21
  36. package/lib/translations.d.ts +1 -1
  37. package/lib/translations.js +13 -13
  38. package/lib/types.d.ts +35 -58
  39. package/lib/versions.d.ts +1 -1
  40. package/lib/versions.js +75 -22
  41. package/package.json +15 -14
  42. package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +3 -0
  43. package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +3 -0
  44. package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +3 -0
  45. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
  46. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +1 -0
  47. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +2 -0
  48. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +2 -0
  49. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +2 -0
  50. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +2 -0
  51. package/src/__tests__/__fixtures__/simple-site/sidebars.json +15 -1
  52. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +6 -0
  53. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +3 -0
  54. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +3 -0
  55. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +3 -0
  56. package/src/__tests__/__snapshots__/cli.test.ts.snap +33 -0
  57. package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
  58. package/src/__tests__/__snapshots__/index.test.ts.snap +478 -60
  59. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -3
  60. package/src/__tests__/cli.test.ts +14 -10
  61. package/src/__tests__/docFrontMatter.test.ts +163 -48
  62. package/src/__tests__/docs.test.ts +167 -21
  63. package/src/__tests__/index.test.ts +74 -30
  64. package/src/__tests__/lastUpdate.test.ts +3 -2
  65. package/src/__tests__/options.test.ts +46 -3
  66. package/src/__tests__/props.test.ts +62 -0
  67. package/src/__tests__/translations.test.ts +0 -1
  68. package/src/__tests__/versions.test.ts +88 -60
  69. package/src/cli.ts +27 -30
  70. package/src/client/__tests__/docsClientUtils.test.ts +4 -5
  71. package/src/client/docsClientUtils.ts +6 -27
  72. package/src/docFrontMatter.ts +8 -3
  73. package/src/docs.ts +92 -9
  74. package/src/index.ts +114 -121
  75. package/src/lastUpdate.ts +10 -6
  76. package/src/markdown/index.ts +8 -12
  77. package/src/numberPrefix.ts +4 -2
  78. package/src/options.ts +47 -17
  79. package/src/plugin-content-docs.d.ts +121 -34
  80. package/src/props.ts +42 -6
  81. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
  82. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
  83. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
  84. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
  85. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
  86. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
  87. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
  88. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
  89. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
  90. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
  91. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
  92. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
  93. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
  94. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
  95. package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +21 -6
  96. package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +29 -7
  97. package/src/sidebars/__tests__/index.test.ts +202 -0
  98. package/src/sidebars/__tests__/processor.test.ts +148 -0
  99. package/src/sidebars/__tests__/utils.test.ts +395 -0
  100. package/src/sidebars/generator.ts +253 -0
  101. package/src/sidebars/index.ts +84 -0
  102. package/src/sidebars/normalization.ts +88 -0
  103. package/src/sidebars/processor.ts +124 -0
  104. package/src/sidebars/types.ts +156 -0
  105. package/src/sidebars/utils.ts +146 -0
  106. package/src/sidebars/validation.ts +124 -0
  107. package/src/tags.ts +21 -0
  108. package/src/theme/hooks/useDocs.ts +5 -1
  109. package/src/translations.ts +26 -36
  110. package/src/types.ts +48 -99
  111. package/src/versions.ts +109 -17
  112. package/lib/sidebarItemsGenerator.js +0 -211
  113. package/lib/sidebars.d.ts +0 -43
  114. package/lib/sidebars.js +0 -319
  115. package/src/__tests__/sidebars.test.ts +0 -639
  116. package/src/sidebarItemsGenerator.ts +0 -307
  117. package/src/sidebars.ts +0 -506
@@ -8,15 +8,14 @@
8
8
  import {
9
9
  CategoryMetadatasFile,
10
10
  DefaultSidebarItemsGenerator,
11
- } from '../sidebarItemsGenerator';
12
- import {DefaultCategoryCollapsedValue} from '../sidebars';
11
+ } from '../generator';
13
12
  import {Sidebar, SidebarItemsGenerator} from '../types';
14
13
  import fs from 'fs-extra';
15
- import {DefaultNumberPrefixParser} from '../numberPrefix';
14
+ import {DefaultNumberPrefixParser} from '../../numberPrefix';
16
15
 
17
16
  describe('DefaultSidebarItemsGenerator', () => {
18
17
  function testDefaultSidebarItemsGenerator(
19
- options: Partial<Parameters<SidebarItemsGenerator>[0]>,
18
+ params: Partial<Parameters<SidebarItemsGenerator>[0]>,
20
19
  ) {
21
20
  return DefaultSidebarItemsGenerator({
22
21
  numberPrefixParser: DefaultNumberPrefixParser,
@@ -29,7 +28,11 @@ describe('DefaultSidebarItemsGenerator', () => {
29
28
  contentPath: 'docs',
30
29
  },
31
30
  docs: [],
32
- ...options,
31
+ options: {
32
+ sidebarCollapsed: true,
33
+ sidebarCollapsible: true,
34
+ },
35
+ ...params,
33
36
  });
34
37
  }
35
38
 
@@ -110,6 +113,10 @@ describe('DefaultSidebarItemsGenerator', () => {
110
113
  frontMatter: {},
111
114
  },
112
115
  ],
116
+ options: {
117
+ sidebarCollapsed: true,
118
+ sidebarCollapsible: true,
119
+ },
113
120
  });
114
121
 
115
122
  expect(sidebarSlice).toEqual([
@@ -190,6 +197,10 @@ describe('DefaultSidebarItemsGenerator', () => {
190
197
  frontMatter: {},
191
198
  },
192
199
  ],
200
+ options: {
201
+ sidebarCollapsed: true,
202
+ sidebarCollapsible: true,
203
+ },
193
204
  });
194
205
 
195
206
  expect(sidebarSlice).toEqual([
@@ -197,7 +208,8 @@ describe('DefaultSidebarItemsGenerator', () => {
197
208
  {
198
209
  type: 'category',
199
210
  label: 'Tutorials',
200
- collapsed: DefaultCategoryCollapsedValue,
211
+ collapsed: true,
212
+ collapsible: true,
201
213
  items: [
202
214
  {type: 'doc', id: 'tutorial1'},
203
215
  {type: 'doc', id: 'tutorial2'},
@@ -207,12 +219,14 @@ describe('DefaultSidebarItemsGenerator', () => {
207
219
  type: 'category',
208
220
  label: 'Guides',
209
221
  collapsed: false,
222
+ collapsible: true,
210
223
  items: [
211
224
  {type: 'doc', id: 'guide1'},
212
225
  {
213
226
  type: 'category',
214
227
  label: 'SubGuides (metadata file label)',
215
- collapsed: DefaultCategoryCollapsedValue,
228
+ collapsed: true,
229
+ collapsible: true,
216
230
  items: [{type: 'doc', id: 'nested-guide'}],
217
231
  },
218
232
  {type: 'doc', id: 'guide2'},
@@ -233,6 +247,7 @@ describe('DefaultSidebarItemsGenerator', () => {
233
247
  'subfolder/subsubfolder/subsubsubfolder3/_category_.json': {
234
248
  position: 1,
235
249
  label: 'subsubsubfolder3 (_category_.json label)',
250
+ collapsible: false,
236
251
  collapsed: false,
237
252
  },
238
253
  });
@@ -305,6 +320,10 @@ describe('DefaultSidebarItemsGenerator', () => {
305
320
  frontMatter: {},
306
321
  },
307
322
  ],
323
+ options: {
324
+ sidebarCollapsed: true,
325
+ sidebarCollapsible: true,
326
+ },
308
327
  });
309
328
 
310
329
  expect(sidebarSlice).toEqual([
@@ -312,6 +331,7 @@ describe('DefaultSidebarItemsGenerator', () => {
312
331
  type: 'category',
313
332
  label: 'subsubsubfolder3 (_category_.json label)',
314
333
  collapsed: false,
334
+ collapsible: false,
315
335
  items: [
316
336
  {type: 'doc', id: 'doc8'},
317
337
  {type: 'doc', id: 'doc7'},
@@ -321,6 +341,7 @@ describe('DefaultSidebarItemsGenerator', () => {
321
341
  type: 'category',
322
342
  label: 'subsubsubfolder2 (_category_.yml label)',
323
343
  collapsed: true,
344
+ collapsible: true,
324
345
  items: [{type: 'doc', id: 'doc6'}],
325
346
  },
326
347
  {type: 'doc', id: 'doc1'},
@@ -329,6 +350,7 @@ describe('DefaultSidebarItemsGenerator', () => {
329
350
  type: 'category',
330
351
  label: 'subsubsubfolder',
331
352
  collapsed: true,
353
+ collapsible: true,
332
354
  items: [{type: 'doc', id: 'doc5'}],
333
355
  },
334
356
  ] as Sidebar);
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import path from 'path';
9
+ import {
10
+ loadUnprocessedSidebars,
11
+ DefaultSidebars,
12
+ DisabledSidebars,
13
+ } from '../index';
14
+ import type {SidebarOptions} from '../../types';
15
+
16
+ describe('loadUnprocessedSidebars', () => {
17
+ const fixtureDir = path.join(__dirname, '__fixtures__', 'sidebars');
18
+ const options: SidebarOptions = {
19
+ sidebarCollapsed: true,
20
+ sidebarCollapsible: true,
21
+ };
22
+ test('sidebars with known sidebar item type', async () => {
23
+ const sidebarPath = path.join(fixtureDir, 'sidebars.json');
24
+ const result = loadUnprocessedSidebars(sidebarPath, options);
25
+ expect(result).toMatchSnapshot();
26
+ });
27
+
28
+ test('sidebars with deep level of category', async () => {
29
+ const sidebarPath = path.join(fixtureDir, 'sidebars-category.js');
30
+ const result = loadUnprocessedSidebars(sidebarPath, options);
31
+ expect(result).toMatchSnapshot();
32
+ });
33
+
34
+ test('sidebars shorthand and longform lead to exact same sidebar', async () => {
35
+ const sidebarPath1 = path.join(fixtureDir, 'sidebars-category.js');
36
+ const sidebarPath2 = path.join(
37
+ fixtureDir,
38
+ 'sidebars-category-shorthand.js',
39
+ );
40
+ const sidebar1 = loadUnprocessedSidebars(sidebarPath1, options);
41
+ const sidebar2 = loadUnprocessedSidebars(sidebarPath2, options);
42
+ expect(sidebar1).toEqual(sidebar2);
43
+ });
44
+
45
+ test('sidebars with category but category.items is not an array', async () => {
46
+ const sidebarPath = path.join(
47
+ fixtureDir,
48
+ 'sidebars-category-wrong-items.json',
49
+ );
50
+ expect(() => loadUnprocessedSidebars(sidebarPath, options))
51
+ .toThrowErrorMatchingInlineSnapshot(`
52
+ "{
53
+ \\"type\\": \\"category\\",
54
+ \\"label\\": \\"Category Label\\",
55
+ \\"items\\" [1]: \\"doc1\\"
56
+ }
57
+ 
58
+ [1] \\"items\\" must be an array"
59
+ `);
60
+ });
61
+
62
+ test('sidebars with category but category label is not a string', async () => {
63
+ const sidebarPath = path.join(
64
+ fixtureDir,
65
+ 'sidebars-category-wrong-label.json',
66
+ );
67
+ expect(() => loadUnprocessedSidebars(sidebarPath, options))
68
+ .toThrowErrorMatchingInlineSnapshot(`
69
+ "{
70
+ \\"type\\": \\"category\\",
71
+ \\"items\\": [
72
+ \\"doc1\\"
73
+ ],
74
+ \\"label\\" [1]: true
75
+ }
76
+ 
77
+ [1] \\"label\\" must be a string"
78
+ `);
79
+ });
80
+
81
+ test('sidebars item doc but id is not a string', async () => {
82
+ const sidebarPath = path.join(
83
+ fixtureDir,
84
+ 'sidebars-doc-id-not-string.json',
85
+ );
86
+ expect(() => loadUnprocessedSidebars(sidebarPath, options))
87
+ .toThrowErrorMatchingInlineSnapshot(`
88
+ "{
89
+ \\"type\\": \\"doc\\",
90
+ \\"id\\" [1]: [
91
+ \\"doc1\\"
92
+ ]
93
+ }
94
+ 
95
+ [1] \\"id\\" must be a string"
96
+ `);
97
+ });
98
+
99
+ test('sidebars with first level not a category', async () => {
100
+ const sidebarPath = path.join(
101
+ fixtureDir,
102
+ 'sidebars-first-level-not-category.js',
103
+ );
104
+ const result = loadUnprocessedSidebars(sidebarPath, options);
105
+ expect(result).toMatchSnapshot();
106
+ });
107
+
108
+ test('sidebars link', async () => {
109
+ const sidebarPath = path.join(fixtureDir, 'sidebars-link.json');
110
+ const result = loadUnprocessedSidebars(sidebarPath, options);
111
+ expect(result).toMatchSnapshot();
112
+ });
113
+
114
+ test('sidebars link wrong label', async () => {
115
+ const sidebarPath = path.join(fixtureDir, 'sidebars-link-wrong-label.json');
116
+ expect(() => loadUnprocessedSidebars(sidebarPath, options))
117
+ .toThrowErrorMatchingInlineSnapshot(`
118
+ "{
119
+ \\"type\\": \\"link\\",
120
+ \\"href\\": \\"https://github.com\\",
121
+ \\"label\\" [1]: false
122
+ }
123
+ 
124
+ [1] \\"label\\" must be a string"
125
+ `);
126
+ });
127
+
128
+ test('sidebars link wrong href', async () => {
129
+ const sidebarPath = path.join(fixtureDir, 'sidebars-link-wrong-href.json');
130
+ expect(() => loadUnprocessedSidebars(sidebarPath, options))
131
+ .toThrowErrorMatchingInlineSnapshot(`
132
+ "{
133
+ \\"type\\": \\"link\\",
134
+ \\"label\\": \\"GitHub\\",
135
+ \\"href\\" [1]: [
136
+ \\"example.com\\"
137
+ ]
138
+ }
139
+ 
140
+ [1] \\"href\\" contains an invalid value"
141
+ `);
142
+ });
143
+
144
+ test('sidebars with unknown sidebar item type', async () => {
145
+ const sidebarPath = path.join(fixtureDir, 'sidebars-unknown-type.json');
146
+ expect(() => loadUnprocessedSidebars(sidebarPath, options))
147
+ .toThrowErrorMatchingInlineSnapshot(`
148
+ "{
149
+ \\"type\\": \\"superman\\",
150
+ \\"undefined\\" [1]: -- missing --
151
+ }
152
+ 
153
+ [1] Unknown sidebar item type \\"superman\\"."
154
+ `);
155
+ });
156
+
157
+ test('sidebars with known sidebar item type but wrong field', async () => {
158
+ const sidebarPath = path.join(fixtureDir, 'sidebars-wrong-field.json');
159
+ expect(() => loadUnprocessedSidebars(sidebarPath, options))
160
+ .toThrowErrorMatchingInlineSnapshot(`
161
+ "{
162
+ \\"type\\": \\"category\\",
163
+ \\"label\\": \\"category\\",
164
+ \\"href\\": \\"https://github.com\\",
165
+ \\"items\\" [1]: -- missing --
166
+ }
167
+ 
168
+ [1] \\"items\\" is required"
169
+ `);
170
+ });
171
+
172
+ test('unexisting path', () => {
173
+ expect(loadUnprocessedSidebars('badpath', options)).toEqual(
174
+ DisabledSidebars,
175
+ );
176
+ });
177
+
178
+ test('undefined path', () => {
179
+ expect(loadUnprocessedSidebars(undefined, options)).toEqual(
180
+ DefaultSidebars,
181
+ );
182
+ });
183
+
184
+ test('literal false path', () => {
185
+ expect(loadUnprocessedSidebars(false, options)).toEqual(DisabledSidebars);
186
+ });
187
+
188
+ test('sidebars with category.collapsed property', async () => {
189
+ const sidebarPath = path.join(fixtureDir, 'sidebars-collapsed.json');
190
+ const result = loadUnprocessedSidebars(sidebarPath, options);
191
+ expect(result).toMatchSnapshot();
192
+ });
193
+
194
+ test('sidebars with category.collapsed property at first level', async () => {
195
+ const sidebarPath = path.join(
196
+ fixtureDir,
197
+ 'sidebars-collapsed-first-level.json',
198
+ );
199
+ const result = loadUnprocessedSidebars(sidebarPath, options);
200
+ expect(result).toMatchSnapshot();
201
+ });
202
+ });
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {processSidebars} from '../processor';
9
+ import type {
10
+ SidebarItem,
11
+ SidebarItemsGenerator,
12
+ Sidebars,
13
+ NormalizedSidebars,
14
+ } from '../types';
15
+ import {DefaultSidebarItemsGenerator} from '../generator';
16
+
17
+ describe('processSidebars', () => {
18
+ const StaticGeneratedSidebarSlice: SidebarItem[] = [
19
+ {type: 'doc', id: 'doc-generated-id-1'},
20
+ {type: 'doc', id: 'doc-generated-id-2'},
21
+ ];
22
+
23
+ const StaticSidebarItemsGenerator: SidebarItemsGenerator = jest.fn(
24
+ async () => {
25
+ return StaticGeneratedSidebarSlice;
26
+ },
27
+ );
28
+
29
+ async function testProcessSidebars(unprocessedSidebars: NormalizedSidebars) {
30
+ return processSidebars(unprocessedSidebars, {
31
+ sidebarItemsGenerator: StaticSidebarItemsGenerator,
32
+ docs: [],
33
+ // @ts-expect-error: useless for this test
34
+ version: {},
35
+ });
36
+ }
37
+
38
+ test('let sidebars without autogenerated items untouched', async () => {
39
+ const unprocessedSidebars: NormalizedSidebars = {
40
+ someSidebar: [
41
+ {type: 'doc', id: 'doc1'},
42
+ {
43
+ type: 'category',
44
+ collapsed: false,
45
+ collapsible: true,
46
+ items: [{type: 'doc', id: 'doc2'}],
47
+ label: 'Category',
48
+ },
49
+ {type: 'link', href: 'https://facebook.com', label: 'FB'},
50
+ ],
51
+ secondSidebar: [
52
+ {type: 'doc', id: 'doc3'},
53
+ {type: 'link', href: 'https://instagram.com', label: 'IG'},
54
+ {
55
+ type: 'category',
56
+ collapsed: false,
57
+ collapsible: true,
58
+ items: [{type: 'doc', id: 'doc4'}],
59
+ label: 'Category',
60
+ },
61
+ ],
62
+ };
63
+
64
+ const processedSidebar = await testProcessSidebars(unprocessedSidebars);
65
+ expect(processedSidebar).toEqual(unprocessedSidebars);
66
+ });
67
+
68
+ test('replace autogenerated items by generated sidebars slices', async () => {
69
+ const unprocessedSidebars: NormalizedSidebars = {
70
+ someSidebar: [
71
+ {type: 'doc', id: 'doc1'},
72
+ {
73
+ type: 'category',
74
+ collapsed: false,
75
+ collapsible: true,
76
+ items: [
77
+ {type: 'doc', id: 'doc2'},
78
+ {type: 'autogenerated', dirName: 'dir1'},
79
+ ],
80
+ label: 'Category',
81
+ },
82
+ {type: 'link', href: 'https://facebook.com', label: 'FB'},
83
+ ],
84
+ secondSidebar: [
85
+ {type: 'doc', id: 'doc3'},
86
+ {type: 'autogenerated', dirName: 'dir2'},
87
+ {type: 'link', href: 'https://instagram.com', label: 'IG'},
88
+ {type: 'autogenerated', dirName: 'dir3'},
89
+ {
90
+ type: 'category',
91
+ collapsed: false,
92
+ collapsible: true,
93
+ items: [{type: 'doc', id: 'doc4'}],
94
+ label: 'Category',
95
+ },
96
+ ],
97
+ };
98
+
99
+ const processedSidebar = await testProcessSidebars(unprocessedSidebars);
100
+
101
+ expect(StaticSidebarItemsGenerator).toHaveBeenCalledTimes(3);
102
+ expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
103
+ defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
104
+ item: {type: 'autogenerated', dirName: 'dir1'},
105
+ docs: [],
106
+ version: {},
107
+ });
108
+ expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
109
+ defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
110
+ item: {type: 'autogenerated', dirName: 'dir2'},
111
+ docs: [],
112
+ version: {},
113
+ });
114
+ expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
115
+ defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
116
+ item: {type: 'autogenerated', dirName: 'dir3'},
117
+ docs: [],
118
+ version: {},
119
+ });
120
+
121
+ expect(processedSidebar).toEqual({
122
+ someSidebar: [
123
+ {type: 'doc', id: 'doc1'},
124
+ {
125
+ type: 'category',
126
+ collapsed: false,
127
+ collapsible: true,
128
+ items: [{type: 'doc', id: 'doc2'}, ...StaticGeneratedSidebarSlice],
129
+ label: 'Category',
130
+ },
131
+ {type: 'link', href: 'https://facebook.com', label: 'FB'},
132
+ ],
133
+ secondSidebar: [
134
+ {type: 'doc', id: 'doc3'},
135
+ ...StaticGeneratedSidebarSlice,
136
+ {type: 'link', href: 'https://instagram.com', label: 'IG'},
137
+ ...StaticGeneratedSidebarSlice,
138
+ {
139
+ type: 'category',
140
+ collapsed: false,
141
+ collapsible: true,
142
+ items: [{type: 'doc', id: 'doc4'}],
143
+ label: 'Category',
144
+ },
145
+ ],
146
+ } as Sidebars);
147
+ });
148
+ });