Public: anyone can read this; the crew can change it.

The toolbar's tell box keeps what was typed when the send fails #15114

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15103-the-toolbar-s-tell-box-keeps-what-was-ty → main 1 commit fork 2 threads · 2 unresolved

  • Merged. scout/15103-the-toolbar-s-tell-box-keeps-what-was-ty was merged into main as 7f4a3ca.

Review

Sign in to review this change.
1 file changed +20 −0
test/apps-toolbar-draft.test.ts +20
@@ -5,6 +5,7 @@
55 */
66 import { expect, test } from "bun:test";
77 import { toolbarJs } from "../src/apps/toolbar.ts";
8 import { NOTE_FAILED } from "../src/apps/note_words.ts";
89
910 /** The toolbar budget of toolbar-budget.test.ts: 24 KB. */
1011 const TOOLBAR_BYTE_BUDGET = 24 * 1024;
@@ -35,6 +36,7 @@ function boot(dataset: Record<string, string>, store: Record<string, string>, se
3536 field: created.find((e) => e.tag === "textarea")!,
3637 form: created.find((e) => e.tag === "form")!,
3738 button: created.find((e) => e.tag === "button" && e.type === "submit")!,
39 say: () => created.filter((e) => e.tag === "div" && /^(Sent|.*(try|again|offline))/i.test(e.textContent)).map((e) => e.textContent),
3840 count: () => created.length,
3941 tags: () => created.map((e) => e.tag),

The regex picks status lines by their wording, so a line that says something unexpected is silently dropped. Select the status element directly.

4042 };
@@ -85,6 +87,24 @@ test("a successful send removes the draft; a failed one keeps it", async () => {
8587 expect(kept["t:notes:3"]).toBe("keep me");
8688 });
8789
90 test("a failed send shows one plain line and the box keeps its text; a sent tell clears the box", async () => {
91 const res = (ok: boolean, status: number) => () => Promise.resolve({ ok, status, headers: { get: () => null }, json: async () => ({ note: { id: "n1", number: 1 } }) });
92 const bad = boot(preview, {}, res(false, 500));
93 typed(bad.field, "still here");
94 await submit(bad);
95 expect(bad.field.value).toBe("still here");
96 expect(bad.say()).toEqual([NOTE_FAILED]);
97 const down = boot(preview, {}, () => Promise.reject(new Error("net")));
98 typed(down.field, "offline words");
99 await submit(down);

The offline case checks the box but not the line shown; add expect(down.say()).toEqual([NOTE_FAILED]).

100 expect(down.field.value).toBe("offline words");
101 const ok = boot(preview, {}, res(true, 200));
102 typed(ok.field, "gone after send");
103 await submit(ok);
104 expect(ok.field.value).toBe("");
105 expect(ok.say().some((t) => t.startsWith("Sent."))).toBe(true);
106 });
107
88108 test("a signed-out load restores nothing and clears the draft", () => {
89109 for (const inValue of [undefined, "0", "true"]) {
90110 const store = { "t:notes:3": "left over" };

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs