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-08-22 05:02:15 +03:00
|
|
|
|
function render(opts: { busy?: boolean; canSend?: boolean } = {}) {
|
2026-08-22 04:28:13 +03:00
|
|
|
|
return renderToStaticMarkup(
|
|
|
|
|
|
<Composer
|
|
|
|
|
|
busy={opts.busy ?? false}
|
|
|
|
|
|
value=""
|
|
|
|
|
|
onChange={() => {}}
|
|
|
|
|
|
onSend={() => {}}
|
|
|
|
|
|
onStop={() => {}}
|
|
|
|
|
|
canSend={opts.canSend ?? true}
|
|
|
|
|
|
/>,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-22 05:02:15 +03:00
|
|
|
|
describe("Composer", () => {
|
|
|
|
|
|
it("chat placeholder + send button", () => {
|
|
|
|
|
|
const html = render();
|
2026-08-22 04:28:13 +03:00
|
|
|
|
assert.match(html, /Ask, answer, or steer the lesson/);
|
|
|
|
|
|
assert.ok(html.includes('aria-label="Send"'), "send button present");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("busy: send button becomes stop", () => {
|
2026-08-22 05:02:15 +03:00
|
|
|
|
const html = render({ busy: true });
|
2026-08-22 04:28:13 +03:00
|
|
|
|
assert.ok(html.includes('aria-label="Stop"'), "stop replaces send while streaming");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
// The Enter decision (user-decided 2026-09-19, docs/probe-teach-split.md §4):
|
|
|
|
|
|
// while the plan verdict pends, Enter must ACCEPT the plan — formerly it sent
|
|
|
|
|
|
// a plain message, leaving the verdict pending again on the next message.
|
|
|
|
|
|
// Pure function so the static-render harness can pin it (key events can't be
|
|
|
|
|
|
// simulated in renderToStaticMarkup).
|
|
|
|
|
|
describe("enterAction", () => {
|
|
|
|
|
|
it("busy stream: Enter stops — verdict or not", () => {
|
|
|
|
|
|
assert.equal(enterAction({ busy: true, verdictPending: false, canSend: true }), "stop");
|
|
|
|
|
|
assert.equal(enterAction({ busy: true, verdictPending: true, canSend: true }), "stop");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("verdict pends: Enter ACCEPTS — with text (the note rides) and with an empty box alike", () => {
|
|
|
|
|
|
assert.equal(enterAction({ busy: false, verdictPending: true, canSend: true }), "accept", "typed text rides the acceptance note");
|
|
|
|
|
|
assert.equal(enterAction({ busy: false, verdictPending: true, canSend: false }), "accept", "empty box still accepts — Enter can never strand the verdict");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("no verdict: send when there is text, nothing when there is not", () => {
|
|
|
|
|
|
assert.equal(enterAction({ busy: false, verdictPending: false, canSend: true }), "send");
|
|
|
|
|
|
assert.equal(enterAction({ busy: false, verdictPending: false, canSend: false }), "none");
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|