2026-08-22 04:28:13 +03:00
|
|
|
|
/**
|
2026-08-22 05:02:15 +03:00
|
|
|
|
* Composer render tests — the chat input row (content only; the persistent
|
|
|
|
|
|
* rounded shell lives in the chat view's overlay so it can morph into the
|
|
|
|
|
|
* question dock without remounting).
|
2026-08-22 04:28:13 +03:00
|
|
|
|
*
|
|
|
|
|
|
* Same tsx classic-JSX shim as render-cards.test.tsx.
|
|
|
|
|
|
*/
|
|
|
|
|
|
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-19 13:16:34 +03:00
|
|
|
|
import { Composer, enterAction } from "../components/composer.tsx";
|
2026-08-22 04:28:13 +03:00
|
|
|
|
|
2026-09-24 19:21:03 +03:00
|
|
|
|
function render(opts: { busy?: boolean; canSend?: boolean; placeholder?: string } = {}) {
|
2026-08-22 04:28:13 +03:00
|
|
|
|
return renderToStaticMarkup(
|
|
|
|
|
|
<Composer
|
|
|
|
|
|
busy={opts.busy ?? false}
|
|
|
|
|
|
value=""
|
|
|
|
|
|
onChange={() => {}}
|
|
|
|
|
|
onSend={() => {}}
|
|
|
|
|
|
onStop={() => {}}
|
|
|
|
|
|
canSend={opts.canSend ?? true}
|
2026-09-24 19:21:03 +03:00
|
|
|
|
{...(opts.placeholder ? { placeholder: opts.placeholder } : {})}
|
2026-08-22 04:28:13 +03:00
|
|
|
|
/>,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-22 05:02:15 +03:00
|
|
|
|
describe("Composer", () => {
|
|
|
|
|
|
it("chat placeholder + send button", () => {
|
|
|
|
|
|
const html = render();
|
2026-09-24 19:21:03 +03:00
|
|
|
|
assert.match(html, /Ask, answer, or steer the lesson/, "the default — active sessions");
|
2026-08-22 04:28:13 +03:00
|
|
|
|
assert.ok(html.includes('aria-label="Send"'), "send button present");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-09-24 19:21:03 +03:00
|
|
|
|
it("placeholder is overridable — the new-session page asks the graph view's question", () => {
|
|
|
|
|
|
const html = render({ placeholder: "What do you want to learn?" });
|
|
|
|
|
|
assert.match(html, /What do you want to learn\?/);
|
|
|
|
|
|
assert.ok(!html.includes("Ask, answer"), "the session placeholder must not ride along");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-03 03:07:49 +03:00
|
|
|
|
it("busy with text: the button STAYS Send (click = steer); busy and empty: it becomes Stop", () => {
|
|
|
|
|
|
const steering = render({ busy: true, canSend: true });
|
|
|
|
|
|
assert.ok(steering.includes('aria-label="Send"'), "the steer affordance is clickable mid-turn");
|
|
|
|
|
|
assert.ok(!steering.includes('aria-label="Stop"'), "no morph while there is text to steer with");
|
|
|
|
|
|
const idleStop = render({ busy: true, canSend: false });
|
|
|
|
|
|
assert.ok(idleStop.includes('aria-label="Stop"'), "empty composer: stop replaces send while streaming");
|
2026-08-22 04:28:13 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-08-22 05:02:15 +03:00
|
|
|
|
it("send button radius is 10px = 25% of the 40px button (concentric with the shell)", () => {
|
|
|
|
|
|
const html = render();
|
|
|
|
|
|
assert.ok(html.includes("rounded-[10px]"), "send radius = shell radius − row padding");
|
2026-08-22 04:28:13 +03:00
|
|
|
|
assert.ok(html.includes("size-10"), "40px send button (10px = 25%)");
|
|
|
|
|
|
});
|
2026-08-22 05:02:15 +03:00
|
|
|
|
|
|
|
|
|
|
it("disabled when nothing to send", () => {
|
|
|
|
|
|
const html = render({ canSend: false });
|
|
|
|
|
|
assert.ok(/aria-label="Send"[^>]*disabled|disabled[^>]*aria-label="Send"/.test(html), "send disabled");
|
|
|
|
|
|
});
|
2026-08-22 04:28:13 +03:00
|
|
|
|
});
|
2026-09-19 13:16:34 +03:00
|
|
|
|
|
2026-10-03 03:01:51 +03:00
|
|
|
|
// The Enter decision (composer steering, 2026-10-03): while a turn runs,
|
|
|
|
|
|
// typed text makes Enter a STEER; Enter with an empty composer stays the
|
|
|
|
|
|
// stop shortcut. (The plan-verdict accept branch died 2026-09-26 with the
|
|
|
|
|
|
// verdict itself — the post-plan reply is a natural text message.) Pure
|
|
|
|
|
|
// function so the static-render harness can pin it (key events can't be
|
|
|
|
|
|
// simulated in renderToStaticMarkup).
|
2026-09-19 13:16:34 +03:00
|
|
|
|
describe("enterAction", () => {
|
2026-10-03 03:01:51 +03:00
|
|
|
|
it("busy stream with text: Enter steers (the queued send)", () => {
|
|
|
|
|
|
assert.equal(enterAction({ busy: true, canSend: true }), "send");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("busy stream, empty composer: Enter stops", () => {
|
|
|
|
|
|
assert.equal(enterAction({ busy: true, canSend: false }), "stop");
|
2026-09-19 13:16:34 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-09-27 00:20:07 +03:00
|
|
|
|
it("idle: send when there is text, nothing when there is not", () => {
|
|
|
|
|
|
assert.equal(enterAction({ busy: false, canSend: true }), "send");
|
|
|
|
|
|
assert.equal(enterAction({ busy: false, canSend: false }), "none");
|
2026-09-19 13:16:34 +03:00
|
|
|
|
});
|
|
|
|
|
|
});
|