@scalar/docusaurus 0.7.16 → 0.7.18
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.
- package/CHANGELOG.md +13 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -3
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +464 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @scalar/docusaurus
|
|
2
2
|
|
|
3
|
+
## 0.7.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [008a0f3]
|
|
8
|
+
- @scalar/types@0.3.0
|
|
9
|
+
|
|
10
|
+
## 0.7.17
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 947a844: Fixed a bug where baseURL was not included when adding a route.
|
|
15
|
+
|
|
3
16
|
## 0.7.16
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { LoadContext, Plugin } from '@docusaurus/types';
|
|
2
2
|
import type { AnyApiReferenceConfiguration } from '@scalar/types';
|
|
3
3
|
export type ScalarOptions = {
|
|
4
|
-
label
|
|
5
|
-
route
|
|
4
|
+
label?: string;
|
|
5
|
+
route?: string;
|
|
6
6
|
/**
|
|
7
7
|
* If you wish to pin a specific CDN version instead of the latest (default)
|
|
8
8
|
* @example https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.28.11
|
package/dist/index.js
CHANGED
|
@@ -4,23 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
+
const utils_1 = require("@docusaurus/utils");
|
|
7
8
|
/**
|
|
8
9
|
* Used to set default options from the user-provided options
|
|
9
10
|
* This is also useful to ensure backwards compatibility with older configs that don't have the new options
|
|
10
11
|
*/
|
|
11
12
|
const createDefaultScalarOptions = (options) => ({
|
|
12
13
|
showNavLink: true,
|
|
14
|
+
...options,
|
|
13
15
|
configuration: {
|
|
14
16
|
_integration: 'docusaurus',
|
|
15
17
|
...(options.configuration ?? {}),
|
|
16
18
|
},
|
|
17
|
-
...options,
|
|
18
19
|
});
|
|
19
20
|
/**
|
|
20
21
|
* Scalar's Docusaurus plugin for Api References
|
|
21
22
|
*/
|
|
22
23
|
const ScalarDocusaurus = (context, options) => {
|
|
23
24
|
const defaultOptions = createDefaultScalarOptions(options);
|
|
25
|
+
const { baseUrl } = context.siteConfig;
|
|
24
26
|
return {
|
|
25
27
|
name: '@scalar/docusaurus',
|
|
26
28
|
/**
|
|
@@ -48,14 +50,14 @@ const ScalarDocusaurus = (context, options) => {
|
|
|
48
50
|
if (defaultOptions.showNavLink) {
|
|
49
51
|
;
|
|
50
52
|
context.siteConfig.themeConfig.navbar.items.push({
|
|
51
|
-
to: defaultOptions.route ?? '/scalar',
|
|
53
|
+
to: (0, utils_1.normalizeUrl)([baseUrl, defaultOptions.route ?? '/scalar']),
|
|
52
54
|
label: defaultOptions.label ?? 'Scalar',
|
|
53
55
|
position: 'left',
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
// Add the appropriate route based on the module system
|
|
57
59
|
addRoute({
|
|
58
|
-
path: defaultOptions.route,
|
|
60
|
+
path: (0, utils_1.normalizeUrl)([baseUrl, defaultOptions.route ?? '/scalar']),
|
|
59
61
|
component: node_path_1.default.resolve(__dirname, './ScalarDocusaurus'),
|
|
60
62
|
exact: true,
|
|
61
63
|
...content,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const index_1 = __importDefault(require("./index"));
|
|
8
|
+
(0, vitest_1.describe)('ScalarDocusaurus', () => {
|
|
9
|
+
(0, vitest_1.describe)('plugin creation', () => {
|
|
10
|
+
(0, vitest_1.it)('returns a plugin object with required methods', () => {
|
|
11
|
+
const mockContext = {
|
|
12
|
+
siteConfig: {
|
|
13
|
+
baseUrl: '/',
|
|
14
|
+
themeConfig: {
|
|
15
|
+
navbar: {
|
|
16
|
+
items: [],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
22
|
+
label: 'Scalar',
|
|
23
|
+
route: '/scalar',
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.expect)(plugin).toHaveProperty('name', '@scalar/docusaurus');
|
|
26
|
+
(0, vitest_1.expect)(plugin).toHaveProperty('injectHtmlTags');
|
|
27
|
+
(0, vitest_1.expect)(plugin).toHaveProperty('loadContent');
|
|
28
|
+
(0, vitest_1.expect)(plugin).toHaveProperty('contentLoaded');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
(0, vitest_1.describe)('injectHtmlTags', () => {
|
|
32
|
+
(0, vitest_1.it)('injects default CDN script when no CDN specified', () => {
|
|
33
|
+
const mockContext = {
|
|
34
|
+
siteConfig: {
|
|
35
|
+
baseUrl: '/',
|
|
36
|
+
themeConfig: {
|
|
37
|
+
navbar: {
|
|
38
|
+
items: [],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
44
|
+
label: 'Scalar',
|
|
45
|
+
route: '/scalar',
|
|
46
|
+
});
|
|
47
|
+
const result = plugin.injectHtmlTags();
|
|
48
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
49
|
+
preBodyTags: [
|
|
50
|
+
{
|
|
51
|
+
tagName: 'script',
|
|
52
|
+
attributes: {
|
|
53
|
+
src: 'https://cdn.jsdelivr.net/npm/@scalar/api-reference',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.it)('injects custom CDN script when specified', () => {
|
|
60
|
+
const mockContext = {
|
|
61
|
+
siteConfig: {
|
|
62
|
+
baseUrl: '/',
|
|
63
|
+
themeConfig: {
|
|
64
|
+
navbar: {
|
|
65
|
+
items: [],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
71
|
+
label: 'Scalar',
|
|
72
|
+
route: '/scalar',
|
|
73
|
+
cdn: 'https://cdn.example.com/custom-scalar.js',
|
|
74
|
+
});
|
|
75
|
+
const result = plugin.injectHtmlTags();
|
|
76
|
+
(0, vitest_1.expect)(result).toEqual({
|
|
77
|
+
preBodyTags: [
|
|
78
|
+
{
|
|
79
|
+
tagName: 'script',
|
|
80
|
+
attributes: {
|
|
81
|
+
src: 'https://cdn.example.com/custom-scalar.js',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
(0, vitest_1.describe)('loadContent', () => {
|
|
89
|
+
(0, vitest_1.it)('returns default options with merged configuration', async () => {
|
|
90
|
+
const mockContext = {
|
|
91
|
+
siteConfig: {
|
|
92
|
+
baseUrl: '/',
|
|
93
|
+
themeConfig: {
|
|
94
|
+
navbar: {
|
|
95
|
+
items: [],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
101
|
+
label: 'Custom Label',
|
|
102
|
+
route: '/custom-route',
|
|
103
|
+
configuration: {
|
|
104
|
+
theme: 'purple',
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
const content = await plugin.loadContent();
|
|
108
|
+
(0, vitest_1.expect)(content).toEqual({
|
|
109
|
+
label: 'Custom Label',
|
|
110
|
+
route: '/custom-route',
|
|
111
|
+
showNavLink: true,
|
|
112
|
+
configuration: {
|
|
113
|
+
_integration: 'docusaurus',
|
|
114
|
+
theme: 'purple',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
(0, vitest_1.it)('applies default values for missing options', async () => {
|
|
119
|
+
const mockContext = {
|
|
120
|
+
siteConfig: {
|
|
121
|
+
baseUrl: '/',
|
|
122
|
+
themeConfig: {
|
|
123
|
+
navbar: {
|
|
124
|
+
items: [],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
130
|
+
label: 'Test Label',
|
|
131
|
+
route: '/test-route',
|
|
132
|
+
});
|
|
133
|
+
const content = await plugin.loadContent();
|
|
134
|
+
(0, vitest_1.expect)(content).toEqual({
|
|
135
|
+
label: 'Test Label',
|
|
136
|
+
route: '/test-route',
|
|
137
|
+
showNavLink: true,
|
|
138
|
+
configuration: {
|
|
139
|
+
_integration: 'docusaurus',
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
(0, vitest_1.it)('merges configuration objects correctly', async () => {
|
|
144
|
+
const mockContext = {
|
|
145
|
+
siteConfig: {
|
|
146
|
+
baseUrl: '/',
|
|
147
|
+
themeConfig: {
|
|
148
|
+
navbar: {
|
|
149
|
+
items: [],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
155
|
+
label: 'Test',
|
|
156
|
+
route: '/test',
|
|
157
|
+
configuration: {
|
|
158
|
+
theme: 'kepler',
|
|
159
|
+
layout: 'modern',
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const content = await plugin.loadContent();
|
|
163
|
+
(0, vitest_1.expect)(content?.configuration).toEqual({
|
|
164
|
+
_integration: 'docusaurus',
|
|
165
|
+
theme: 'kepler',
|
|
166
|
+
layout: 'modern',
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
(0, vitest_1.describe)('contentLoaded', () => {
|
|
171
|
+
(0, vitest_1.it)('adds navbar link with baseUrl when showNavLink is true', () => {
|
|
172
|
+
const mockContext = {
|
|
173
|
+
siteConfig: {
|
|
174
|
+
baseUrl: '/my-site/',
|
|
175
|
+
themeConfig: {
|
|
176
|
+
navbar: {
|
|
177
|
+
items: [],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
const mockActions = {
|
|
183
|
+
addRoute: vitest_1.vi.fn(),
|
|
184
|
+
};
|
|
185
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
186
|
+
label: 'API Docs',
|
|
187
|
+
route: '/api',
|
|
188
|
+
showNavLink: true,
|
|
189
|
+
});
|
|
190
|
+
plugin.contentLoaded?.({
|
|
191
|
+
content: {},
|
|
192
|
+
actions: mockActions,
|
|
193
|
+
});
|
|
194
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items).toHaveLength(1);
|
|
195
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items[0]).toEqual({
|
|
196
|
+
to: '/my-site/api',
|
|
197
|
+
label: 'API Docs',
|
|
198
|
+
position: 'left',
|
|
199
|
+
});
|
|
200
|
+
(0, vitest_1.expect)(mockActions.addRoute).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
201
|
+
path: '/my-site/api',
|
|
202
|
+
}));
|
|
203
|
+
});
|
|
204
|
+
(0, vitest_1.it)('adds navbar link with default values', () => {
|
|
205
|
+
const mockContext = {
|
|
206
|
+
siteConfig: {
|
|
207
|
+
baseUrl: '/docs/',
|
|
208
|
+
themeConfig: {
|
|
209
|
+
navbar: {
|
|
210
|
+
items: [],
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
const mockActions = {
|
|
216
|
+
addRoute: vitest_1.vi.fn(),
|
|
217
|
+
};
|
|
218
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
219
|
+
label: 'Scalar',
|
|
220
|
+
route: '/scalar',
|
|
221
|
+
showNavLink: true,
|
|
222
|
+
});
|
|
223
|
+
plugin.contentLoaded?.({
|
|
224
|
+
content: {},
|
|
225
|
+
actions: mockActions,
|
|
226
|
+
});
|
|
227
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items[0]).toEqual({
|
|
228
|
+
to: '/docs/scalar',
|
|
229
|
+
label: 'Scalar',
|
|
230
|
+
position: 'left',
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
(0, vitest_1.it)('does not add navbar link when showNavLink is false', () => {
|
|
234
|
+
const mockContext = {
|
|
235
|
+
siteConfig: {
|
|
236
|
+
baseUrl: '/',
|
|
237
|
+
themeConfig: {
|
|
238
|
+
navbar: {
|
|
239
|
+
items: [],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
const mockActions = {
|
|
245
|
+
addRoute: vitest_1.vi.fn(),
|
|
246
|
+
};
|
|
247
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
248
|
+
label: 'Scalar',
|
|
249
|
+
route: '/scalar',
|
|
250
|
+
showNavLink: false,
|
|
251
|
+
});
|
|
252
|
+
plugin.contentLoaded?.({
|
|
253
|
+
content: {},
|
|
254
|
+
actions: mockActions,
|
|
255
|
+
});
|
|
256
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items).toHaveLength(0);
|
|
257
|
+
(0, vitest_1.expect)(mockActions.addRoute).toHaveBeenCalled();
|
|
258
|
+
});
|
|
259
|
+
(0, vitest_1.it)('handles root baseUrl correctly', () => {
|
|
260
|
+
const mockContext = {
|
|
261
|
+
siteConfig: {
|
|
262
|
+
baseUrl: '/',
|
|
263
|
+
themeConfig: {
|
|
264
|
+
navbar: {
|
|
265
|
+
items: [],
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
const mockActions = {
|
|
271
|
+
addRoute: vitest_1.vi.fn(),
|
|
272
|
+
};
|
|
273
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
274
|
+
label: 'Scalar',
|
|
275
|
+
showNavLink: true,
|
|
276
|
+
route: '/scalar',
|
|
277
|
+
});
|
|
278
|
+
plugin.contentLoaded?.({
|
|
279
|
+
content: {},
|
|
280
|
+
actions: mockActions,
|
|
281
|
+
});
|
|
282
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items[0].to).toBe('/scalar');
|
|
283
|
+
(0, vitest_1.expect)(mockActions.addRoute).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
284
|
+
path: '/scalar',
|
|
285
|
+
}));
|
|
286
|
+
});
|
|
287
|
+
(0, vitest_1.it)('always adds route regardless of showNavLink setting', () => {
|
|
288
|
+
const mockContext = {
|
|
289
|
+
siteConfig: {
|
|
290
|
+
baseUrl: '/base/',
|
|
291
|
+
themeConfig: {
|
|
292
|
+
navbar: {
|
|
293
|
+
items: [],
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
const mockActions = {
|
|
299
|
+
addRoute: vitest_1.vi.fn(),
|
|
300
|
+
};
|
|
301
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
302
|
+
label: 'Scalar',
|
|
303
|
+
route: '/api',
|
|
304
|
+
showNavLink: false, // navbar disabled
|
|
305
|
+
});
|
|
306
|
+
plugin.contentLoaded?.({
|
|
307
|
+
content: {},
|
|
308
|
+
actions: mockActions,
|
|
309
|
+
});
|
|
310
|
+
// Route should still be added
|
|
311
|
+
(0, vitest_1.expect)(mockActions.addRoute).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
312
|
+
path: '/base/api',
|
|
313
|
+
exact: true,
|
|
314
|
+
}));
|
|
315
|
+
// But navbar should not have items
|
|
316
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items).toHaveLength(0);
|
|
317
|
+
});
|
|
318
|
+
(0, vitest_1.it)('passes content to route configuration', () => {
|
|
319
|
+
const mockContext = {
|
|
320
|
+
siteConfig: {
|
|
321
|
+
baseUrl: '/',
|
|
322
|
+
themeConfig: {
|
|
323
|
+
navbar: {
|
|
324
|
+
items: [],
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
const mockActions = {
|
|
330
|
+
addRoute: vitest_1.vi.fn(),
|
|
331
|
+
};
|
|
332
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
333
|
+
label: 'Scalar',
|
|
334
|
+
route: '/scalar',
|
|
335
|
+
});
|
|
336
|
+
const testContent = {
|
|
337
|
+
configuration: {
|
|
338
|
+
theme: 'purple',
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
plugin.contentLoaded?.({
|
|
342
|
+
content: testContent,
|
|
343
|
+
actions: mockActions,
|
|
344
|
+
});
|
|
345
|
+
(0, vitest_1.expect)(mockActions.addRoute).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
346
|
+
path: '/scalar',
|
|
347
|
+
exact: true,
|
|
348
|
+
configuration: {
|
|
349
|
+
theme: 'purple',
|
|
350
|
+
},
|
|
351
|
+
}));
|
|
352
|
+
});
|
|
353
|
+
(0, vitest_1.it)('uses default route when none specified', () => {
|
|
354
|
+
const mockContext = {
|
|
355
|
+
siteConfig: {
|
|
356
|
+
baseUrl: '/site/',
|
|
357
|
+
themeConfig: {
|
|
358
|
+
navbar: {
|
|
359
|
+
items: [],
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
const mockActions = {
|
|
365
|
+
addRoute: vitest_1.vi.fn(),
|
|
366
|
+
};
|
|
367
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
368
|
+
label: 'Scalar',
|
|
369
|
+
route: '/scalar',
|
|
370
|
+
showNavLink: true,
|
|
371
|
+
});
|
|
372
|
+
plugin.contentLoaded?.({
|
|
373
|
+
content: {},
|
|
374
|
+
actions: mockActions,
|
|
375
|
+
});
|
|
376
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items[0].to).toBe('/site/scalar');
|
|
377
|
+
(0, vitest_1.expect)(mockActions.addRoute).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
378
|
+
path: '/site/scalar',
|
|
379
|
+
}));
|
|
380
|
+
});
|
|
381
|
+
(0, vitest_1.it)('uses default label when none specified', () => {
|
|
382
|
+
const mockContext = {
|
|
383
|
+
siteConfig: {
|
|
384
|
+
baseUrl: '/',
|
|
385
|
+
themeConfig: {
|
|
386
|
+
navbar: {
|
|
387
|
+
items: [],
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
const mockActions = {
|
|
393
|
+
addRoute: vitest_1.vi.fn(),
|
|
394
|
+
};
|
|
395
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
396
|
+
route: '/api',
|
|
397
|
+
showNavLink: true,
|
|
398
|
+
});
|
|
399
|
+
plugin.contentLoaded?.({
|
|
400
|
+
content: {},
|
|
401
|
+
actions: mockActions,
|
|
402
|
+
});
|
|
403
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items[0].label).toBe('Scalar');
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
(0, vitest_1.describe)('edge cases', () => {
|
|
407
|
+
(0, vitest_1.it)('handles complex baseUrl paths', () => {
|
|
408
|
+
const mockContext = {
|
|
409
|
+
siteConfig: {
|
|
410
|
+
baseUrl: '/very/deep/nested/path/',
|
|
411
|
+
themeConfig: {
|
|
412
|
+
navbar: {
|
|
413
|
+
items: [],
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
const mockActions = {
|
|
419
|
+
addRoute: vitest_1.vi.fn(),
|
|
420
|
+
};
|
|
421
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
422
|
+
label: 'API',
|
|
423
|
+
route: '/docs',
|
|
424
|
+
showNavLink: true,
|
|
425
|
+
});
|
|
426
|
+
plugin.contentLoaded?.({
|
|
427
|
+
content: {},
|
|
428
|
+
actions: mockActions,
|
|
429
|
+
});
|
|
430
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items[0].to).toBe('/very/deep/nested/path/docs');
|
|
431
|
+
(0, vitest_1.expect)(mockActions.addRoute).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
432
|
+
path: '/very/deep/nested/path/docs',
|
|
433
|
+
}));
|
|
434
|
+
});
|
|
435
|
+
(0, vitest_1.it)('handles empty route string', () => {
|
|
436
|
+
const mockContext = {
|
|
437
|
+
siteConfig: {
|
|
438
|
+
baseUrl: '/base/',
|
|
439
|
+
themeConfig: {
|
|
440
|
+
navbar: {
|
|
441
|
+
items: [],
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
const mockActions = {
|
|
447
|
+
addRoute: vitest_1.vi.fn(),
|
|
448
|
+
};
|
|
449
|
+
const plugin = (0, index_1.default)(mockContext, {
|
|
450
|
+
label: 'API',
|
|
451
|
+
route: '',
|
|
452
|
+
showNavLink: true,
|
|
453
|
+
});
|
|
454
|
+
plugin.contentLoaded?.({
|
|
455
|
+
content: {},
|
|
456
|
+
actions: mockActions,
|
|
457
|
+
});
|
|
458
|
+
(0, vitest_1.expect)(mockContext.siteConfig.themeConfig.navbar.items[0].to).toBe('/base/');
|
|
459
|
+
(0, vitest_1.expect)(mockActions.addRoute).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
460
|
+
path: '/base/',
|
|
461
|
+
}));
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
});
|