@mintlify/common 1.0.1069 → 1.0.1071

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,122 @@
1
+ import { getScopedNavForPath } from './scopeNavToPath.js';
2
+ const versionedNav = {
3
+ versions: [
4
+ {
5
+ version: 'v2',
6
+ default: true,
7
+ groups: [
8
+ {
9
+ group: 'Guides',
10
+ pages: [
11
+ { title: 'Overview', href: '/v2/overview' },
12
+ { title: 'Shared', href: '/shared' },
13
+ ],
14
+ },
15
+ ],
16
+ },
17
+ {
18
+ version: 'v1',
19
+ groups: [
20
+ {
21
+ group: 'Guides',
22
+ pages: [
23
+ { title: 'Overview', href: '/v1/overview' },
24
+ { title: 'Shared', href: '/shared' },
25
+ ],
26
+ },
27
+ ],
28
+ },
29
+ ],
30
+ };
31
+ const localizedNav = {
32
+ languages: [
33
+ {
34
+ language: 'en',
35
+ default: true,
36
+ groups: [{ group: 'Guides', pages: [{ title: 'Overview', href: '/overview' }] }],
37
+ },
38
+ {
39
+ language: 'es',
40
+ groups: [{ group: 'Guides', pages: [{ title: 'Resumen', href: '/es/overview' }] }],
41
+ },
42
+ ],
43
+ };
44
+ describe('version and language resolution', () => {
45
+ it('resolves the version from the path dictionary when the page is version-scoped', () => {
46
+ expect(getScopedNavForPath({ decoratedNav: versionedNav, currentPath: '/v1/overview' })
47
+ .currentVersion).toBe('v1');
48
+ expect(getScopedNavForPath({ decoratedNav: versionedNav, currentPath: '/v2/overview' })
49
+ .currentVersion).toBe('v2');
50
+ });
51
+ it('falls back to the default version for a page shared across versions', () => {
52
+ const scoped = getScopedNavForPath({ decoratedNav: versionedNav, currentPath: '/shared' });
53
+ expect(scoped.currentVersion).toBe('v2');
54
+ });
55
+ it('falls back for a path that is not in the navigation', () => {
56
+ const scoped = getScopedNavForPath({
57
+ decoratedNav: versionedNav,
58
+ currentPath: '/nothing/here',
59
+ });
60
+ expect(scoped.currentVersion).toBe('v2');
61
+ });
62
+ it('leaves the version undefined when the nav has no versions', () => {
63
+ const scoped = getScopedNavForPath({ decoratedNav: localizedNav, currentPath: '/overview' });
64
+ expect(scoped.currentVersion).toBeUndefined();
65
+ });
66
+ it('resolves the language from the path dictionary', () => {
67
+ expect(getScopedNavForPath({ decoratedNav: localizedNav, currentPath: '/es/overview' })
68
+ .currentLanguage).toBe('es');
69
+ expect(getScopedNavForPath({ decoratedNav: localizedNav, currentPath: '/overview' }).currentLanguage).toBe('en');
70
+ });
71
+ it('falls back for a path that is in no language division', () => {
72
+ const scoped = getScopedNavForPath({
73
+ decoratedNav: localizedNav,
74
+ currentPath: '/nothing/here',
75
+ });
76
+ expect(scoped.currentLanguage).toBe('en');
77
+ });
78
+ it('leaves the language undefined when the nav has no languages', () => {
79
+ const scoped = getScopedNavForPath({ decoratedNav: versionedNav, currentPath: '/v1/overview' });
80
+ expect(scoped.currentLanguage).toBeUndefined();
81
+ });
82
+ it('resolves version and language together', () => {
83
+ const nav = {
84
+ versions: [
85
+ {
86
+ version: 'v2',
87
+ default: true,
88
+ languages: [
89
+ {
90
+ language: 'en',
91
+ default: true,
92
+ groups: [{ group: 'Guides', pages: [{ title: 'Overview', href: '/v2/overview' }] }],
93
+ },
94
+ {
95
+ language: 'es',
96
+ groups: [{ group: 'Guides', pages: [{ title: 'Resumen', href: '/v2/es/overview' }] }],
97
+ },
98
+ ],
99
+ },
100
+ {
101
+ version: 'v1',
102
+ languages: [
103
+ {
104
+ language: 'en',
105
+ groups: [{ group: 'Guides', pages: [{ title: 'Overview', href: '/v1/overview' }] }],
106
+ },
107
+ ],
108
+ },
109
+ ],
110
+ };
111
+ const scoped = getScopedNavForPath({ decoratedNav: nav, currentPath: '/v2/es/overview' });
112
+ expect(scoped.currentVersion).toBe('v2');
113
+ expect(scoped.currentLanguage).toBe('es');
114
+ });
115
+ it('produces the same scoped nav on repeated calls', () => {
116
+ const first = getScopedNavForPath({ decoratedNav: versionedNav, currentPath: '/shared' });
117
+ const second = getScopedNavForPath({ decoratedNav: versionedNav, currentPath: '/shared' });
118
+ expect(JSON.stringify(second.scopedNav)).toBe(JSON.stringify(first.scopedNav));
119
+ expect(second.currentVersion).toBe(first.currentVersion);
120
+ expect([...second.firstHrefInVersion]).toEqual([...first.firstHrefInVersion]);
121
+ });
122
+ });