Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Jul 9, 2024
1 parent b5eeff8 commit 4c7f11c
Showing 1 changed file with 109 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,116 @@ import { Sitemap } from "../sitemap"

import { selectedVersionCorrespondingURL } from "./correspondingPage"

const sitemapURLsV1 = [
"https://test.github.io/project/0.1/",
"https://test.github.io/project/0.1/bar/",
"https://test.github.io/project/0.1/foo/"
]

describe("Version switcher tests", () => {
it("selectedVersionCorrespondingURL test", () => {
assert.equal(
selectedVersionCorrespondingURL({
selectedVersionSitemap: sitemapFromURLList(sitemapURLsV1),
selectedVersionBaseURL: new URL("https://test.github.io/project/0.1/"),
currentLocation: new URL("https://test.github.io/project/latest/bar/#heading?param=some"),
currentBaseURL: "https://test.github.io/project/latest/"
})?.href,
"https://test.github.io/project/0.1/bar/#heading?param=some",
)
assert.equal(
selectedVersionCorrespondingURL({
selectedVersionSitemap: sitemapFromURLList(sitemapURLsV1),
selectedVersionBaseURL: new URL("https://test.github.io/project/0.1/"),
currentLocation: new URL("https://test.github.io/project/latest/notinv1/"),
currentBaseURL: "https://test.github.io/project/latest/"
}),
undefined,
)
// These examples are obtained by pausing the JS debugger in various situation and
// observing the local variables.
describe("Normal deployed to GitHub situation", () => {
const sitemapURLsV1 = [
"https://test.github.io/project/0.1/",
"https://test.github.io/project/0.1/bar/",
"https://test.github.io/project/0.1/foo/"
]

it("returns a URL when the selected version has the current page", () => {
assert.equal(
selectedVersionCorrespondingURL({
selectedVersionSitemap: sitemapFromURLList(sitemapURLsV1),
selectedVersionBaseURL: new URL(
"https://test.github.io/project/0.1/",
),
currentLocation: new URL("https://test.github.io/project/0.2/bar/#heading?param=some"),
currentBaseURL: "https://test.github.io/project/0.2/"
})?.href,
"https://test.github.io/project/0.1/bar/#heading?param=some",
)
})
it("returns nothing when the selected version does not have the current page", () => {
assert.equal(
selectedVersionCorrespondingURL({
selectedVersionSitemap: sitemapFromURLList(sitemapURLsV1),
selectedVersionBaseURL: new URL(
"https://test.github.io/project/0.1/",
),
currentLocation: new URL(
"https://test.github.io/project/0.2/notinv1/#heading?param=some",
),
currentBaseURL: "https://test.github.io/project/0.2/"
}),
undefined,
)
})
})

describe("Deployed to GitHub with canonical_version='latest'", () => {
// https://github.com/squidfunk/mkdocs-material/issues/7226 If the target
// version has `canonical_version='latest'`, then the sitemap looks as though
// it was for the "latest" version
const sitemapURLsLatestVersion = [
"https://test.github.io/project/latest/",
"https://test.github.io/project/latest/bar/",
"https://test.github.io/project/latest/foo/"
]

it("does not (yet, TODO #7226) return a URL when the selected version has the current page", () => {
assert.equal(
selectedVersionCorrespondingURL({
selectedVersionSitemap: sitemapFromURLList(sitemapURLsLatestVersion),
selectedVersionBaseURL: new URL(
"https://test.github.io/project/0.1/",
),
currentLocation: new URL("https://test.github.io/project/0.2/bar/#heading?param=some"),
currentBaseURL: "https://test.github.io/project/0.2/"
})?.href,
undefined,
)
})
it("returns nothing when the selected version does not have the current page", () => {
assert.equal(
selectedVersionCorrespondingURL({
selectedVersionSitemap: sitemapFromURLList(sitemapURLsLatestVersion),
selectedVersionBaseURL: new URL(
"https://test.github.io/project/0.1/",
),
currentLocation: new URL(
"https://test.github.io/project/0.2/notinv1/#heading?param=some",
),
currentBaseURL: "https://test.github.io/project/0.2/"
}),
undefined,
)
})
})

describe("Served from localhost with `mike serve`", () => {
// TODO: test how fetchSitemap converts the actual sitemap into this
const sitemapURLsLocalhost = [
"https://localhost/project/0.1/",
"https://localhost/project/0.1/bar/",
"https://localhost/project/0.1/foo/"
]

it("does not (yet, TODO) return a URL when the selected version has the current page", () => {
assert.equal(
selectedVersionCorrespondingURL({
selectedVersionSitemap: sitemapFromURLList(sitemapURLsLocalhost),
selectedVersionBaseURL: new URL("https://localhost:8000/0.1/"),
currentLocation: new URL("https://localhost:8000/0.2/bar/#heading?param=some"),
currentBaseURL: "https://localhost:8000/0.2/"
})?.href,
undefined,
)
})
it("returns nothing when the selected version does not have the current page", () => {
assert.equal(
selectedVersionCorrespondingURL({
selectedVersionSitemap: sitemapFromURLList(sitemapURLsLocalhost),
selectedVersionBaseURL: new URL("https://localhost:8000/0.1/"),
currentLocation: new URL("https://localhost:8000/0.2/notinv1/#heading?param=some"),
currentBaseURL: "https://localhost:8000/0.2/"
}),
undefined,
)
})
})
})

Expand Down

0 comments on commit 4c7f11c

Please sign in to comment.