Skip to content

Commit a8e7b4d

Browse files
authored
add tests to #1022 (#1045)
1 parent 336a949 commit a8e7b4d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/pager-test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assert from "node:assert";
2+
import {normalizeConfig} from "../src/config.js";
23
import {findLink as pager} from "../src/pager.js";
34

45
describe("findLink(path, options)", () => {
@@ -92,4 +93,35 @@ describe("findLink(path, options)", () => {
9293
assert.deepStrictEqual(pager("/b", config), {prev: {name: "a", path: "/a"}, next: {name: "c", path: "/c"}});
9394
assert.deepStrictEqual(pager("/c", config), {prev: {name: "b", path: "/b"}, next: undefined});
9495
});
96+
it("normalizes / to /index", async () => {
97+
const config = await normalizeConfig({pages: [{name: "Home", path: "/"}]});
98+
assert.strictEqual(pager("/index", config), undefined);
99+
assert.strictEqual(pager("/", config), undefined);
100+
});
101+
it("normalizes / to /index (2)", async () => {
102+
const config = await normalizeConfig({
103+
pages: [
104+
{name: "Home", path: "/"},
105+
{name: "Second Home", path: "/second"}
106+
]
107+
});
108+
assert.deepStrictEqual(pager("/second", config), {next: undefined, prev: {name: "Home", path: "/index"}});
109+
assert.deepStrictEqual(pager("/index", config), {next: {name: "Second Home", path: "/second"}, prev: undefined});
110+
assert.strictEqual(pager("/", config), undefined);
111+
});
112+
it("normalizes / to /index (3)", async () => {
113+
const config = await normalizeConfig({
114+
pages: [
115+
{name: "Home", path: "/"},
116+
{name: "Second Home", path: "/second"},
117+
{name: "By The Sea", path: "/by-the-sea"}
118+
]
119+
});
120+
assert.deepStrictEqual(pager("/second", config), {
121+
next: {name: "By The Sea", path: "/by-the-sea"},
122+
prev: {name: "Home", path: "/index"}
123+
});
124+
assert.deepStrictEqual(pager("/index", config), {next: {name: "Second Home", path: "/second"}, prev: undefined});
125+
assert.strictEqual(pager("/", config), undefined);
126+
});
95127
});

0 commit comments

Comments
 (0)