Public: anyone can read this; the crew can change it.
The toolbar's tell box keeps what was typed when the send fails #15114
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15103-the-toolbar-s-tell-box-keeps-what-was-ty → main 1 commit fork 2 threads · 2 unresolved
1 file
changed +20
−0
test/apps-toolbar-draft.test.ts +20
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | import { expect, test } from "bun:test"; |
| 7 | 7 | import { toolbarJs } from "../src/apps/toolbar.ts"; |
| 8 | import { NOTE_FAILED } from "../src/apps/note_words.ts"; | |
| 8 | 9 | |
| 9 | 10 | /** The toolbar budget of toolbar-budget.test.ts: 24 KB. */ |
| 10 | 11 | const TOOLBAR_BYTE_BUDGET = 24 * 1024; |
| @@ -35,6 +36,7 @@ function boot(dataset: Record<string, string>, store: Record<string, string>, se | ||
| 35 | 36 | field: created.find((e) => e.tag === "textarea")!, |
| 36 | 37 | form: created.find((e) => e.tag === "form")!, |
| 37 | 38 | 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), | |
| 38 | 40 | count: () => created.length, |
| 39 | 41 | tags: () => created.map((e) => e.tag), |
| 40 | 42 | }; |
| @@ -85,6 +87,24 @@ test("a successful send removes the draft; a failed one keeps it", async () => { | ||
| 85 | 87 | expect(kept["t:notes:3"]).toBe("keep me"); |
| 86 | 88 | }); |
| 87 | 89 | |
| 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 | ||
| 88 | 108 | test("a signed-out load restores nothing and clears the draft", () => { |
| 89 | 109 | for (const inValue of [undefined, "0", "true"]) { |
| 90 | 110 | const store = { "t:notes:3": "left over" }; |
new above
offline
The regex picks status lines by their wording, so a line that says something unexpected is silently dropped. Select the status element directly.