Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Done card: show each part of the request with its check (frontend for #619) (#626)

Oleksandr Ivanchenkocf1e2d575082
diff --git a/frontend/src/components/DoneCheck.tsx b/frontend/src/components/DoneCheck.tsx
index 2cfe58ee..a6be4bc3 100644
--- a/frontend/src/components/DoneCheck.tsx
+++ b/frontend/src/components/DoneCheck.tsx
@@ -1,6 +1,8 @@
// 0.9.8 done-check (autonomy/done-check/design.md): one box between the chips and the answer that says whether
// anything checked a done item, with each check on demand; and the one-word marker on done rows in the list.
// Server text (line, what, how, evidence) is drawn as text only, never as links or HTML.
+// request-parts (autonomy/request-parts/ui-brief.md): with written parts, the box leads with one row per part of the
+// person's request, its criteria folded under it, and today's checks follow under "How it was checked".
import React, { useId, useState } from 'react';
import { AlertTriangle, Check, ChevronDown, CircleDashed, Clock, Shield, ShieldCheck, ShieldHalf, ShieldX, X, type LucideIcon } from 'lucide-react';
@@ -13,7 +15,16 @@ import {
ITEM_WORD,
type ItemKind,
MARKER,
+ NO_CRITERIA_HELP,
+ PART_COLOUR,
+ PART_WORD,
+ PARTS_HEADING,
+ type CheckedPart,
+ type PartResult,
SECTION_LABEL,
+ criteriaToggle,
+ partKind,
+ partsLayout,
STATE_STYLE,
droppedLine,
howText,
@@ -32,6 +43,57 @@ const STATE_ICON: Record<CheckState, LucideIcon> = {
not_checked: Shield,
};
+const PART_ICON: Record<PartResult, LucideIcon> = { passed: Check, failed: X, not_checked: CircleDashed };
+
+/** One part of the person's request: their words, its result, and the criteria that prove it on demand. */
+const PartRow: React.FC<{ part: CheckedPart }> = ({ part }) => {
+ const id = `${useId()}-criteria`;
+ const kind = partKind(part.result);
+ // A part that was not met opens its fold, so the failing criterion shows without a tap.
+ const [open, setOpen] = useState(kind === 'failed');
+ const Icon = PART_ICON[kind];
+ const n = part.criteria.length;
+ return (
+ <li className="grid grid-cols-[14px_minmax(0,1fr)] gap-x-2.5 py-2 border-b border-hairline last:border-b-0" data-part={kind}>
+ <Icon size={14} className={`mt-1 ${PART_COLOUR[kind]}`} aria-hidden="true" />
+ <div className="min-w-0">
+ <p className="text-body text-zinc-100 break-words [overflow-wrap:anywhere]" data-part-text>
+ {part.text}
+ </p>
+ <div className="text-meta flex flex-wrap items-baseline gap-x-1 break-words [overflow-wrap:anywhere]">
+ <span className={`font-semibold ${PART_COLOUR[kind]}`} data-part-result>
+ {PART_WORD[kind]}
+ </span>
+ {n === 0 && <span className="text-zinc-400" data-part-no-criteria> · {NO_CRITERIA_HELP}</span>}
+ {n > 0 && (
+ <>
+ <span className="text-zinc-400" aria-hidden="true">·</span>
+ <button type="button" aria-expanded={open} aria-controls={id} onClick={() => setOpen((o) => !o)} className={linkBtn} data-compact data-part-toggle>
+ {criteriaToggle(open, n)}
+ <ChevronDown size={14} aria-hidden="true" className={`transition-transform motion-reduce:transition-none ${open ? 'rotate-180' : ''}`} />
+ </button>
+ </>
+ )}
+ </div>
+ {n > 0 && (
+ <ul id={id} hidden={!open} className={`mt-1 border-l-2 border-hairline-strong pl-2 space-y-1 ${open ? 'kw-fade-in' : ''}`} data-part-criteria>
+ {part.criteria.map((c, i) => {
+ const ck = partKind(c.result);
+ return (
+ <li key={c.id || i} className="text-meta break-words [overflow-wrap:anywhere]" data-criterion={ck}>
+ <span className="text-zinc-200">{c.text}</span>
+ <span className="text-zinc-400"> · </span>
+ <span className={`font-semibold ${PART_COLOUR[ck]}`}>{PART_WORD[ck]}</span>
+ </li>
+ );
+ })}
+ </ul>
+ )}
+ </div>
+ </li>
+ );
+};
+
const ITEM_ICON: Record<ItemKind, { Icon: LucideIcon; cls: string }> = {
passed: { Icon: Check, cls: 'text-ok' },
failed: { Icon: X, cls: 'text-bad' },
@@ -48,11 +110,16 @@ export const DoneCheck: React.FC<{
const listId = `${useId()}-checks`;
const state = checked.state;
const style = STATE_STYLE[state];
- const [open, setOpen] = useState(style.open);
+ const layout = partsLayout(checked);
+ // With parts shown, the failing criterion sits under its part, so the checks list starts closed and the answer
+ // stays above the fold on a phone (design-check-ui.md fix 1). Today's card keeps its open-when-failed rule.
+ const [open, setOpen] = useState(style.open && !layout);
const { prefix, rest } = splitLine(state, checked.line);
const Icon = STATE_ICON[state];
const items = checked.items;
const n = items.length + checked.items_dropped;
+ const partsId = `${listId}-parts`;
+ const howId = `${listId}-how`;
return (
<section aria-label={SECTION_LABEL} data-done-check={state} className={`rounded-2xl border px-4 py-3 flex flex-col gap-2 min-w-0 ${style.box}`}>
<p className="grid grid-cols-[16px_minmax(0,1fr)] gap-x-2.5 text-body text-zinc-100" data-check-line>
@@ -70,6 +137,23 @@ export const DoneCheck: React.FC<{
)}
</span>
</p>
+ {layout && checked.parts && (
+ <div className="ml-[26px] min-w-0" data-parts={layout}>
+ <p id={partsId} className="text-meta font-semibold text-zinc-300" data-parts-heading>
+ {PARTS_HEADING}
+ </p>
+ <ul aria-labelledby={partsId} className="border-t border-hairline" data-parts-list>
+ {checked.parts.map((p, i) => (
+ <PartRow key={i} part={p} />
+ ))}
+ </ul>
+ </div>
+ )}
+ {layout && items.length > 0 && (
+ <p id={howId} className="ml-[26px] mt-3 text-meta font-semibold text-zinc-300" data-how-heading>
+ {SECTION_LABEL}
+ </p>
+ )}
{items.length > 0 ? (
<>
<div className="ml-[26px]">
@@ -78,7 +162,7 @@ export const DoneCheck: React.FC<{
<ChevronDown size={14} aria-hidden="true" className={`transition-transform motion-reduce:transition-none ${open ? 'rotate-180' : ''}`} />
</button>
</div>
- <ul id={listId} hidden={!open} className={`ml-[26px] border-t border-hairline ${open ? 'kw-fade-in' : ''}`} data-check-list>
+ <ul id={listId} hidden={!open} aria-labelledby={layout ? howId : undefined} className={`ml-[26px] border-t border-hairline ${open ? 'kw-fade-in' : ''}`} data-check-list>
{items.map((it, i) => {
const kind = itemKind(it);
const { Icon: ItemIcon, cls } = ITEM_ICON[kind];
diff --git a/frontend/src/doneCheck.ts b/frontend/src/doneCheck.ts
index 3fb5ea37..c0a21cad 100644
--- a/frontend/src/doneCheck.ts
+++ b/frontend/src/doneCheck.ts
@@ -17,6 +17,27 @@ export interface Checked {
items: CheckedItem[];
items_dropped: number;
line: string;
+ /** request-parts (#619, 0.9.11): present only when the task has criteria. Every field is optional, so an older
+ * server draws today's card. `parts_written: false` means each criterion stands in as a part. */
+ parts_checked?: number;
+ parts_total?: number;
+ parts_written?: boolean;
+ parts?: CheckedPart[];
+}
+
+export type PartResult = 'passed' | 'failed' | 'not_checked';
+
+export interface CheckedCriterion {
+ id: string;
+ text: string;
+ result: PartResult | string;
+}
+
+export interface CheckedPart {
+ /** The person's own words for this part of the request. */
+ text: string;
+ result: PartResult | string;
+ criteria: CheckedCriterion[];
}
const STATES: readonly CheckState[] = ['checked', 'partly', 'not_checked', 'failed'];
@@ -30,9 +51,48 @@ export function knownChecked(v: unknown): (Checked & { state: CheckState }) | nu
? c.items.filter((i): i is CheckedItem => !!i && typeof i === 'object' && typeof (i as CheckedItem).what === 'string')
: [];
const dropped = typeof c.items_dropped === 'number' && Number.isFinite(c.items_dropped) && c.items_dropped > 0 ? Math.floor(c.items_dropped) : 0;
- return { state: c.state as CheckState, items, items_dropped: dropped, line: typeof c.line === 'string' ? c.line : '' };
+ const out: Checked & { state: CheckState } = { state: c.state as CheckState, items, items_dropped: dropped, line: typeof c.line === 'string' ? c.line : '' };
+ if (typeof c.parts_written === 'boolean') out.parts_written = c.parts_written;
+ if (typeof c.parts_total === 'number' && Number.isFinite(c.parts_total)) out.parts_total = c.parts_total;
+ if (typeof c.parts_checked === 'number' && Number.isFinite(c.parts_checked)) out.parts_checked = c.parts_checked;
+ if (Array.isArray(c.parts)) out.parts = c.parts.flatMap((p) => knownPart(p));
+ return out;
}
+function knownPart(v: unknown): CheckedPart[] {
+ if (!v || typeof v !== 'object') return [];
+ const p = v as Partial<CheckedPart>;
+ if (typeof p.text !== 'string' || !p.text.trim()) return [];
+ const criteria = Array.isArray(p.criteria)
+ ? p.criteria.filter((x): x is CheckedCriterion => !!x && typeof x === 'object' && typeof (x as CheckedCriterion).text === 'string' && (x as CheckedCriterion).text.trim() !== '')
+ : [];
+ return [{ text: p.text, result: typeof p.result === 'string' ? p.result : 'not_checked', criteria }];
+}
+
+/**
+ * Which layout the parts call for (request-parts ui-brief.md):
+ * - `many`: written parts, two or more: one row per part, then the checks under "How it was checked".
+ * - `one`: a single written part: named, with no counter.
+ * - `null`: no parts, or `parts_written` false/missing: today's card, with no "parts" words.
+ */
+export function partsLayout(c: Pick<Checked, 'parts' | 'parts_total' | 'parts_written'>): 'many' | null {
+ if (c.parts_written !== true || !c.parts) return null;
+ // One written part: today's card; the server line already names it (design-check-ui.md fix 4).
+ return typeof c.parts_total === 'number' && c.parts_total >= 2 && c.parts.length >= 2 ? 'many' : null;
+}
+
+/** A part's or criterion's result; anything unknown reads as "no check", never passed. */
+export function partKind(result: unknown): PartResult {
+ return result === 'passed' || result === 'failed' ? result : 'not_checked';
+}
+
+/** impl.md "Notes for Mira's card": copy to reuse. */
+export const PART_WORD: Record<PartResult, string> = { passed: 'Passed', failed: 'Not met', not_checked: 'No check' };
+export const PART_COLOUR: Record<PartResult, string> = { passed: 'text-ok', failed: 'text-bad', not_checked: 'text-warn' };
+export const PARTS_HEADING = 'Parts of your request';
+export const NO_CRITERIA_HELP = 'Nothing checked this part.';
+export const criteriaToggle = (open: boolean, n: number): string => (open ? 'Hide what proves it' : `Show what proves it (${n})`);
+
/** design.md section 4: the line when the server's is blank. */
export const FALLBACK_LINE: Record<CheckState, string> = {
checked: 'Checked: every check passed.',
diff --git a/frontend/src/doneCheckFixture.ts b/frontend/src/doneCheckFixture.ts
index 4e99344e..dd929928 100644
--- a/frontend/src/doneCheckFixture.ts
+++ b/frontend/src/doneCheckFixture.ts
@@ -48,3 +48,92 @@ export const CHECKED_FAILED: Checked = {
/** A 120-character URL for the 390 px overflow check. */
export const LONG_URL = 'https://shop.example/products/spring-blend/variants/house-blend-1kg/photos/originals/2026-11-13/front-view-large.jpg?v=1';
+
+// request-parts (autonomy/request-parts/ui-brief.md): the five cases for the parts rows. PARTS_NO_CHECK is the
+// impl.md "JSON shape" sample, with the "…" in its line filled from impl.md's line examples; the rest are made-up
+// data in the same shape (#619, vega-request-parts).
+export const PARTS_NO_CHECK: Checked = {
+ state: 'partly',
+ items: [
+ { what: 'test -f shared/sales/october-sales.pdf', how: 'ran the command', result: 'passed', evidence: 'exit 0' },
+ { what: 'The PDF has the October totals', how: 'task criterion, met with evidence', result: 'passed', evidence: 'Page 1: October total 48,210 EUR' },
+ { what: 'The PDF is in shared/sales/', how: 'task criterion, met with evidence', result: 'passed', evidence: 'shared/sales/october-sales.pdf, 212 KB' },
+ ],
+ items_dropped: 0,
+ line: 'Partly checked: 2 of 3 parts checked; "send it to Ana": no check; test -f shared/sales/october-sales.pdf passed.',
+ parts_checked: 2,
+ parts_total: 3,
+ parts_written: true,
+ parts: [
+ { text: 'Make the October sales PDF', result: 'passed', criteria: [{ id: 'c1', text: 'The PDF has the October totals', result: 'passed' }] },
+ { text: 'put it in the shared folder', result: 'passed', criteria: [{ id: 'c2', text: 'The PDF is in shared/sales/', result: 'passed' }] },
+ { text: 'send it to Ana', result: 'not_checked', criteria: [] },
+ ],
+};
+
+export const PARTS_ALL_PASSED: Checked = {
+ state: 'checked',
+ items: [
+ { what: 'The draft names all three new flavours', how: 'task criterion, met with evidence', result: 'passed', evidence: 'Spring Blend, House Decaf and Cold Brew Kit are in the second paragraph' },
+ { what: 'The draft is under 150 words', how: 'task criterion, met with evidence', result: 'passed', evidence: '128 words' },
+ { what: 'The draft is in the newsletter queue', how: 'task criterion, met with evidence', result: 'passed', evidence: 'Queued for Tuesday 9:00' },
+ ],
+ items_dropped: 0,
+ line: 'Checked: 2 of 2 parts checked.',
+ parts_checked: 2,
+ parts_total: 2,
+ parts_written: true,
+ parts: [
+ {
+ text: 'Write a short newsletter about the three new flavours',
+ result: 'passed',
+ criteria: [
+ { id: 'c1', text: 'The draft names all three new flavours', result: 'passed' },
+ { id: 'c2', text: 'The draft is under 150 words', result: 'passed' },
+ ],
+ },
+ { text: 'and queue it for Tuesday morning', result: 'passed', criteria: [{ id: 'c3', text: 'The draft is in the newsletter queue', result: 'passed' }] },
+ ],
+};
+
+export const PARTS_ONE_FAILED: Checked = {
+ state: 'failed',
+ items: [
+ { what: 'The PDF has the October totals', how: 'task criterion, marked not met', result: 'failed', evidence: 'The totals table stops at 30 September' },
+ { what: 'The PDF is in shared/sales/', how: 'task criterion, met with evidence', result: 'passed', evidence: 'shared/sales/october-sales.pdf, 198 KB' },
+ { what: 'Ana has the PDF', how: 'task criterion, met with evidence', result: 'passed', evidence: 'Sent to [email protected] at 09:14' },
+ ],
+ items_dropped: 0,
+ line: 'Failed: 2 of 3 parts checked; "Make the October sales PDF": not met.',
+ parts_checked: 2,
+ parts_total: 3,
+ parts_written: true,
+ parts: [
+ { text: 'Make the October sales PDF', result: 'failed', criteria: [{ id: 'c1', text: 'The PDF has the October totals', result: 'failed' }] },
+ { text: 'put it in the shared folder', result: 'passed', criteria: [{ id: 'c2', text: 'The PDF is in shared/sales/', result: 'passed' }] },
+ { text: 'send it to Ana', result: 'passed', criteria: [{ id: 'c3', text: 'Ana has the PDF', result: 'passed' }] },
+ ],
+};
+
+export const PARTS_ONE_WRITTEN: Checked = {
+ state: 'checked',
+ items: [{ what: 'The FAQ mentions the yearly discount', how: 'task criterion, met with evidence', result: 'passed', evidence: 'FAQ, question 4: "Pay yearly and save 20 %"' }],
+ items_dropped: 0,
+ line: 'Checked: "Add the yearly discount to the FAQ" checked.',
+ parts_checked: 1,
+ parts_total: 1,
+ parts_written: true,
+ parts: [{ text: 'Add the yearly discount to the FAQ', result: 'passed', criteria: [{ id: 'c1', text: 'The FAQ mentions the yearly discount', result: 'passed' }] }],
+};
+
+/** parts_written false: each criterion stands in as a part, so the card stays today's card. */
+export const PARTS_NOT_WRITTEN: Checked = {
+ ...CHECKED_PARTLY,
+ parts_checked: 1,
+ parts_total: 2,
+ parts_written: false,
+ parts: [
+ { text: 'The three plan prices match the plan sheet', result: 'passed', criteria: [{ id: 'c1', text: 'The three plan prices match the plan sheet', result: 'passed' }] },
+ { text: 'The FAQ mentions the yearly discount', result: 'not_checked', criteria: [{ id: 'c2', text: 'The FAQ mentions the yearly discount', result: 'not_checked' }] },
+ ],
+};
diff --git a/frontend/tests/requestParts.test.mjs b/frontend/tests/requestParts.test.mjs
new file mode 100644
index 00000000..ba8d6e68
--- /dev/null
+++ b/frontend/tests/requestParts.test.mjs
@@ -0,0 +1,204 @@
+// request-parts card (autonomy/request-parts/ui-brief.md): with written parts, the done-check box leads with one
+// row per part of the person's request, criteria folded under each, and today's checks under "How it was checked".
+// Data: impl.md "JSON shape" sample and four made-up objects in the same shape (src/doneCheckFixture.ts).
+process.env.TZ = 'UTC';
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/inbox', pretendToBeVisual: true });
+const g = globalThis;
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'HTMLButtonElement', 'Element', 'Node', 'Event', 'MouseEvent', 'KeyboardEvent', 'FocusEvent', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'localStorage', 'sessionStorage']) {
+ if (!(k in dom.window)) continue;
+ Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });
+}
+g.IS_REACT_ACT_ENVIRONMENT = false;
+
+const m = await loadBundled(`
+ export { default as React } from 'react';
+ export { createRoot } from 'react-dom/client';
+ export * as dc from './src/doneCheck';
+ export * as cx from './src/doneCheckFixture';
+ export { DoneCheck } from './src/components/DoneCheck';
+`);
+const { React, createRoot, dc, cx } = m;
+const h = React.createElement;
+const settle = async (n = 8) => {
+ for (let i = 0; i < n; i++) await new Promise((r) => setTimeout(r, 0));
+};
+const click = async (b) => {
+ b.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ await settle();
+};
+const text = (e) => e.textContent.replace(/\s+/g, ' ').trim();
+const clone = (x) => JSON.parse(JSON.stringify(x));
+
+async function box(checked) {
+ document.body.innerHTML = '';
+ const el = document.createElement('div');
+ document.body.appendChild(el);
+ const root = createRoot(el);
+ root.render(h(m.DoneCheck, { checked: dc.knownChecked(checked) }));
+ await settle();
+ return { el, root, q: (x) => el.querySelector(x), qa: (x) => [...el.querySelectorAll(x)] };
+}
+const before = (a, b) => !!(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING);
+
+test('3 parts, one with no check: rows in order in the person\'s words, "No check" plainly, then How it was checked', async () => {
+ const r = await box(cx.PARTS_NO_CHECK);
+ assert.equal(text(r.q('[data-check-line]')), cx.PARTS_NO_CHECK.line, 'the line is the server\'s, untouched');
+ assert.equal(r.q('[data-parts]').getAttribute('data-parts'), 'many');
+ assert.equal(text(r.q('[data-parts-heading]')), 'Parts of your request');
+ const rows = r.qa('[data-part]');
+ assert.deepEqual(rows.map((x) => text(x.querySelector('[data-part-text]'))), ['Make the October sales PDF', 'put it in the shared folder', 'send it to Ana']);
+ assert.deepEqual(rows.map((x) => x.getAttribute('data-part')), ['passed', 'passed', 'not_checked']);
+ assert.deepEqual(rows.map((x) => text(x.querySelector('[data-part-result]'))), ['Passed', 'Passed', 'No check']);
+ assert.match(rows[2].querySelector('[data-part-result]').className, /text-warn/, 'no check stands out in amber');
+ assert.equal(rows[2].querySelector('[data-part-toggle]'), null, 'nothing to open on a part with no criteria');
+ assert.equal(text(rows[2].querySelector('[data-part-no-criteria]')), '· Nothing checked this part.');
+ const how = r.q('[data-how-heading]');
+ assert.equal(text(how), 'How it was checked');
+ assert.ok(before(r.q('[data-parts]'), how) && before(how, r.q('[data-check-toggle]')), 'parts, then the heading, then the checks');
+ assert.equal(r.q('[data-check-list]').getAttribute('aria-labelledby'), how.id);
+ assert.equal(r.qa('[data-check-list] [data-check-item]').length, 3, 'today\'s checks are all still listed');
+ r.root.unmount();
+});
+
+test('criteria fold under each part: closed by default, a keyboard-reachable button opens them with their results', async () => {
+ const r = await box(cx.PARTS_NO_CHECK);
+ const row = r.qa('[data-part]')[0];
+ const btn = row.querySelector('[data-part-toggle]');
+ assert.equal(btn.tagName, 'BUTTON');
+ assert.equal(btn.getAttribute('type'), 'button');
+ assert.equal(btn.getAttribute('aria-expanded'), 'false');
+ assert.equal(text(btn), 'Show what proves it (1)');
+ const list = document.getElementById(btn.getAttribute('aria-controls'));
+ assert.ok(list && list.hidden, 'controls a hidden list');
+ // A display utility (flex, grid, block) on the list would beat the hidden attribute and show it while folded.
+ for (const ul of r.qa('[data-part-criteria], [data-check-list], [data-parts-list]')) assert.doesNotMatch(ul.className, /(^|\s)(flex|grid|block|inline-flex)(\s|$)/, 'no display class on a foldable list');
+ await click(btn);
+ assert.equal(btn.getAttribute('aria-expanded'), 'true');
+ assert.equal(text(btn), 'Hide what proves it');
+ assert.equal(list.hidden, false);
+ assert.equal(text(list), 'The PDF has the October totals · Passed');
+ assert.ok(r.qa('[data-part]')[1].querySelector('[data-part-criteria]').hidden, 'the other part stays folded');
+ r.root.unmount();
+});
+
+test('all parts passed: every row Passed, two criteria under the first part', async () => {
+ const r = await box(cx.PARTS_ALL_PASSED);
+ assert.equal(r.q('section').getAttribute('data-done-check'), 'checked');
+ const rows = r.qa('[data-part]');
+ assert.equal(rows.length, 2);
+ assert.ok(rows.every((x) => text(x.querySelector('[data-part-result]')) === 'Passed'));
+ assert.equal(text(rows[0].querySelector('[data-part-toggle]')), 'Show what proves it (2)');
+ assert.equal(r.q('[data-part-no-criteria]'), null);
+ r.root.unmount();
+});
+
+test('one part failed: "Not met" in the bad colour, its fold starts open; the checks list starts closed so the answer stays up', async () => {
+ const r = await box(cx.PARTS_ONE_FAILED);
+ assert.equal(r.q('section').getAttribute('data-done-check'), 'failed');
+ const rows = r.qa('[data-part]');
+ const row = rows[0];
+ assert.equal(row.getAttribute('data-part'), 'failed');
+ assert.equal(text(row.querySelector('[data-part-result]')), 'Not met');
+ assert.match(row.querySelector('[data-part-result]').className, /text-bad/);
+ const btn = row.querySelector('[data-part-toggle]');
+ assert.equal(btn.getAttribute('aria-expanded'), 'true', 'a part that was not met opens its fold');
+ assert.equal(text(btn), 'Hide what proves it');
+ assert.equal(row.querySelector('[data-part-criteria]').hidden, false);
+ assert.equal(row.querySelector('[data-criterion]').getAttribute('data-criterion'), 'failed');
+ assert.match(text(row.querySelector('[data-part-criteria]')), /Not met$/);
+ for (const other of rows.slice(1)) {
+ const t = other.querySelector('[data-part-toggle]');
+ if (t) assert.equal(t.getAttribute('aria-expanded'), 'false', 'parts that passed stay folded');
+ }
+ assert.equal(r.q('[data-check-list]').hidden, true, 'with parts shown, the checks list starts closed');
+ assert.equal(r.q('[data-check-toggle]').getAttribute('aria-expanded'), 'false');
+ await click(btn);
+ assert.equal(row.querySelector('[data-part-criteria]').hidden, true, 'and it still folds');
+ r.root.unmount();
+});
+
+test('the fold sits on the result line: "Passed · Show what proves it (n)", the dot hidden from screen readers', async () => {
+ const r = await box(cx.PARTS_NO_CHECK);
+ const row = r.qa('[data-part]')[0];
+ const line = row.querySelector('[data-part-result]').parentElement;
+ assert.ok(line.contains(row.querySelector('[data-part-toggle]')), 'result and toggle share one line');
+ assert.deepEqual([...line.children].map(text), ['Passed', '·', 'Show what proves it (1)'], 'result, dot, toggle; the gap is CSS');
+ assert.match(line.className, /\bflex-wrap\b/);
+ assert.equal(line.querySelector('[aria-hidden="true"]').textContent, '·');
+ assert.doesNotMatch(row.querySelector('[data-part-toggle]').className, /\bmt-1\b/);
+ assert.match(r.q('[data-how-heading]').className, /\bmt-3\b/, 'the section gap is bigger than the gap between parts');
+ r.root.unmount();
+});
+
+test('today\'s card is unchanged without parts: the failed card still opens its checks list', async () => {
+ const x = clone(cx.PARTS_ONE_FAILED);
+ delete x.parts_written;
+ const r = await box(x);
+ assert.equal(r.q('[data-parts]'), null);
+ assert.equal(r.q('[data-check-list]').hidden, false);
+ r.root.unmount();
+});
+
+test('one written part: exactly today\'s card, the server line names it and there is no counter', async () => {
+ const strip = (html) => html.replace(/id="[^"]*"|aria-controls="[^"]*"|aria-labelledby="[^"]*"/g, '');
+ const a = await box(cx.PARTS_ONE_WRITTEN);
+ const html = strip(a.el.innerHTML);
+ assert.equal(a.q('[data-parts]'), null);
+ assert.equal(a.q('[data-how-heading]'), null);
+ assert.match(text(a.q('[data-check-line]')), /Add the yearly discount to the FAQ/);
+ assert.doesNotMatch(text(a.el), /\b1 of 1\b/);
+ assert.doesNotMatch(text(a.el), /parts/i);
+ a.root.unmount();
+ const plain = clone(cx.PARTS_ONE_WRITTEN);
+ for (const k of ['parts', 'parts_total', 'parts_checked', 'parts_written']) delete plain[k];
+ const b = await box(plain);
+ assert.equal(html, strip(b.el.innerHTML), 'same markup as a card without the parts fields');
+ b.root.unmount();
+});
+
+test('parts_written false: exactly today\'s card, no parts rows and no "parts" words', async () => {
+ const strip = (html) => html.replace(/id="[^"]*"|aria-controls="[^"]*"/g, '');
+ const a = await box(cx.PARTS_NOT_WRITTEN);
+ const html = strip(a.el.innerHTML);
+ assert.equal(a.q('[data-parts]'), null);
+ assert.equal(a.q('[data-how-heading]'), null);
+ assert.doesNotMatch(text(a.el), /parts/i);
+ a.root.unmount();
+ const b = await box(cx.CHECKED_PARTLY);
+ assert.equal(html, strip(b.el.innerHTML), 'same markup as a card without the parts fields');
+ b.root.unmount();
+});
+
+test('older server or odd data: missing parts_written, too few parts, malformed parts and unknown results', async () => {
+ const noFlag = clone(cx.PARTS_NO_CHECK);
+ delete noFlag.parts_written;
+ assert.equal(dc.partsLayout(dc.knownChecked(noFlag)), null, 'missing parts_written: today\'s card');
+ const empty = { ...clone(cx.PARTS_NO_CHECK), parts: [] };
+ assert.equal(dc.partsLayout(dc.knownChecked(empty)), null, 'parts_total 3 but no parts: today\'s card');
+ assert.equal(dc.partsLayout(dc.knownChecked({ ...clone(cx.PARTS_NO_CHECK), parts: 'x' })), null);
+ const odd = clone(cx.PARTS_NO_CHECK);
+ odd.parts = [null, { text: '' }, { text: 'Make it', result: 'maybe', criteria: [{ id: 'c1', text: 'It is made', result: 'weird' }, 7, { id: 'c2' }] }, { text: 'Ship it', result: 'passed' }];
+ const k = dc.knownChecked(odd);
+ assert.equal(k.parts.length, 2, 'only parts with words are kept');
+ assert.equal(k.parts[0].criteria.length, 1, 'only criteria with words are kept');
+ assert.deepEqual(k.parts[1].criteria, [], 'missing criteria read as none');
+ const r = await box(odd);
+ assert.deepEqual(r.qa('[data-part-result]').map(text), ['No check', 'Passed'], 'an unknown result is never Passed');
+ await click(r.q('[data-part-toggle]'));
+ assert.match(text(r.q('[data-criterion]')), /No check$/);
+ r.root.unmount();
+});
+
+test('server text is text only: a part with markup is drawn as its characters', async () => {
+ const x = clone(cx.PARTS_NO_CHECK);
+ x.parts[2].text = '<img src=x onerror=alert(1)> send it to Ana';
+ const r = await box(x);
+ assert.equal(r.q('[data-part] img'), null);
+ assert.equal(text(r.qa('[data-part-text]')[2]), '<img src=x onerror=alert(1)> send it to Ana');
+ r.root.unmount();
+});