Files
DeepTutor/web/tests/mastery-study-route.test.ts
Bingxi Zhao (Frank) da856ad670 release: v1.6.9
Ship folder-based workspaces and data migration, daily practice, redesigned
provider and model settings, and streaming conversation improvements.
Synchronize README translations and document the archive/permanent-delete
upgrade behavior in assets/releases/ver1-6-9.md.

Reduce initial JavaScript by deduplicating English resources and loading
animation features after hydration. Keep the existing route size budgets.
Update regression fixtures and browser audits for scoped URLs and the new
settings and learning interfaces.
2026-09-21 02:30:40 +08:00

78 lines
2.0 KiB
TypeScript

import assert from "node:assert/strict";
import path from "node:path";
import test from "node:test";
import { isMasteryDraftSessionReady } from "../lib/mastery-study-route";
const base = {
guard: {
routeKey: "topic-a:new",
previousSessionId: "session-old",
},
routeKey: "topic-a:new",
masteryPathId: "topic-a",
pathId: "topic-a",
};
test("a stale previous session cannot bounce a new-study route backwards", () => {
assert.equal(
isMasteryDraftSessionReady({ ...base, sessionId: "session-old" }),
false,
);
});
test("the backend-bound draft session is promoted into the route", () => {
assert.equal(
isMasteryDraftSessionReady({ ...base, sessionId: "session-new" }),
true,
);
});
test("a route or topic switch invalidates an older draft guard", () => {
assert.equal(
isMasteryDraftSessionReady({
...base,
routeKey: "topic-b:new",
sessionId: "session-new",
}),
false,
);
assert.equal(
isMasteryDraftSessionReady({
...base,
masteryPathId: "topic-b",
sessionId: "session-new",
}),
false,
);
});
test("an unbound draft stays on the sessionless study route", () => {
assert.equal(isMasteryDraftSessionReady({ ...base, sessionId: null }), false);
});
test("legacy /mastery/.../study URLs permanently redirect to /sessions", async () => {
const nextConfig = require(path.resolve(process.cwd(), "next.config.js")) as {
redirects?: () => Promise<
Array<{ source: string; destination: string; statusCode: number }>
>;
};
assert.equal(typeof nextConfig.redirects, "function");
const redirects = await nextConfig.redirects!();
assert.deepEqual(
redirects.filter((entry) => entry.source.includes("/study")),
[
{
source: "/mastery/:pathId/study",
destination: "/learning/mastery/:pathId/sessions",
statusCode: 301,
},
{
source: "/mastery/:pathId/study/:sessionId",
destination: "/learning/mastery/:pathId/sessions/:sessionId",
statusCode: 301,
},
],
);
});