@mintlify/common 1.0.1241 → 1.0.1243
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { generatePathToHiddenDict } from '../divisions/generatePathToHiddenDict.js';
|
|
2
|
+
import { generatePathToHiddenFromSearchDict } from '../divisions/generatePathToHiddenFromSearchDict.js';
|
|
3
|
+
import { filterDivisions, isActiveDivision } from './filterDivisions.js';
|
|
4
|
+
import { getScopedNavForPath } from './scopeNavToPath.js';
|
|
5
|
+
function sidebar(group, path) {
|
|
6
|
+
return [
|
|
7
|
+
{
|
|
8
|
+
group,
|
|
9
|
+
pages: [
|
|
10
|
+
{ title: 'Overview', href: path },
|
|
11
|
+
{ title: 'Setup', href: `${path}/setup` },
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
function languageFixture(language) {
|
|
17
|
+
const menus = [
|
|
18
|
+
{ item: 'Control', path: `/${language}/control` },
|
|
19
|
+
{ item: 'Analytics', path: `/${language}/analytics` },
|
|
20
|
+
].map(({ item, path }) => ({ item, path, groups: sidebar(item, path) }));
|
|
21
|
+
const products = [
|
|
22
|
+
{ tab: 'Storage', path: `/${language}/control/storage` },
|
|
23
|
+
{ tab: 'Object Storage', path: `/${language}/control/storage/objects` },
|
|
24
|
+
{ tab: 'Networking', path: `/${language}/control/networking` },
|
|
25
|
+
].map(({ tab, path }) => ({ tab, path, groups: sidebar(tab, path) }));
|
|
26
|
+
const config = {
|
|
27
|
+
language,
|
|
28
|
+
tabs: [
|
|
29
|
+
{
|
|
30
|
+
tab: 'Platform',
|
|
31
|
+
menu: menus.map(({ item, groups }) => ({ item, groups })),
|
|
32
|
+
},
|
|
33
|
+
...products.map(({ tab, groups }) => ({
|
|
34
|
+
tab,
|
|
35
|
+
hidden: true,
|
|
36
|
+
searchable: true,
|
|
37
|
+
groups,
|
|
38
|
+
})),
|
|
39
|
+
{
|
|
40
|
+
tab: 'Internal',
|
|
41
|
+
hidden: true,
|
|
42
|
+
groups: sidebar('Internal', `/${language}/internal`),
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
const cases = [
|
|
47
|
+
...menus.flatMap(({ item, path, groups }) => [path, `${path}/setup`].map((currentPath) => ({
|
|
48
|
+
language,
|
|
49
|
+
currentPath,
|
|
50
|
+
activeTab: 'Platform',
|
|
51
|
+
activeMenu: item,
|
|
52
|
+
sidebar: groups,
|
|
53
|
+
}))),
|
|
54
|
+
...products.flatMap(({ tab, path, groups }) => [path, `${path}/setup`].map((currentPath) => ({
|
|
55
|
+
language,
|
|
56
|
+
currentPath,
|
|
57
|
+
activeTab: tab,
|
|
58
|
+
sidebar: groups,
|
|
59
|
+
}))),
|
|
60
|
+
];
|
|
61
|
+
return { config, cases };
|
|
62
|
+
}
|
|
63
|
+
const languages = ['en', 'es'];
|
|
64
|
+
const fixtures = languages.map(languageFixture);
|
|
65
|
+
const decoratedNav = {
|
|
66
|
+
languages: fixtures.map(({ config }) => config),
|
|
67
|
+
};
|
|
68
|
+
const cases = fixtures.flatMap((fixture) => fixture.cases);
|
|
69
|
+
describe.each(['full navigation', 'scoped navigation'])('hidden tabs with %s', (mode) => {
|
|
70
|
+
it.each(cases)('$currentPath resolves to its own tab and complete sidebar', ({ language, currentPath, activeTab, activeMenu, sidebar }) => {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
let nav = decoratedNav;
|
|
73
|
+
if (mode === 'scoped navigation') {
|
|
74
|
+
const scoped = getScopedNavForPath({ decoratedNav, currentPath });
|
|
75
|
+
expect(scoped.currentLanguage).toBe(language);
|
|
76
|
+
nav = scoped.scopedNav;
|
|
77
|
+
}
|
|
78
|
+
const result = filterDivisions({
|
|
79
|
+
decoratedNav: nav,
|
|
80
|
+
currentPath,
|
|
81
|
+
currentLanguage: language,
|
|
82
|
+
currentVersion: undefined,
|
|
83
|
+
userGroups: new Set(),
|
|
84
|
+
shouldUseDivisionMatch: true,
|
|
85
|
+
cache: { dropdownCache: new Map() },
|
|
86
|
+
});
|
|
87
|
+
const expectedTabs = [{ tab: 'Platform', isActive: activeTab === 'Platform' }];
|
|
88
|
+
if (activeTab !== 'Platform') {
|
|
89
|
+
expectedTabs.push({ tab: activeTab, isActive: true });
|
|
90
|
+
}
|
|
91
|
+
expect(result.tabs.map(({ tab, isActive }) => ({ tab, isActive }))).toEqual(expectedTabs);
|
|
92
|
+
expect(result.tabs.filter(isActiveDivision).map(({ tab }) => tab)).toEqual([activeTab]);
|
|
93
|
+
expect(result.languages.filter(isActiveDivision).map(({ language }) => language)).toEqual([
|
|
94
|
+
language,
|
|
95
|
+
]);
|
|
96
|
+
expect(result.groupsOrPages).toEqual(sidebar);
|
|
97
|
+
expect((_b = (_a = result.tabs
|
|
98
|
+
.find(({ tab }) => tab === 'Platform')) === null || _a === void 0 ? void 0 : _a.menu) === null || _b === void 0 ? void 0 : _b.map(({ item, href, isActive }) => ({ item, href, isActive }))).toEqual([
|
|
99
|
+
{ item: 'Control', href: `/${language}/control`, isActive: activeMenu === 'Control' },
|
|
100
|
+
{ item: 'Analytics', href: `/${language}/analytics`, isActive: activeMenu === 'Analytics' },
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('hidden tab indexing', () => {
|
|
105
|
+
it('keeps searchable products hidden in navigation while eligible for indexing', () => {
|
|
106
|
+
const hiddenFromNav = generatePathToHiddenDict(decoratedNav);
|
|
107
|
+
const hiddenFromSearch = generatePathToHiddenFromSearchDict(decoratedNav);
|
|
108
|
+
for (const { currentPath, activeTab } of cases) {
|
|
109
|
+
const path = currentPath.slice(1);
|
|
110
|
+
expect(hiddenFromNav.has(path), currentPath).toBe(activeTab !== 'Platform');
|
|
111
|
+
expect(hiddenFromSearch.has(path), currentPath).toBe(false);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
it('keeps hidden tabs without searchable excluded from indexing', () => {
|
|
115
|
+
const expected = new Map();
|
|
116
|
+
for (const language of languages) {
|
|
117
|
+
expected.set(`${language}/internal`, true);
|
|
118
|
+
expected.set(`${language}/internal/setup`, true);
|
|
119
|
+
}
|
|
120
|
+
expect(generatePathToHiddenFromSearchDict(decoratedNav)).toEqual(expected);
|
|
121
|
+
});
|
|
122
|
+
});
|