Files
lunch/tests/kitchen.test.ts
T
Kai BöhmandClaude Opus 5.5 8387a305e8
ci / olares chart · sanity (pull_request) Successful in 4s
ci / app · types + tests + build (pull_request) Successful in 3m4s
markt / eintrag (pull_request) Successful in 26s
ci / oberfläche · Browser am iPhone (pull_request) Successful in 7m23s
Add presentation mode and a read-only kitchen display (26.11.28)
Every recipe can be presented in large type, portrait on the phone and side
by side in landscape on a tablet or Echo Show: ingredients in the chosen
portions, then step by step with per-step amounts and timers. Tap the left
third to go back, anywhere else to go forward, or swipe; wake lock keeps the
screen on.

An admin unlocks a kitchen display with a one-time link (kid_devices with
kind 'kitchen', cookie lunch_kueche). It has no session: it reads the next
planned dishes and all recipes of its household, every other page leads to
/kueche and every API answers 401. Kid sign-in only accepts kind 'kids'.

Cooking mode and presentation share components/cooking/kit.tsx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUc2nv7rJVU2gp3Bgtha3q
2026-11-07 09:54:12 +00:00

60 lines
2.7 KiB
TypeScript

import { randomUUID } from "node:crypto";
import pg from "pg";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import { seedHousehold } from "./fixture";
vi.mock("server-only", () => ({}));
vi.mock("next/headers", () => ({ cookies: async () => ({ get: () => undefined, has: () => false }) }));
// lib/kitchen.ts: Was zeigt das Küchendisplay unter „Als Nächstes“? Die noch
// nicht gekochten Gerichte der laufenden Runde in Reihenfolge — nichts, solange
// die Runde noch gewünscht wird.
const url = process.env.TEST_DATABASE_URL;
describe.skipIf(!url)("kitchen display", () => {
const client = new pg.Client({ connectionString: url });
const h = randomUUID();
let roundId = "";
let kitchen: typeof import("@/lib/kitchen");
let db: typeof import("@/lib/db");
const as = <T>(fn: (c: pg.PoolClient) => Promise<T>) => db.withHousehold(h, fn);
beforeAll(async () => {
process.env.DATABASE_URL = url;
await client.connect();
const ingredient = (await client.query("select id from ingredients limit 1")).rows[0].id;
await seedHousehold(client, h, ingredient);
kitchen = await import("@/lib/kitchen");
db = await import("@/lib/db");
await as(async (c) => {
await c.query("update rounds set status = 'done'");
roundId = (await c.query("insert into rounds (household_id, slots_count, default_portions, status) values ($1, 3, 4, 'open') returning id", [h])).rows[0].id;
for (const [i, t] of ["Pizza", "Curry", "Suppe"].entries()) {
const d = (await c.query("insert into dishes (household_id, title) values ($1, $2) returning id", [h, t])).rows[0].id;
await c.query("insert into slots (household_id, round_id, position, dish_id, portions) values ($1, $2, $3, $4, $5)", [h, roundId, i + 1, d, 3 + i]);
}
});
});
afterAll(async () => {
await client.end();
await db.pool.end();
});
it("shows nothing while the round is still being wished", async () => {
expect(await as(kitchen.upcoming)).toEqual([]);
});
it("lists the uncooked dishes of a planned round in order, with their portions", async () => {
await as((c) => c.query("update rounds set status = 'shopping' where id = $1", [roundId]));
expect((await as(kitchen.upcoming)).map((d) => [d.title, d.portions])).toEqual([["Pizza", 3], ["Curry", 4], ["Suppe", 5]]);
await as((c) => c.query("update slots set cooked_at = now() where position = 1 and round_id = $1", [roundId]));
expect((await as(kitchen.upcoming)).map((d) => d.title)).toEqual(["Curry", "Suppe"]);
});
it("the overview carries every dish of the pool", async () => {
const { dishes } = await as(kitchen.kitchenOverview);
expect(dishes.map((d) => d.title)).toEqual(expect.arrayContaining(["Curry", "Pizza", "Suppe"]));
});
});