@@ -2,7 +2,7 @@ import { strict as assert } from "assert"
2
2
3
3
import { Sitemap } from "../sitemap"
4
4
5
- import { selectedVersionCorrespondingURL } from "./correspondingPage"
5
+ import { selectedVersionCorrespondingURL , shortestCommonPrefix , stripPrefix } from "./correspondingPage"
6
6
7
7
describe ( "Version switcher tests" , ( ) => {
8
8
// These examples are obtained by pausing the JS debugger in various situation and
@@ -54,7 +54,7 @@ describe("Version switcher tests", () => {
54
54
"https://test.github.io/project/latest/foo/"
55
55
]
56
56
57
- it ( "does not (yet, TODO #7226) return a URL when the selected version has the current page" , ( ) => {
57
+ it ( "returns a URL when the selected version has the current page" , ( ) => {
58
58
assert . equal (
59
59
selectedVersionCorrespondingURL ( {
60
60
selectedVersionSitemap : sitemapFromURLList ( sitemapURLsLatestVersion ) ,
@@ -64,7 +64,7 @@ describe("Version switcher tests", () => {
64
64
currentLocation : new URL ( "https://test.github.io/project/0.2/bar/#heading?param=some" ) ,
65
65
currentBaseURL : "https://test.github.io/project/0.2/"
66
66
} ) ?. href ,
67
- undefined ,
67
+ "https://test.github.io/project/0.1/bar/#heading?param=some" ,
68
68
)
69
69
} )
70
70
it ( "returns nothing when the selected version does not have the current page" , ( ) => {
@@ -92,15 +92,15 @@ describe("Version switcher tests", () => {
92
92
"https://localhost/project/0.1/foo/"
93
93
]
94
94
95
- it ( "does not (yet, TODO) return a URL when the selected version has the current page" , ( ) => {
95
+ it ( "returns a URL when the selected version has the current page" , ( ) => {
96
96
assert . equal (
97
97
selectedVersionCorrespondingURL ( {
98
98
selectedVersionSitemap : sitemapFromURLList ( sitemapURLsLocalhost ) ,
99
99
selectedVersionBaseURL : new URL ( "https://localhost:8000/0.1/" ) ,
100
100
currentLocation : new URL ( "https://localhost:8000/0.2/bar/#heading?param=some" ) ,
101
101
currentBaseURL : "https://localhost:8000/0.2/"
102
102
} ) ?. href ,
103
- undefined ,
103
+ "https://localhost:8000/0.1/bar/#heading?param=some" ,
104
104
)
105
105
} )
106
106
it ( "returns nothing when the selected version does not have the current page" , ( ) => {
@@ -130,3 +130,16 @@ describe("Version switcher tests", () => {
130
130
function sitemapFromURLList ( urls : string [ ] ) : Sitemap {
131
131
return new Map ( urls . map ( url => [ url , [ new URL ( url ) ] ] ) )
132
132
}
133
+
134
+ describe ( "Utility string processing function tests" , ( ) => {
135
+ it ( "shortestCommonPrefix" , ( ) => {
136
+ assert . equal ( shortestCommonPrefix ( [ ] ) , "" )
137
+ assert . equal ( shortestCommonPrefix ( [ "abc" , "abcd" , "abe" ] ) , "ab" )
138
+ assert . equal ( shortestCommonPrefix ( [ "abcef" , "abcd" , "abc" ] ) , "abc" )
139
+ assert . equal ( shortestCommonPrefix ( [ "" , "abc" ] ) , "" )
140
+ } )
141
+ it ( "stripPrefix" , ( ) => {
142
+ assert . equal ( stripPrefix ( "abc" , "ab" ) , "c" )
143
+ assert . equal ( stripPrefix ( "abc" , "b" ) , undefined )
144
+ } )
145
+ } )
0 commit comments