- Add buildFsAtSubStart so dev "Retry step" resets the current sub while keeping earlier subs complete; quiz screen clears the selected answer. - Stop adding hinted files' parent folders to click hints (avoids wrongly highlighting Downloads when already inside it). - Extend Playwright: localStorage reset, full playthrough through quiz, and a retry-step regression test. Add Vitest for buildFsAtSubStart. Made-with: Cursor
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
buildFsAtSubStart,
|
|
buildInitialFs,
|
|
isFsLevelComplete,
|
|
isQuizComplete,
|
|
isSubComplete,
|
|
QUIZ_CORRECT_ID,
|
|
} from "~/lib/folder-game/levels";
|
|
import { DESKTOP_ID } from "~/lib/folder-game/state";
|
|
|
|
describe("isFsLevelComplete", () => {
|
|
it("level 0 completes when Games and Documents were opened", () => {
|
|
const fs = buildInitialFs(0);
|
|
expect(isFsLevelComplete(0, fs)).toBe(false);
|
|
expect(
|
|
isFsLevelComplete(0, {
|
|
...fs,
|
|
visitedFolderIds: ["fld-games", "fld-docs"],
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("level 1 completes when files are sorted", () => {
|
|
const fs = buildInitialFs(1);
|
|
const nodes = fs.nodes.map((n) => {
|
|
if (n.id === "file-cat") return { ...n, parentId: "fld-pics" };
|
|
if (n.id === "file-hw") return { ...n, parentId: "fld-school" };
|
|
return n;
|
|
});
|
|
expect(isFsLevelComplete(1, { ...fs, nodes })).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("isSubComplete", () => {
|
|
it("level 0 sub 0 requires Games", () => {
|
|
const fs = buildInitialFs(0);
|
|
expect(isSubComplete(0, 0, fs)).toBe(false);
|
|
expect(
|
|
isSubComplete(0, 0, {
|
|
...fs,
|
|
visitedFolderIds: ["fld-games"],
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("isQuizComplete", () => {
|
|
it("accepts Documents choice", () => {
|
|
expect(isQuizComplete(QUIZ_CORRECT_ID)).toBe(true);
|
|
expect(isQuizComplete("opt-dl")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("buildFsAtSubStart", () => {
|
|
it("matches full initial state for sub 0", () => {
|
|
expect(buildFsAtSubStart(1, 0)).toEqual(buildInitialFs(1));
|
|
});
|
|
|
|
it("level 1 sub 1 start keeps cat sorted and homework on desktop", () => {
|
|
const fs = buildFsAtSubStart(1, 1);
|
|
expect(isSubComplete(1, 0, fs)).toBe(true);
|
|
expect(isSubComplete(1, 1, fs)).toBe(false);
|
|
const nodes = fs.nodes;
|
|
const cat = nodes.find((n) => n.id === "file-cat");
|
|
const hw = nodes.find((n) => n.id === "file-hw");
|
|
expect(cat?.parentId).toBe("fld-pics");
|
|
expect(hw?.parentId).toBe(DESKTOP_ID);
|
|
});
|
|
|
|
it("level 2 sub 2 start has beach and budget sorted, installer in downloads", () => {
|
|
const fs = buildFsAtSubStart(2, 2);
|
|
const beach = fs.nodes.find((n) => n.id === "f-beach");
|
|
const budget = fs.nodes.find((n) => n.id === "f-budget");
|
|
const game = fs.nodes.find((n) => n.id === "f-game");
|
|
expect(beach?.parentId).toBe("fld-photos");
|
|
expect(budget?.parentId).toBe("fld-work");
|
|
expect(game?.parentId).toBe("fld-downloads");
|
|
expect(isSubComplete(2, 0, fs)).toBe(true);
|
|
expect(isSubComplete(2, 1, fs)).toBe(true);
|
|
expect(isSubComplete(2, 2, fs)).toBe(false);
|
|
});
|
|
});
|