Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SidebarThreadUndoNotice.browser.test.tsx

37 lines1.4 KB

1import { describe, expect, it, vi } from "vite-plus/test";
2​
3import { act, fakeTimers, render } from "../../../test/render";
4import { useThreadUndoNotice } from "../../hooks/showThreadUndoNotice";
5import { SidebarThreadUndoNotice } from "./SidebarThreadUndoNotice";
6​
7const spoken = () =>
8 [...document.querySelectorAll('body > [aria-live="polite"]')]
9 .map((region) => region.textContent)
10 .join("");
11​
12describe("SidebarThreadUndoNotice", () => {
13 it("speaks the notice, and drops it when the notice clears before it is spoken", async () => {
14 using _notice = { [Symbol.dispose]: () => useThreadUndoNotice.setState({ notice: null }) };
15 await using _screen = await render(<SidebarThreadUndoNotice />);
16 using _timers = fakeTimers();
17 const showSettled = () =>
18 act(async () =>
19 useThreadUndoNotice.setState({
20 notice: { action: "Settled", count: 1, undo: async () => {} },
21 }),
22 );
23​
24 await showSettled();
25 await act(async () => vi.advanceTimersByTime(300));
26 expect(spoken()).toMatch(/^Settled 1 thread, /);
27​
28 await act(async () => useThreadUndoNotice.setState({ notice: null }));
29 for (const region of document.querySelectorAll('body > [aria-live="polite"]')) {
30 region.textContent = "";
31 }
32 await showSettled();
33 await act(async () => useThreadUndoNotice.setState({ notice: null }));
34 await act(async () => vi.advanceTimersByTime(300));
35 expect(spoken()).toBe("");
36 });
37});