2026-09-01 18:28:35 +03:00
|
|
|
/**
|
2026-09-15 17:01:01 +03:00
|
|
|
* Session-row render tests — the picker's status language (owner,
|
|
|
|
|
* minimal-color round): ONE indicator, the braille spinner, present ONLY
|
|
|
|
|
* while a teach turn is in flight; every other state (idle, question
|
|
|
|
|
* pending) renders nothing — phases only advance, so phase-as-signal was
|
|
|
|
|
* decoration, and question-pending is the dominant RESTING state (the
|
|
|
|
|
* meta line's text carries it). Pure function of the list item, so SSR of
|
|
|
|
|
* <SessionRow> pins every visible state. Same tsx classic-JSX shim as
|
|
|
|
|
* render-cards.test.tsx.
|
2026-09-01 18:28:35 +03:00
|
|
|
*/
|
|
|
|
|
import React from "react";
|
|
|
|
|
(globalThis as Record<string, unknown>).React = React;
|
|
|
|
|
|
|
|
|
|
import assert from "node:assert/strict";
|
|
|
|
|
import { describe, it } from "node:test";
|
|
|
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
2026-09-01 19:49:47 +03:00
|
|
|
import { SessionRow, timeAgo } from "../components/sidebar.tsx";
|
2026-09-15 17:01:01 +03:00
|
|
|
import type { ChatListItem } from "../src/core/index.ts";
|
2026-09-01 18:28:35 +03:00
|
|
|
|
|
|
|
|
function item(overrides: Partial<ChatListItem>): ChatListItem {
|
|
|
|
|
return {
|
|
|
|
|
id: "c1",
|
|
|
|
|
title: "Test session",
|
|
|
|
|
createdAt: "2026-01-01T00:00:00.000Z",
|
|
|
|
|
updatedAt: "2026-01-02T00:00:00.000Z",
|
|
|
|
|
messageCount: 4,
|
|
|
|
|
phase: "probe",
|
|
|
|
|
pendingQuestion: false,
|
|
|
|
|
busy: false,
|
|
|
|
|
...overrides,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function render(chat: ChatListItem, active = false) {
|
|
|
|
|
return renderToStaticMarkup(<SessionRow chat={chat} active={active} onOpen={() => {}} />);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe("SessionRow", () => {
|
2026-09-15 17:01:01 +03:00
|
|
|
it("no phase strips, no phase colors — the retired decoration", () => {
|
2026-09-01 19:49:47 +03:00
|
|
|
const html = render(item({ phase: "teach" }));
|
|
|
|
|
assert.ok(!html.includes("phase-strip"), "strip removed by design (too busy)");
|
2026-09-15 17:01:01 +03:00
|
|
|
assert.ok(!html.includes("bg-phase-"), "phase fills are retired app-wide");
|
|
|
|
|
assert.ok(!html.includes("border-phase-"), "phase rings are retired app-wide");
|
2026-09-01 19:49:47 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-15 17:01:01 +03:00
|
|
|
it("idle session: NO indicator — absence is the state", () => {
|
|
|
|
|
for (const phase of ["probe", "plan", "teach"] as const) {
|
2026-09-01 18:28:35 +03:00
|
|
|
const html = render(item({ phase }));
|
2026-09-15 17:01:01 +03:00
|
|
|
assert.ok(!html.includes("session-dot"), "no dots — the status language is spinner-only");
|
|
|
|
|
assert.ok(!html.includes("braille-spinner"), "idle never shows the spinner");
|
2026-09-01 18:28:35 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-15 17:01:01 +03:00
|
|
|
it("a pending question renders NO indicator — resting state, carried by the meta text", () => {
|
2026-09-01 19:49:47 +03:00
|
|
|
const html = render(item({ phase: "teach", pendingQuestion: true }));
|
2026-09-15 17:01:01 +03:00
|
|
|
assert.ok(!html.includes("session-dot"), "no dots");
|
|
|
|
|
assert.ok(!html.includes("braille-spinner"), "motion is reserved for working");
|
|
|
|
|
assert.ok(html.includes("Waiting for your answer"), "the meta line's text");
|
2026-09-01 18:28:35 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-15 17:01:01 +03:00
|
|
|
it("a working session (turn in flight) renders the braille spinner — the ONLY indicator", () => {
|
2026-09-01 19:49:47 +03:00
|
|
|
const html = render(item({ phase: "plan", busy: true }));
|
2026-09-15 17:01:01 +03:00
|
|
|
assert.ok(html.includes('data-testid="braille-spinner"'), "the spinner");
|
|
|
|
|
assert.ok(html.includes("braille-frame"), "CSS-animated frames");
|
|
|
|
|
assert.ok((html.match(/class="braille-frame"/g) ?? []).length === 10, "all ten frames");
|
|
|
|
|
assert.ok(html.includes('data-frame="0"'), "frame 0 leads (static fallback)");
|
|
|
|
|
assert.ok(html.includes("Teacher is working"), "accessible label");
|
|
|
|
|
assert.ok(!html.includes("bg-attention"), "no colored state fill — monochrome by design");
|
2026-09-01 18:28:35 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-15 17:01:01 +03:00
|
|
|
it("busy does not double-signal background agents (that is the sidebar section's channel)", () => {
|
|
|
|
|
// The narrowing lives in the API route (busy = isTurnRunning only);
|
|
|
|
|
// the row itself just renders busy faithfully. Pinned here so the
|
|
|
|
|
// contract can't silently re-widen: an extraction-only "working"
|
|
|
|
|
// row would be a double signal.
|
|
|
|
|
const html = render(item({ busy: true, pendingQuestion: false }));
|
|
|
|
|
assert.ok(html.includes("Teacher is working"), "the spinner's label names the turn, not agents");
|
2026-09-01 18:28:35 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-01 19:49:47 +03:00
|
|
|
it("the meta line: state replaces the count when the state is the useful fact", () => {
|
|
|
|
|
const awaiting = render(item({ pendingQuestion: true, updatedAt: "2026-01-02T01:00:00.000Z" }));
|
|
|
|
|
assert.ok(awaiting.includes("Waiting for your answer · "), "awaiting meta");
|
|
|
|
|
assert.ok(!awaiting.includes("messages"), "count yields to the state");
|
2026-09-15 17:01:01 +03:00
|
|
|
assert.ok(!awaiting.includes("braille-spinner"), "…and the spinner stays off");
|
2026-09-01 19:49:47 +03:00
|
|
|
|
|
|
|
|
const working = render(item({ busy: true }));
|
|
|
|
|
assert.ok(working.includes("Teacher is working…"), "working meta");
|
|
|
|
|
|
2026-09-17 13:48:04 +03:00
|
|
|
// Owner, typography round 5: the message count is dropped — it
|
|
|
|
|
// informed no decision. Idle meta is just how long ago.
|
2026-09-01 19:49:47 +03:00
|
|
|
const idle = render(item({ title: "Partial derivatives", messageCount: 7 }));
|
|
|
|
|
assert.ok(idle.includes("Partial derivatives"));
|
2026-09-17 13:48:04 +03:00
|
|
|
assert.ok(!idle.includes("messages"), "the count is gone (flip-flop: one line in sessionMeta)");
|
|
|
|
|
assert.match(idle, /\d{4}-\d{2}-\d{2}/, "idle shows the ISO date");
|
2026-09-01 18:28:35 +03:00
|
|
|
});
|
|
|
|
|
|
2026-09-17 13:48:04 +03:00
|
|
|
it("active row is visually marked by the background alone (owner, round 5: no weight change)", () => {
|
2026-09-01 18:28:35 +03:00
|
|
|
const html = render(item({}), true);
|
2026-09-17 13:48:04 +03:00
|
|
|
assert.ok(html.includes("bg-accent"), "active background");
|
|
|
|
|
assert.ok(!html.includes("font-medium"), "weight is not a second channel doing the same job");
|
2026-09-01 18:28:35 +03:00
|
|
|
});
|
|
|
|
|
});
|
2026-09-01 19:49:47 +03:00
|
|
|
|
|
|
|
|
describe("timeAgo", () => {
|
|
|
|
|
const now = new Date("2026-01-02T12:00:00.000Z");
|
|
|
|
|
|
2026-09-17 13:48:04 +03:00
|
|
|
it("just now / minutes / hours / days, then the ISO date (owner, round 5)", () => {
|
2026-09-01 19:49:47 +03:00
|
|
|
assert.equal(timeAgo("2026-01-02T11:59:30.000Z", now), "just now");
|
|
|
|
|
assert.equal(timeAgo("2026-01-02T11:55:00.000Z", now), "5m ago");
|
|
|
|
|
assert.equal(timeAgo("2026-01-02T09:00:00.000Z", now), "3h ago");
|
|
|
|
|
assert.equal(timeAgo("2025-12-31T12:00:00.000Z", now), "2d ago");
|
2026-09-17 13:48:04 +03:00
|
|
|
assert.equal(timeAgo("2025-06-02T12:00:00.000Z", now), "2025-06-02", "beyond a week: ISO — unambiguous, sortable");
|
2026-09-01 19:49:47 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("negative drift (clock skew) reads as just now, never a future date", () => {
|
|
|
|
|
assert.equal(timeAgo("2026-01-02T12:01:00.000Z", now), "just now");
|
|
|
|
|
});
|
|
|
|
|
});
|