@@ -4,32 +4,116 @@ import { Sitemap } from "../sitemap"
4
4
5
5
import { selectedVersionCorrespondingURL } from "./correspondingPage"
6
6
7
- const sitemapURLsV1 = [
8
- "https://test.github.io/project/0.1/" ,
9
- "https://test.github.io/project/0.1/bar/" ,
10
- "https://test.github.io/project/0.1/foo/"
11
- ]
12
-
13
7
describe ( "Version switcher tests" , ( ) => {
14
- it ( "selectedVersionCorrespondingURL test" , ( ) => {
15
- assert . equal (
16
- selectedVersionCorrespondingURL ( {
17
- selectedVersionSitemap : sitemapFromURLList ( sitemapURLsV1 ) ,
18
- selectedVersionBaseURL : new URL ( "https://test.github.io/project/0.1/" ) ,
19
- currentLocation : new URL ( "https://test.github.io/project/latest/bar/#heading?param=some" ) ,
20
- currentBaseURL : "https://test.github.io/project/latest/"
21
- } ) ?. href ,
22
- "https://test.github.io/project/0.1/bar/#heading?param=some" ,
23
- )
24
- assert . equal (
25
- selectedVersionCorrespondingURL ( {
26
- selectedVersionSitemap : sitemapFromURLList ( sitemapURLsV1 ) ,
27
- selectedVersionBaseURL : new URL ( "https://test.github.io/project/0.1/" ) ,
28
- currentLocation : new URL ( "https://test.github.io/project/latest/notinv1/" ) ,
29
- currentBaseURL : "https://test.github.io/project/latest/"
30
- } ) ,
31
- undefined ,
32
- )
8
+ // These examples are obtained by pausing the JS debugger in various situation and
9
+ // observing the local variables.
10
+ describe ( "Normal deployed to GitHub situation" , ( ) => {
11
+ const sitemapURLsV1 = [
12
+ "https://test.github.io/project/0.1/" ,
13
+ "https://test.github.io/project/0.1/bar/" ,
14
+ "https://test.github.io/project/0.1/foo/"
15
+ ]
16
+
17
+ it ( "returns a URL when the selected version has the current page" , ( ) => {
18
+ assert . equal (
19
+ selectedVersionCorrespondingURL ( {
20
+ selectedVersionSitemap : sitemapFromURLList ( sitemapURLsV1 ) ,
21
+ selectedVersionBaseURL : new URL (
22
+ "https://test.github.io/project/0.1/" ,
23
+ ) ,
24
+ currentLocation : new URL ( "https://test.github.io/project/0.2/bar/#heading?param=some" ) ,
25
+ currentBaseURL : "https://test.github.io/project/0.2/"
26
+ } ) ?. href ,
27
+ "https://test.github.io/project/0.1/bar/#heading?param=some" ,
28
+ )
29
+ } )
30
+ it ( "returns nothing when the selected version does not have the current page" , ( ) => {
31
+ assert . equal (
32
+ selectedVersionCorrespondingURL ( {
33
+ selectedVersionSitemap : sitemapFromURLList ( sitemapURLsV1 ) ,
34
+ selectedVersionBaseURL : new URL (
35
+ "https://test.github.io/project/0.1/" ,
36
+ ) ,
37
+ currentLocation : new URL (
38
+ "https://test.github.io/project/0.2/notinv1/#heading?param=some" ,
39
+ ) ,
40
+ currentBaseURL : "https://test.github.io/project/0.2/"
41
+ } ) ,
42
+ undefined ,
43
+ )
44
+ } )
45
+ } )
46
+
47
+ describe ( "Deployed to GitHub with canonical_version='latest'" , ( ) => {
48
+ // https://github.com/squidfunk/mkdocs-material/issues/7226 If the target
49
+ // version has `canonical_version='latest'`, then the sitemap looks as though
50
+ // it was for the "latest" version
51
+ const sitemapURLsLatestVersion = [
52
+ "https://test.github.io/project/latest/" ,
53
+ "https://test.github.io/project/latest/bar/" ,
54
+ "https://test.github.io/project/latest/foo/"
55
+ ]
56
+
57
+ it ( "does not (yet, TODO #7226) return a URL when the selected version has the current page" , ( ) => {
58
+ assert . equal (
59
+ selectedVersionCorrespondingURL ( {
60
+ selectedVersionSitemap : sitemapFromURLList ( sitemapURLsLatestVersion ) ,
61
+ selectedVersionBaseURL : new URL (
62
+ "https://test.github.io/project/0.1/" ,
63
+ ) ,
64
+ currentLocation : new URL ( "https://test.github.io/project/0.2/bar/#heading?param=some" ) ,
65
+ currentBaseURL : "https://test.github.io/project/0.2/"
66
+ } ) ?. href ,
67
+ undefined ,
68
+ )
69
+ } )
70
+ it ( "returns nothing when the selected version does not have the current page" , ( ) => {
71
+ assert . equal (
72
+ selectedVersionCorrespondingURL ( {
73
+ selectedVersionSitemap : sitemapFromURLList ( sitemapURLsLatestVersion ) ,
74
+ selectedVersionBaseURL : new URL (
75
+ "https://test.github.io/project/0.1/" ,
76
+ ) ,
77
+ currentLocation : new URL (
78
+ "https://test.github.io/project/0.2/notinv1/#heading?param=some" ,
79
+ ) ,
80
+ currentBaseURL : "https://test.github.io/project/0.2/"
81
+ } ) ,
82
+ undefined ,
83
+ )
84
+ } )
85
+ } )
86
+
87
+ describe ( "Served from localhost with `mike serve`" , ( ) => {
88
+ // TODO: test how fetchSitemap converts the actual sitemap into this
89
+ const sitemapURLsLocalhost = [
90
+ "https://localhost/project/0.1/" ,
91
+ "https://localhost/project/0.1/bar/" ,
92
+ "https://localhost/project/0.1/foo/"
93
+ ]
94
+
95
+ it ( "does not (yet, TODO) return a URL when the selected version has the current page" , ( ) => {
96
+ assert . equal (
97
+ selectedVersionCorrespondingURL ( {
98
+ selectedVersionSitemap : sitemapFromURLList ( sitemapURLsLocalhost ) ,
99
+ selectedVersionBaseURL : new URL ( "https://localhost:8000/0.1/" ) ,
100
+ currentLocation : new URL ( "https://localhost:8000/0.2/bar/#heading?param=some" ) ,
101
+ currentBaseURL : "https://localhost:8000/0.2/"
102
+ } ) ?. href ,
103
+ undefined ,
104
+ )
105
+ } )
106
+ it ( "returns nothing when the selected version does not have the current page" , ( ) => {
107
+ assert . equal (
108
+ selectedVersionCorrespondingURL ( {
109
+ selectedVersionSitemap : sitemapFromURLList ( sitemapURLsLocalhost ) ,
110
+ selectedVersionBaseURL : new URL ( "https://localhost:8000/0.1/" ) ,
111
+ currentLocation : new URL ( "https://localhost:8000/0.2/notinv1/#heading?param=some" ) ,
112
+ currentBaseURL : "https://localhost:8000/0.2/"
113
+ } ) ,
114
+ undefined ,
115
+ )
116
+ } )
33
117
} )
34
118
} )
35
119
0 commit comments