Files
lunch/tests/onboarding.test.ts
kai c4ba00807b
release / which version (push) Successful in 2s
release / olares chart · sanity (push) Successful in 4s
release / app (push) Successful in 1m5s
release / tag and release (push) Successful in 2s
Guide new households and every round: getting started, where are we (26.11.27) (#28)
2026-11-07 09:25:03 +00:00

55 lines
2.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { checklistState, nextAction, roundStage, setupSteps } from "@/lib/onboarding";
const fresh = { poolDishes: 0, hasStore: false, people: 1, openInvites: 0, rounds: 0, skipped: [] };
describe("getting started", () => {
it("ticks steps off from the data, in Kai's order", () => {
expect(setupSteps(fresh).map((s) => [s.key, s.done])).toEqual([
["dishes", false],
["store", false],
["family", false],
["round", false],
]);
const s = setupSteps({ ...fresh, poolDishes: 3, hasStore: true, openInvites: 1 });
expect(s[0]).toMatchObject({ done: false, n: 3, of: 5 });
expect(s[1]!.done && s[2]!.done).toBe(true);
expect(setupSteps({ ...fresh, skipped: ["family"] })[2]).toMatchObject({ done: true, skipped: true });
});
it("shows the list, then 'finished' once, then nothing", () => {
const all = setupSteps({ poolDishes: 7, hasStore: true, people: 3, openInvites: 0, rounds: 1, skipped: [] });
expect(checklistState(setupSteps(fresh), { hidden: false, finishedSeen: false })).toBe("show");
expect(checklistState(all, { hidden: false, finishedSeen: false })).toBe("finished");
expect(checklistState(all, { hidden: false, finishedSeen: true })).toBe("none");
expect(checklistState(setupSteps(fresh), { hidden: true, finishedSeen: false })).toBe("none");
});
});
describe("where the round stands", () => {
const r = (status: "open" | "planned" | "shopping" | "done" | null, slots = 0, cooked = 0, toRate = 0) => roundStage({ status, slots, cooked, toRate });
it("follows the round from wishing to rating", () => {
expect(r(null)).toBeNull();
expect(r("open")).toBe("wish");
expect(r("open", 4)).toBe("plan");
expect(r("planned", 4)).toBe("shop");
expect(r("shopping", 4)).toBe("shop");
expect(r("shopping", 4, 1)).toBe("cook");
expect(r("shopping", 4, 1, 1)).toBe("rate");
expect(r(null, 0, 0, 2)).toBe("rate");
});
it("says what is next for each person", () => {
const adult = { planner: true, shopper: true, cook: true, child: false };
const child = { planner: false, shopper: false, cook: false, child: true };
const extra = { tokensLeft: 2, nextSlotId: "s1", nextTitle: "Curry" };
expect(nextAction(null, adult, extra)).toMatchObject({ key: "openRound", href: "/runde/neu" });
expect(nextAction(null, child, extra)).toMatchObject({ key: "waitRound", href: null });
expect(nextAction("wish", child, extra)).toMatchObject({ key: "wish", values: { n: 2 } });
expect(nextAction("wish", adult, { ...extra, tokensLeft: 0 })).toMatchObject({ key: "makePlan" });
expect(nextAction("plan", child, extra)).toMatchObject({ key: "planComing", href: null });
expect(nextAction("cook", adult, extra)).toMatchObject({ key: "cook", href: "/kochen/s1", values: { title: "Curry" } });
expect(nextAction("shop", child, extra)).toMatchObject({ key: "shopping", href: null });
});
});