Files
heidi/lib/domain/practice/session-progress.test.ts
CatoandClaude 45e179efd9 feat(design): a fixed session total, one opening for the inner pages, softer dark mode, and a photograph on the home page (#353)
* fix(session): the total of a sitting does not change while it runs

The counter read 1/8, then 2/9, then 4/10: a missed question is put back
into the queue, and the screen counted the queue. The finish line moved
away every time the learner got something wrong.

`sittingProgress` (pure, with a test) reads the plan from the queue: the
total is the distinct questions and stays fixed, the number is the last new
question reached, and second attempts still to come are shown beside the
counter as their own figure («+1 Wiederholung»), never added to it. The
resume label on the practice page counts the same way.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* feat(design): the pages a learner works in open the same way, and dark mode loses its white hairlines

Situations, grammar, vocabulary, speaking and listening open like practice
does: a heavy title on the sky ground that fades into the page, through the
shared `BandHeader` (`tone="sky"`), not five copies. The grey hide patches
no longer sit behind those titles, and the index cards on situations and
grammar are the shared `card`.

In dark mode `border-strong` was pure white, so every outlined box was the
loudest thing on the screen. It is a grey token now; text stays white.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* feat(home): the first screen is Zürich — a photograph by day, another at blue hour

The home page opens with one photograph: Lake Zurich and the Alps in the
light theme, the Limmat at blue hour in the dark one. It runs edge to edge
and fades into the sky ground, so the headline stays on the tokens' own
colour and its contrast does not depend on the picture. On a wide screen
the chat card is lifted onto the picture's lower edge. The cow is the
mascot beside the three steps again, small, on every screen.

Both pictures are from Wikimedia Commons under CC BY (4.0, albinfo; 2.0,
kuhnmi), cropped and resized to 1600px WebP, about 130 KB each. A typed
registry in lib/config/photos.ts holds file, page, author, licence and
licence link; the Impressum lists every entry and the home page credits
the picture it shows. A test fails on a photo without author, licence or
page, on a licence outside the allowed kinds, on a missing or oversized
file, and on a missing alt text in any of the seven languages.

`next/image` as its documentation describes a themed picture: two lazy
images, the theme's stylesheet decides which is displayed, the hidden one
is never fetched, and the shown one carries fetchPriority="high".

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-25 12:57:41 +01:00

58 lines
2.6 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { requeue, sittingProgress } from "./session.ts";
import type { PracticeItem } from "./types.ts";
const item = (id: string) => ({ id }) as PracticeItem;
const PLAN = ["a", "b", "c", "d", "e", "f", "g", "h"];
/** Drives a sitting the way the session screen does: answer, requeue a miss, step on. */
function run(plan: readonly string[], wrong: ReadonlySet<number>) {
let queue = plan.map(item);
const asked: string[] = [];
const seen: ReturnType<typeof sittingProgress>[] = [];
for (let at = 0; at < queue.length; at++) {
seen.push(sittingProgress(queue.map((i) => i.id), at));
if (wrong.has(at)) {
queue = [...queue.slice(0, at + 1), ...requeue({ remaining: queue.slice(at + 1), item: queue[at], asked })];
}
asked.push(queue[at].id);
}
return { seen, end: sittingProgress(queue.map((i) => i.id), queue.length), length: queue.length };
}
test("the total does not change while a sitting runs, however many are missed", () => {
// It read 1/8, 2/9, 4/10: the queue grew with every miss and the counter counted the queue.
const { seen, length } = run(PLAN, new Set([0, 1, 7]));
assert.equal(length, 11, "three misses came back once each");
assert.deepEqual([...new Set(seen.map((s) => s.total))], [8]);
});
test("the number never goes backwards and never passes the total", () => {
const { seen } = run(PLAN, new Set([0, 1, 2, 3, 4, 5, 6, 7]));
for (let i = 1; i < seen.length; i++) assert.ok(seen[i].n >= seen[i - 1].n, `step ${i} went back`);
assert.ok(seen.every((s) => s.n >= 1 && s.n <= s.total));
});
test("a miss is counted beside the total, as a repeat still to come", () => {
const { seen } = run(PLAN, new Set([0]));
assert.deepEqual(seen[0], { n: 1, done: 0, total: 8, repeats: 0 });
// Missed: it waits three questions on, and says so.
assert.deepEqual(seen[1], { n: 2, done: 1, total: 8, repeats: 1 });
// ON the second attempt: the number is the last new question reached.
assert.deepEqual(seen[4], { n: 4, done: 4, total: 8, repeats: 1 });
// Past it: nothing waiting, and the count goes on from where it was.
assert.deepEqual(seen[5], { n: 5, done: 4, total: 8, repeats: 0 });
});
test("a sitting without a miss counts exactly as before", () => {
const { seen, end } = run(PLAN, new Set());
assert.deepEqual(seen.map((s) => s.n), [1, 2, 3, 4, 5, 6, 7, 8]);
assert.ok(seen.every((s) => s.repeats === 0));
assert.deepEqual(end, { n: 8, done: 8, total: 8, repeats: 0 });
});
test("an empty queue is not a division by zero", () => {
assert.deepEqual(sittingProgress([], 0), { n: 1, done: 0, total: 0, repeats: 0 });
});