|
| 1 | +import { readFileSync } from "node:fs"; |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import { |
3 | 4 | checkMessageParts, |
|
6 | 7 | MAX_MESSAGE_BODY_BYTES, |
7 | 8 | MAX_MESSAGE_CHARS, |
8 | 9 | MAX_MESSAGE_PARTS, |
| 10 | + MESSAGE_CHARS_WARN_AT, |
| 11 | + messageCountAnnouncement, |
9 | 12 | } from "./message-limits"; |
10 | 13 |
|
11 | 14 | describe("message limits", () => { |
@@ -61,3 +64,39 @@ describe("message limits", () => { |
61 | 64 | expect(exceedsMessageBodyBytes(null)).toBe(false); |
62 | 65 | }); |
63 | 66 | }); |
| 67 | + |
| 68 | +describe("messageCountAnnouncement", () => { |
| 69 | + it("says nothing at all for a normal message", () => { |
| 70 | + expect(messageCountAnnouncement(0)).toBe(""); |
| 71 | + expect(messageCountAnnouncement(MESSAGE_CHARS_WARN_AT - 1)).toBe(""); |
| 72 | + }); |
| 73 | + |
| 74 | + it("reads the count out from the warning point on", () => { |
| 75 | + expect(messageCountAnnouncement(MESSAGE_CHARS_WARN_AT)).toBe( |
| 76 | + `${MESSAGE_CHARS_WARN_AT} / ${MAX_MESSAGE_CHARS}` |
| 77 | + ); |
| 78 | + expect(messageCountAnnouncement(MAX_MESSAGE_CHARS)).toBe( |
| 79 | + `${MAX_MESSAGE_CHARS} / ${MAX_MESSAGE_CHARS}` |
| 80 | + ); |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
| 84 | +/** |
| 85 | + * Structural guard, not behavioural proof: the webapp has no DOM test environment, so nothing |
| 86 | + * here mounts the composer or listens to a screen reader. It asserts the live region is written |
| 87 | + * unconditionally, which is the part the announcement depends on. |
| 88 | + */ |
| 89 | +describe("the composer's live region", () => { |
| 90 | + const source = readFileSync(new URL("./DashboardAgentComposer.tsx", import.meta.url), "utf8"); |
| 91 | + |
| 92 | + it("is in the DOM before the count reaches the warning point", () => { |
| 93 | + const region = source.slice(source.indexOf('aria-live="polite"')); |
| 94 | + expect(region).toContain("messageCountAnnouncement(value.length)"); |
| 95 | + // The old form: the region itself only existed past the threshold. |
| 96 | + expect(source).not.toMatch(/MESSAGE_CHARS_WARN_AT \? \(\s*<p[^>]*aria-live/); |
| 97 | + }); |
| 98 | + |
| 99 | + it("does not read the visible counter out a second time", () => { |
| 100 | + expect(source).toContain("aria-hidden"); |
| 101 | + }); |
| 102 | +}); |
0 commit comments