@docusaurus/theme-common 2.0.0-beta.13 → 2.0.0-beta.15
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/lib/components/Collapsible/index.d.ts +2 -1
- package/lib/components/Collapsible/index.d.ts.map +1 -0
- package/lib/components/Collapsible/index.js +2 -1
- package/lib/components/Collapsible/index.js.map +1 -0
- package/lib/components/Details/index.d.ts +2 -1
- package/lib/components/Details/index.d.ts.map +1 -0
- package/lib/components/Details/index.js +2 -1
- package/lib/components/Details/index.js.map +1 -0
- package/lib/components/Details/styles.module.css +4 -4
- package/lib/hooks/styles.css +10 -0
- package/lib/hooks/useHideableNavbar.d.ts +13 -0
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
- package/lib/hooks/useHideableNavbar.js +59 -0
- package/lib/hooks/useHideableNavbar.js.map +1 -0
- package/lib/hooks/useKeyboardNavigation.d.ts +9 -0
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
- package/lib/hooks/useKeyboardNavigation.js +31 -0
- package/lib/hooks/useKeyboardNavigation.js.map +1 -0
- package/lib/hooks/useLockBodyScroll.d.ts +8 -0
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
- package/lib/hooks/useLockBodyScroll.js +16 -0
- package/lib/hooks/useLockBodyScroll.js.map +1 -0
- package/lib/hooks/usePrismTheme.d.ts +9 -0
- package/lib/hooks/usePrismTheme.d.ts.map +1 -0
- package/lib/hooks/usePrismTheme.js +18 -0
- package/lib/hooks/usePrismTheme.js.map +1 -0
- package/lib/hooks/useSearchPage.d.ts +14 -0
- package/lib/hooks/useSearchPage.d.ts.map +1 -0
- package/lib/hooks/useSearchPage.js +43 -0
- package/lib/hooks/useSearchPage.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +15 -0
- package/lib/hooks/useWindowSize.d.ts.map +1 -0
- package/lib/hooks/useWindowSize.js +54 -0
- package/lib/hooks/useWindowSize.js.map +1 -0
- package/lib/index.d.ts +11 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/utils/ThemeClassNames.d.ts +3 -0
- package/lib/utils/ThemeClassNames.d.ts.map +1 -0
- package/lib/utils/ThemeClassNames.js +3 -0
- package/lib/utils/ThemeClassNames.js.map +1 -0
- package/lib/utils/announcementBarUtils.d.ts +2 -1
- package/lib/utils/announcementBarUtils.d.ts.map +1 -0
- package/lib/utils/announcementBarUtils.js +3 -1
- package/lib/utils/announcementBarUtils.js.map +1 -0
- package/lib/utils/codeBlockUtils.d.ts +3 -3
- package/lib/utils/codeBlockUtils.d.ts.map +1 -0
- package/lib/utils/codeBlockUtils.js +4 -1
- package/lib/utils/codeBlockUtils.js.map +1 -0
- package/lib/utils/colorModeUtils.d.ts +18 -0
- package/lib/utils/colorModeUtils.d.ts.map +1 -0
- package/lib/utils/colorModeUtils.js +84 -0
- package/lib/utils/colorModeUtils.js.map +1 -0
- package/lib/utils/docSidebarItemsExpandedState.d.ts +17 -0
- package/lib/utils/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/utils/docSidebarItemsExpandedState.js +22 -0
- package/lib/utils/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +3 -2
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +2 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +1 -0
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +2 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +1 -0
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +2 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +1 -0
- package/lib/utils/docsUtils.d.ts +3 -2
- package/lib/utils/docsUtils.d.ts.map +1 -0
- package/lib/utils/docsUtils.js +2 -1
- package/lib/utils/docsUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +1 -0
- package/lib/utils/generalUtils.d.ts.map +1 -0
- package/lib/utils/generalUtils.js +1 -0
- package/lib/utils/generalUtils.js.map +1 -0
- package/lib/utils/historyUtils.d.ts +1 -0
- package/lib/utils/historyUtils.d.ts.map +1 -0
- package/lib/utils/historyUtils.js +1 -0
- package/lib/utils/historyUtils.js.map +1 -0
- package/lib/utils/jsUtils.d.ts +1 -0
- package/lib/utils/jsUtils.d.ts.map +1 -0
- package/lib/utils/jsUtils.js +1 -0
- package/lib/utils/jsUtils.js.map +1 -0
- package/lib/utils/mobileSecondaryMenu.d.ts +2 -1
- package/lib/utils/mobileSecondaryMenu.d.ts.map +1 -0
- package/lib/utils/mobileSecondaryMenu.js +2 -1
- package/lib/utils/mobileSecondaryMenu.js.map +1 -0
- package/lib/utils/pathUtils.d.ts +1 -0
- package/lib/utils/pathUtils.d.ts.map +1 -0
- package/lib/utils/pathUtils.js +1 -0
- package/lib/utils/pathUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +1 -0
- package/lib/utils/reactUtils.d.ts.map +1 -0
- package/lib/utils/reactUtils.js +1 -0
- package/lib/utils/reactUtils.js.map +1 -0
- package/lib/utils/regexpUtils.d.ts +2 -1
- package/lib/utils/regexpUtils.d.ts.map +1 -0
- package/lib/utils/regexpUtils.js +2 -1
- package/lib/utils/regexpUtils.js.map +1 -0
- package/lib/utils/scrollUtils.d.ts +2 -1
- package/lib/utils/scrollUtils.d.ts.map +1 -0
- package/lib/utils/scrollUtils.js +1 -0
- package/lib/utils/scrollUtils.js.map +1 -0
- package/lib/utils/searchUtils.d.ts +1 -0
- package/lib/utils/searchUtils.d.ts.map +1 -0
- package/lib/utils/searchUtils.js +1 -0
- package/lib/utils/searchUtils.js.map +1 -0
- package/lib/utils/storageUtils.d.ts +1 -0
- package/lib/utils/storageUtils.d.ts.map +1 -0
- package/lib/utils/storageUtils.js +1 -0
- package/lib/utils/storageUtils.js.map +1 -0
- package/lib/utils/tabGroupChoiceUtils.d.ts +19 -0
- package/lib/utils/tabGroupChoiceUtils.d.ts.map +1 -0
- package/lib/utils/tabGroupChoiceUtils.js +54 -0
- package/lib/utils/tabGroupChoiceUtils.js.map +1 -0
- package/lib/utils/tagsUtils.d.ts +1 -0
- package/lib/utils/tagsUtils.d.ts.map +1 -0
- package/lib/utils/tagsUtils.js +1 -0
- package/lib/utils/tagsUtils.js.map +1 -0
- package/lib/utils/tocUtils.d.ts +2 -1
- package/lib/utils/tocUtils.d.ts.map +1 -0
- package/lib/utils/tocUtils.js +1 -0
- package/lib/utils/tocUtils.js.map +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
- package/lib/utils/useAlternatePageUtils.js +1 -0
- package/lib/utils/useAlternatePageUtils.js.map +1 -0
- package/lib/utils/useContextualSearchFilters.d.ts +1 -0
- package/lib/utils/useContextualSearchFilters.d.ts.map +1 -0
- package/lib/utils/useContextualSearchFilters.js +2 -1
- package/lib/utils/useContextualSearchFilters.js.map +1 -0
- package/lib/utils/useLocalPathname.d.ts +1 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -0
- package/lib/utils/useLocalPathname.js +1 -0
- package/lib/utils/useLocalPathname.js.map +1 -0
- package/lib/utils/useLocationChange.d.ts +2 -1
- package/lib/utils/useLocationChange.d.ts.map +1 -0
- package/lib/utils/useLocationChange.js +1 -0
- package/lib/utils/useLocationChange.js.map +1 -0
- package/lib/utils/usePluralForm.d.ts +1 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -0
- package/lib/utils/usePluralForm.js +1 -0
- package/lib/utils/usePluralForm.js.map +1 -0
- package/lib/utils/usePrevious.d.ts +1 -0
- package/lib/utils/usePrevious.d.ts.map +1 -0
- package/lib/utils/usePrevious.js +1 -0
- package/lib/utils/usePrevious.js.map +1 -0
- package/lib/utils/useTOCHighlight.d.ts +1 -0
- package/lib/utils/useTOCHighlight.d.ts.map +1 -0
- package/lib/utils/useTOCHighlight.js +2 -0
- package/lib/utils/useTOCHighlight.js.map +1 -0
- package/lib/utils/useThemeConfig.d.ts +16 -9
- package/lib/utils/useThemeConfig.d.ts.map +1 -0
- package/lib/utils/useThemeConfig.js +1 -0
- package/lib/utils/useThemeConfig.js.map +1 -0
- package/package.json +11 -11
- package/src/components/Collapsible/index.tsx +5 -5
- package/src/components/Details/index.tsx +6 -1
- package/src/components/Details/styles.module.css +4 -4
- package/src/hooks/styles.css +10 -0
- package/src/hooks/useHideableNavbar.ts +77 -0
- package/src/hooks/useKeyboardNavigation.ts +37 -0
- package/src/hooks/useLockBodyScroll.ts +18 -0
- package/src/hooks/usePrismTheme.ts +20 -0
- package/src/hooks/useSearchPage.ts +66 -0
- package/src/hooks/useWindowSize.ts +68 -0
- package/src/index.ts +19 -1
- package/src/utils/ThemeClassNames.ts +2 -0
- package/src/utils/announcementBarUtils.tsx +3 -2
- package/src/utils/codeBlockUtils.ts +4 -5
- package/src/utils/colorModeUtils.tsx +135 -0
- package/src/utils/docSidebarItemsExpandedState.tsx +41 -0
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +7 -4
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +1 -1
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +5 -1
- package/src/utils/docsUtils.tsx +3 -3
- package/src/utils/mobileSecondaryMenu.tsx +3 -3
- package/src/utils/regexpUtils.ts +1 -1
- package/src/utils/scrollUtils.tsx +1 -1
- package/src/utils/tabGroupChoiceUtils.tsx +90 -0
- package/src/utils/tocUtils.ts +1 -1
- package/src/utils/useContextualSearchFilters.ts +4 -1
- package/src/utils/useLocationChange.ts +1 -1
- package/src/utils/useTOCHighlight.ts +1 -0
- package/src/utils/useThemeConfig.ts +19 -9
- package/copyUntypedFiles.js +0 -20
- package/lib/.tsbuildinfo +0 -1
- package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
- package/src/utils/__tests__/docsUtils.test.tsx +0 -331
- package/src/utils/__tests__/jsUtils.test.ts +0 -33
- package/src/utils/__tests__/pathUtils.test.ts +0 -32
- package/src/utils/__tests__/tagUtils.test.ts +0 -66
- package/src/utils/__tests__/tocUtils.test.ts +0 -197
- package/tsconfig.json +0 -10
|
@@ -1,331 +0,0 @@
|
|
|
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 React from 'react';
|
|
9
|
-
import {renderHook} from '@testing-library/react-hooks';
|
|
10
|
-
import {
|
|
11
|
-
findFirstCategoryLink,
|
|
12
|
-
isActiveSidebarItem,
|
|
13
|
-
DocsVersionProvider,
|
|
14
|
-
useDocsVersion,
|
|
15
|
-
useDocById,
|
|
16
|
-
useDocsSidebar,
|
|
17
|
-
DocsSidebarProvider,
|
|
18
|
-
findSidebarCategory,
|
|
19
|
-
} from '../docsUtils';
|
|
20
|
-
import {
|
|
21
|
-
PropSidebar,
|
|
22
|
-
PropSidebarItem,
|
|
23
|
-
PropSidebarItemCategory,
|
|
24
|
-
PropVersionMetadata,
|
|
25
|
-
} from '@docusaurus/plugin-content-docs';
|
|
26
|
-
|
|
27
|
-
// Make tests more readable with some useful category item defaults
|
|
28
|
-
function testCategory(
|
|
29
|
-
data?: Partial<PropSidebarItemCategory>,
|
|
30
|
-
): PropSidebarItemCategory {
|
|
31
|
-
return {
|
|
32
|
-
type: 'category',
|
|
33
|
-
href: undefined,
|
|
34
|
-
label: 'Category label',
|
|
35
|
-
items: [],
|
|
36
|
-
collapsed: true,
|
|
37
|
-
collapsible: true,
|
|
38
|
-
...data,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function testVersion(data?: Partial<PropVersionMetadata>): PropVersionMetadata {
|
|
43
|
-
return {
|
|
44
|
-
version: 'versionName',
|
|
45
|
-
label: 'Version Label',
|
|
46
|
-
className: 'version className',
|
|
47
|
-
badge: true,
|
|
48
|
-
banner: 'unreleased',
|
|
49
|
-
docs: {},
|
|
50
|
-
docsSidebars: {},
|
|
51
|
-
isLast: false,
|
|
52
|
-
pluginId: 'default',
|
|
53
|
-
...data,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
describe('docsUtils', () => {
|
|
58
|
-
describe('useDocsVersion', () => {
|
|
59
|
-
test('should throw if context provider is missing', () => {
|
|
60
|
-
expect(
|
|
61
|
-
() => renderHook(() => useDocsVersion()).result.current,
|
|
62
|
-
).toThrowErrorMatchingInlineSnapshot(
|
|
63
|
-
`"This hook requires usage of <DocsVersionProvider>"`,
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('should read value from context provider', () => {
|
|
68
|
-
const version = testVersion();
|
|
69
|
-
const {result} = renderHook(() => useDocsVersion(), {
|
|
70
|
-
wrapper: ({children}) => (
|
|
71
|
-
<DocsVersionProvider version={version}>
|
|
72
|
-
{children}
|
|
73
|
-
</DocsVersionProvider>
|
|
74
|
-
),
|
|
75
|
-
});
|
|
76
|
-
expect(result.current).toBe(version);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('useDocsSidebar', () => {
|
|
81
|
-
test('should throw if context provider is missing', () => {
|
|
82
|
-
expect(
|
|
83
|
-
() => renderHook(() => useDocsSidebar()).result.current,
|
|
84
|
-
).toThrowErrorMatchingInlineSnapshot(
|
|
85
|
-
`"This hook requires usage of <DocsSidebarProvider>"`,
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('should read value from context provider', () => {
|
|
90
|
-
const sidebar: PropSidebar = [];
|
|
91
|
-
const {result} = renderHook(() => useDocsSidebar(), {
|
|
92
|
-
wrapper: ({children}) => (
|
|
93
|
-
<DocsSidebarProvider sidebar={sidebar}>
|
|
94
|
-
{children}
|
|
95
|
-
</DocsSidebarProvider>
|
|
96
|
-
),
|
|
97
|
-
});
|
|
98
|
-
expect(result.current).toBe(sidebar);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('useDocById', () => {
|
|
103
|
-
const version = testVersion({
|
|
104
|
-
docs: {
|
|
105
|
-
doc1: {
|
|
106
|
-
id: 'doc1',
|
|
107
|
-
title: 'Doc 1',
|
|
108
|
-
description: 'desc1',
|
|
109
|
-
sidebar: 'sidebar1',
|
|
110
|
-
},
|
|
111
|
-
doc2: {
|
|
112
|
-
id: 'doc2',
|
|
113
|
-
title: 'Doc 2',
|
|
114
|
-
description: 'desc2',
|
|
115
|
-
sidebar: 'sidebar2',
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
function callHook(docId: string | undefined) {
|
|
121
|
-
const {result} = renderHook(() => useDocById(docId), {
|
|
122
|
-
wrapper: ({children}) => (
|
|
123
|
-
<DocsVersionProvider version={version}>
|
|
124
|
-
{children}
|
|
125
|
-
</DocsVersionProvider>
|
|
126
|
-
),
|
|
127
|
-
});
|
|
128
|
-
return result.current;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
test('should accept undefined', () => {
|
|
132
|
-
expect(callHook(undefined)).toBeUndefined();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('should find doc1', () => {
|
|
136
|
-
expect(callHook('doc1')).toMatchObject({id: 'doc1'});
|
|
137
|
-
});
|
|
138
|
-
test('should find doc2', () => {
|
|
139
|
-
expect(callHook('doc2')).toMatchObject({id: 'doc2'});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('should throw for doc3', () => {
|
|
143
|
-
expect(() => callHook('doc3')).toThrowErrorMatchingInlineSnapshot(
|
|
144
|
-
`"no version doc found by id=doc3"`,
|
|
145
|
-
);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe('findSidebarCategory', () => {
|
|
150
|
-
test('should be able to return undefined', () => {
|
|
151
|
-
expect(findSidebarCategory([], () => false)).toBeUndefined();
|
|
152
|
-
expect(
|
|
153
|
-
findSidebarCategory([testCategory(), testCategory()], () => false),
|
|
154
|
-
).toBeUndefined();
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('should return first element matching predicate', () => {
|
|
158
|
-
const first = testCategory();
|
|
159
|
-
const second = testCategory();
|
|
160
|
-
const third = testCategory();
|
|
161
|
-
const sidebar = [first, second, third];
|
|
162
|
-
expect(findSidebarCategory(sidebar, () => true)).toEqual(first);
|
|
163
|
-
expect(findSidebarCategory(sidebar, (item) => item === first)).toEqual(
|
|
164
|
-
first,
|
|
165
|
-
);
|
|
166
|
-
expect(findSidebarCategory(sidebar, (item) => item === second)).toEqual(
|
|
167
|
-
second,
|
|
168
|
-
);
|
|
169
|
-
expect(findSidebarCategory(sidebar, (item) => item === third)).toEqual(
|
|
170
|
-
third,
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test('should be able to search in sub items', () => {
|
|
175
|
-
const subsub1 = testCategory();
|
|
176
|
-
const subsub2 = testCategory();
|
|
177
|
-
const sub1 = testCategory({
|
|
178
|
-
items: [subsub1, subsub2],
|
|
179
|
-
});
|
|
180
|
-
const sub2 = testCategory();
|
|
181
|
-
const parent = testCategory({
|
|
182
|
-
items: [sub1, sub2],
|
|
183
|
-
});
|
|
184
|
-
const sidebar = [parent];
|
|
185
|
-
|
|
186
|
-
expect(findSidebarCategory(sidebar, () => true)).toEqual(parent);
|
|
187
|
-
expect(findSidebarCategory(sidebar, (item) => item === sub1)).toEqual(
|
|
188
|
-
sub1,
|
|
189
|
-
);
|
|
190
|
-
expect(findSidebarCategory(sidebar, (item) => item === sub2)).toEqual(
|
|
191
|
-
sub2,
|
|
192
|
-
);
|
|
193
|
-
expect(findSidebarCategory(sidebar, (item) => item === subsub1)).toEqual(
|
|
194
|
-
subsub1,
|
|
195
|
-
);
|
|
196
|
-
expect(findSidebarCategory(sidebar, (item) => item === subsub2)).toEqual(
|
|
197
|
-
subsub2,
|
|
198
|
-
);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
describe('findFirstCategoryLink', () => {
|
|
203
|
-
test('category without link nor child', () => {
|
|
204
|
-
expect(
|
|
205
|
-
findFirstCategoryLink(
|
|
206
|
-
testCategory({
|
|
207
|
-
href: undefined,
|
|
208
|
-
}),
|
|
209
|
-
),
|
|
210
|
-
).toEqual(undefined);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
test('category with link', () => {
|
|
214
|
-
expect(
|
|
215
|
-
findFirstCategoryLink(
|
|
216
|
-
testCategory({
|
|
217
|
-
href: '/itemPath',
|
|
218
|
-
}),
|
|
219
|
-
),
|
|
220
|
-
).toEqual('/itemPath');
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test('category with deeply nested category link', () => {
|
|
224
|
-
expect(
|
|
225
|
-
findFirstCategoryLink(
|
|
226
|
-
testCategory({
|
|
227
|
-
href: undefined,
|
|
228
|
-
items: [
|
|
229
|
-
testCategory({
|
|
230
|
-
href: undefined,
|
|
231
|
-
items: [
|
|
232
|
-
testCategory({
|
|
233
|
-
href: '/itemPath',
|
|
234
|
-
}),
|
|
235
|
-
],
|
|
236
|
-
}),
|
|
237
|
-
],
|
|
238
|
-
}),
|
|
239
|
-
),
|
|
240
|
-
).toEqual('/itemPath');
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
test('category with deeply nested link', () => {
|
|
244
|
-
expect(
|
|
245
|
-
findFirstCategoryLink(
|
|
246
|
-
testCategory({
|
|
247
|
-
href: undefined,
|
|
248
|
-
items: [
|
|
249
|
-
testCategory({
|
|
250
|
-
href: undefined,
|
|
251
|
-
items: [{type: 'link', href: '/itemPath', label: 'Label'}],
|
|
252
|
-
}),
|
|
253
|
-
],
|
|
254
|
-
}),
|
|
255
|
-
),
|
|
256
|
-
).toEqual('/itemPath');
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
describe('isActiveSidebarItem', () => {
|
|
261
|
-
test('with link href', () => {
|
|
262
|
-
const item: PropSidebarItem = {
|
|
263
|
-
type: 'link',
|
|
264
|
-
href: '/itemPath',
|
|
265
|
-
label: 'Label',
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
expect(isActiveSidebarItem(item, '/unexistingPath')).toEqual(false);
|
|
269
|
-
|
|
270
|
-
expect(isActiveSidebarItem(item, '/itemPath')).toEqual(true);
|
|
271
|
-
|
|
272
|
-
// Ensure it's not trailing slash sensitive:
|
|
273
|
-
expect(isActiveSidebarItem(item, '/itemPath/')).toEqual(true);
|
|
274
|
-
expect(
|
|
275
|
-
isActiveSidebarItem({...item, href: '/itemPath/'}, '/itemPath'),
|
|
276
|
-
).toEqual(true);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
test('with category href', () => {
|
|
280
|
-
const item: PropSidebarItem = testCategory({
|
|
281
|
-
href: '/itemPath',
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
expect(isActiveSidebarItem(item, '/unexistingPath')).toEqual(false);
|
|
285
|
-
|
|
286
|
-
expect(isActiveSidebarItem(item, '/itemPath')).toEqual(true);
|
|
287
|
-
|
|
288
|
-
// Ensure it's not trailing slash sensitive:
|
|
289
|
-
expect(isActiveSidebarItem(item, '/itemPath/')).toEqual(true);
|
|
290
|
-
expect(
|
|
291
|
-
isActiveSidebarItem({...item, href: '/itemPath/'}, '/itemPath'),
|
|
292
|
-
).toEqual(true);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
test('with category nested items', () => {
|
|
296
|
-
const item: PropSidebarItem = testCategory({
|
|
297
|
-
href: '/category-path',
|
|
298
|
-
items: [
|
|
299
|
-
{
|
|
300
|
-
type: 'link',
|
|
301
|
-
href: '/sub-link-path',
|
|
302
|
-
label: 'Label',
|
|
303
|
-
},
|
|
304
|
-
testCategory({
|
|
305
|
-
href: '/sub-category-path',
|
|
306
|
-
items: [
|
|
307
|
-
{
|
|
308
|
-
type: 'link',
|
|
309
|
-
href: '/sub-sub-link-path',
|
|
310
|
-
label: 'Label',
|
|
311
|
-
},
|
|
312
|
-
],
|
|
313
|
-
}),
|
|
314
|
-
],
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
expect(isActiveSidebarItem(item, '/unexistingPath')).toEqual(false);
|
|
318
|
-
|
|
319
|
-
expect(isActiveSidebarItem(item, '/category-path')).toEqual(true);
|
|
320
|
-
expect(isActiveSidebarItem(item, '/sub-link-path')).toEqual(true);
|
|
321
|
-
expect(isActiveSidebarItem(item, '/sub-category-path')).toEqual(true);
|
|
322
|
-
expect(isActiveSidebarItem(item, '/sub-sub-link-path')).toEqual(true);
|
|
323
|
-
|
|
324
|
-
// Ensure it's not trailing slash sensitive:
|
|
325
|
-
expect(isActiveSidebarItem(item, '/category-path/')).toEqual(true);
|
|
326
|
-
expect(isActiveSidebarItem(item, '/sub-link-path/')).toEqual(true);
|
|
327
|
-
expect(isActiveSidebarItem(item, '/sub-category-path/')).toEqual(true);
|
|
328
|
-
expect(isActiveSidebarItem(item, '/sub-sub-link-path/')).toEqual(true);
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
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 {uniq} from '../jsUtils';
|
|
9
|
-
|
|
10
|
-
describe('uniq', () => {
|
|
11
|
-
test('remove duplicate primitives', () => {
|
|
12
|
-
expect(uniq(['A', 'B', 'C', 'B', 'A', 'D'])).toEqual(['A', 'B', 'C', 'D']);
|
|
13
|
-
expect(uniq([3, 3, 5, 1, 6, 3, 5])).toEqual([3, 5, 1, 6]);
|
|
14
|
-
expect(uniq([null, undefined, 3, null, 4, 3])).toEqual([
|
|
15
|
-
null,
|
|
16
|
-
undefined,
|
|
17
|
-
3,
|
|
18
|
-
4,
|
|
19
|
-
]);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('remove duplicate objects/arrays by identity', () => {
|
|
23
|
-
const obj1 = {};
|
|
24
|
-
const obj2 = {};
|
|
25
|
-
const obj3 = {};
|
|
26
|
-
const array1: unknown[] = [];
|
|
27
|
-
const array2: unknown[] = [];
|
|
28
|
-
const array3: unknown[] = [];
|
|
29
|
-
expect(
|
|
30
|
-
uniq([obj1, obj1, obj2, array1, obj2, array3, array2, array1, obj3]),
|
|
31
|
-
).toEqual([obj1, obj2, array1, array3, array2, obj3]);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
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 {isSamePath} from '../pathUtils';
|
|
9
|
-
|
|
10
|
-
describe('isSamePath', () => {
|
|
11
|
-
test('should be true for compared path without trailing slash', () => {
|
|
12
|
-
expect(isSamePath('/docs', '/docs')).toBeTruthy();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('should be true for compared path with trailing slash', () => {
|
|
16
|
-
expect(isSamePath('/docs', '/docs/')).toBeTruthy();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('should be false for compared path with double trailing slash', () => {
|
|
20
|
-
expect(isSamePath('/docs', '/docs//')).toBeFalsy();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('should be true for twice undefined/null', () => {
|
|
24
|
-
expect(isSamePath(undefined, undefined)).toBeTruthy();
|
|
25
|
-
expect(isSamePath(undefined, undefined)).toBeTruthy();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('should be false when one undefined', () => {
|
|
29
|
-
expect(isSamePath('/docs', undefined)).toBeFalsy();
|
|
30
|
-
expect(isSamePath(undefined, '/docs')).toBeFalsy();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
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 {shuffle} from 'lodash';
|
|
9
|
-
import {listTagsByLetters} from '../tagsUtils';
|
|
10
|
-
|
|
11
|
-
describe('listTagsByLetters', () => {
|
|
12
|
-
type Param = Parameters<typeof listTagsByLetters>[0];
|
|
13
|
-
type Tag = Param[number];
|
|
14
|
-
type Result = ReturnType<typeof listTagsByLetters>;
|
|
15
|
-
|
|
16
|
-
test('Should create letters list', () => {
|
|
17
|
-
const tag1: Tag = {
|
|
18
|
-
name: 'tag1',
|
|
19
|
-
permalink: '/tag1',
|
|
20
|
-
count: 1,
|
|
21
|
-
};
|
|
22
|
-
const tag2: Tag = {
|
|
23
|
-
name: 'Tag2',
|
|
24
|
-
permalink: '/tag2',
|
|
25
|
-
count: 11,
|
|
26
|
-
};
|
|
27
|
-
const tagzxy: Tag = {
|
|
28
|
-
name: 'zxy',
|
|
29
|
-
permalink: '/zxy',
|
|
30
|
-
count: 987,
|
|
31
|
-
};
|
|
32
|
-
const tagAbc: Tag = {
|
|
33
|
-
name: 'Abc',
|
|
34
|
-
permalink: '/abc',
|
|
35
|
-
count: 123,
|
|
36
|
-
};
|
|
37
|
-
const tagdef: Tag = {
|
|
38
|
-
name: 'def',
|
|
39
|
-
permalink: '/def',
|
|
40
|
-
count: 1,
|
|
41
|
-
};
|
|
42
|
-
const tagaaa: Tag = {
|
|
43
|
-
name: 'aaa',
|
|
44
|
-
permalink: '/aaa',
|
|
45
|
-
count: 10,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const expectedResult: Result = [
|
|
49
|
-
{letter: 'A', tags: [tagaaa, tagAbc]},
|
|
50
|
-
{letter: 'D', tags: [tagdef]},
|
|
51
|
-
{letter: 'T', tags: [tag1, tag2]},
|
|
52
|
-
{letter: 'Z', tags: [tagzxy]},
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
// Input order shouldn't matter, output is always consistently sorted
|
|
56
|
-
expect(
|
|
57
|
-
listTagsByLetters([tag1, tag2, tagzxy, tagAbc, tagdef, tagaaa]),
|
|
58
|
-
).toEqual(expectedResult);
|
|
59
|
-
expect(
|
|
60
|
-
listTagsByLetters([tagzxy, tagdef, tagaaa, tag2, tagAbc, tag1]),
|
|
61
|
-
).toEqual(expectedResult);
|
|
62
|
-
expect(
|
|
63
|
-
listTagsByLetters(shuffle([tagzxy, tagdef, tagaaa, tag2, tagAbc, tag1])),
|
|
64
|
-
).toEqual(expectedResult);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
@@ -1,197 +0,0 @@
|
|
|
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 {TOCItem} from '@docusaurus/types';
|
|
9
|
-
import {filterTOC} from '../tocUtils';
|
|
10
|
-
|
|
11
|
-
describe('filterTOC', () => {
|
|
12
|
-
test('filter a toc with all heading levels', () => {
|
|
13
|
-
const toc: TOCItem[] = [
|
|
14
|
-
{
|
|
15
|
-
id: 'alpha',
|
|
16
|
-
level: 1,
|
|
17
|
-
value: 'alpha',
|
|
18
|
-
children: [
|
|
19
|
-
{
|
|
20
|
-
id: 'bravo',
|
|
21
|
-
level: 2,
|
|
22
|
-
value: 'Bravo',
|
|
23
|
-
children: [
|
|
24
|
-
{
|
|
25
|
-
id: 'charlie',
|
|
26
|
-
level: 3,
|
|
27
|
-
value: 'Charlie',
|
|
28
|
-
children: [
|
|
29
|
-
{
|
|
30
|
-
id: 'delta',
|
|
31
|
-
level: 4,
|
|
32
|
-
value: 'Delta',
|
|
33
|
-
children: [
|
|
34
|
-
{
|
|
35
|
-
id: 'echo',
|
|
36
|
-
level: 5,
|
|
37
|
-
value: 'Echo',
|
|
38
|
-
children: [
|
|
39
|
-
{
|
|
40
|
-
id: 'foxtrot',
|
|
41
|
-
level: 6,
|
|
42
|
-
value: 'Foxtrot',
|
|
43
|
-
children: [],
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
expect(filterTOC({toc, minHeadingLevel: 2, maxHeadingLevel: 2})).toEqual([
|
|
58
|
-
{
|
|
59
|
-
id: 'bravo',
|
|
60
|
-
level: 2,
|
|
61
|
-
value: 'Bravo',
|
|
62
|
-
children: [],
|
|
63
|
-
},
|
|
64
|
-
]);
|
|
65
|
-
|
|
66
|
-
expect(filterTOC({toc, minHeadingLevel: 3, maxHeadingLevel: 3})).toEqual([
|
|
67
|
-
{
|
|
68
|
-
id: 'charlie',
|
|
69
|
-
level: 3,
|
|
70
|
-
value: 'Charlie',
|
|
71
|
-
children: [],
|
|
72
|
-
},
|
|
73
|
-
]);
|
|
74
|
-
|
|
75
|
-
expect(filterTOC({toc, minHeadingLevel: 2, maxHeadingLevel: 3})).toEqual([
|
|
76
|
-
{
|
|
77
|
-
id: 'bravo',
|
|
78
|
-
level: 2,
|
|
79
|
-
value: 'Bravo',
|
|
80
|
-
children: [
|
|
81
|
-
{
|
|
82
|
-
id: 'charlie',
|
|
83
|
-
level: 3,
|
|
84
|
-
value: 'Charlie',
|
|
85
|
-
children: [],
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
]);
|
|
90
|
-
|
|
91
|
-
expect(filterTOC({toc, minHeadingLevel: 2, maxHeadingLevel: 4})).toEqual([
|
|
92
|
-
{
|
|
93
|
-
id: 'bravo',
|
|
94
|
-
level: 2,
|
|
95
|
-
value: 'Bravo',
|
|
96
|
-
children: [
|
|
97
|
-
{
|
|
98
|
-
id: 'charlie',
|
|
99
|
-
level: 3,
|
|
100
|
-
value: 'Charlie',
|
|
101
|
-
children: [
|
|
102
|
-
{
|
|
103
|
-
id: 'delta',
|
|
104
|
-
level: 4,
|
|
105
|
-
value: 'Delta',
|
|
106
|
-
children: [],
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
]);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// It's not 100% clear exactly how the TOC should behave under weird heading levels provided by the user
|
|
116
|
-
// Adding a test so that behavior stays the same over time
|
|
117
|
-
test('filter invalid heading levels (but possible) TOC', () => {
|
|
118
|
-
const toc: TOCItem[] = [
|
|
119
|
-
{
|
|
120
|
-
id: 'charlie',
|
|
121
|
-
level: 3,
|
|
122
|
-
value: 'Charlie',
|
|
123
|
-
children: [],
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
id: 'bravo',
|
|
127
|
-
level: 2,
|
|
128
|
-
value: 'Bravo',
|
|
129
|
-
children: [
|
|
130
|
-
{
|
|
131
|
-
id: 'delta',
|
|
132
|
-
level: 4,
|
|
133
|
-
value: 'Delta',
|
|
134
|
-
children: [],
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
},
|
|
138
|
-
];
|
|
139
|
-
|
|
140
|
-
expect(filterTOC({toc, minHeadingLevel: 2, maxHeadingLevel: 2})).toEqual([
|
|
141
|
-
{
|
|
142
|
-
id: 'bravo',
|
|
143
|
-
level: 2,
|
|
144
|
-
value: 'Bravo',
|
|
145
|
-
children: [],
|
|
146
|
-
},
|
|
147
|
-
]);
|
|
148
|
-
|
|
149
|
-
expect(filterTOC({toc, minHeadingLevel: 3, maxHeadingLevel: 3})).toEqual([
|
|
150
|
-
{
|
|
151
|
-
id: 'charlie',
|
|
152
|
-
level: 3,
|
|
153
|
-
value: 'Charlie',
|
|
154
|
-
children: [],
|
|
155
|
-
},
|
|
156
|
-
]);
|
|
157
|
-
|
|
158
|
-
expect(filterTOC({toc, minHeadingLevel: 4, maxHeadingLevel: 4})).toEqual([
|
|
159
|
-
{
|
|
160
|
-
id: 'delta',
|
|
161
|
-
level: 4,
|
|
162
|
-
value: 'Delta',
|
|
163
|
-
children: [],
|
|
164
|
-
},
|
|
165
|
-
]);
|
|
166
|
-
|
|
167
|
-
expect(filterTOC({toc, minHeadingLevel: 2, maxHeadingLevel: 3})).toEqual([
|
|
168
|
-
{
|
|
169
|
-
id: 'charlie',
|
|
170
|
-
level: 3,
|
|
171
|
-
value: 'Charlie',
|
|
172
|
-
children: [],
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
id: 'bravo',
|
|
176
|
-
level: 2,
|
|
177
|
-
value: 'Bravo',
|
|
178
|
-
children: [],
|
|
179
|
-
},
|
|
180
|
-
]);
|
|
181
|
-
|
|
182
|
-
expect(filterTOC({toc, minHeadingLevel: 3, maxHeadingLevel: 4})).toEqual([
|
|
183
|
-
{
|
|
184
|
-
id: 'charlie',
|
|
185
|
-
level: 3,
|
|
186
|
-
value: 'Charlie',
|
|
187
|
-
children: [],
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
id: 'delta',
|
|
191
|
-
level: 4,
|
|
192
|
-
value: 'Delta',
|
|
193
|
-
children: [],
|
|
194
|
-
},
|
|
195
|
-
]);
|
|
196
|
-
});
|
|
197
|
-
});
|