Skip to content

Commit 7020234

Browse files
loganblevinscreepy raffeclaude
committed
test(inbox): wait for the reveal's reading notice before the dwell's fake clock
The dwell helper flushed two real frames before faking the clock, but a reveal takes three (attach observers, place, verify) and can restart on mutations, so a fixed count could still leave its verification queued on the real clock. Capture the reveal's `reading-positioned` notice instead and wait until the reader's own container has received it. Co-authored-by: creepy raffe <8e4fdf71fdd48cce832978ccbfec79d607d52cee262d31228d38423bc5bde34b@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Logan Blevins <[email protected]>
1 parent 8cead17 commit 7020234

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

‎src/bundled/inbox/InboxPage.test.tsx‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
waitFor,
1313
within,
1414
} from "@testing-library/react";
15-
import { afterEach, beforeEach, expect, it, vi } from "vitest";
15+
import { afterEach, beforeEach, expect, it, onTestFinished, vi } from "vitest";
1616
import userEvent from "@testing-library/user-event";
1717
import { PageTabs } from "../channels/PageTabs";
1818
import { InboxPage } from "./InboxPage";
@@ -4166,18 +4166,28 @@ function threadLayout() {
41664166
? ([box] as unknown as DOMRectList)
41674167
: getClientRects.call(this);
41684168
});
4169+
// A reveal's completion notice does not bubble, so capture it.
4170+
const positioned = new Set<Element>();
4171+
const notice = (event: Event) => {
4172+
if (event.target instanceof Element) positioned.add(event.target);
4173+
};
4174+
document.addEventListener("reading-positioned", notice, true);
4175+
onTestFinished(() =>
4176+
document.removeEventListener("reading-positioned", notice, true),
4177+
);
41694178
return async (reader: HTMLElement, read: () => void) => {
4170-
// A reveal can still be between its two real frames here (use-message-
4171-
// reveal's placing frame, then its completing one); the fake clock below
4172-
// never runs a frame requested before it, so let those land first. Its
4173-
// settled state is a private ref with no DOM signal to wait on instead.
4174-
for (let frame = 0; frame < 2; frame++)
4175-
await act(
4176-
() =>
4177-
new Promise<void>((resolve) =>
4178-
requestAnimationFrame(() => resolve()),
4179-
),
4180-
);
4179+
// The fake clock below never runs a frame requested before it, so first
4180+
// let this reader's reveal finish on the real one: it notifies reading
4181+
// once its row is placed and verified.
4182+
await waitFor(() =>
4183+
expect(
4184+
[...positioned].some(
4185+
(target) =>
4186+
target.isConnected &&
4187+
(target.contains(reader) || reader.contains(target)),
4188+
),
4189+
).toBe(true),
4190+
);
41814191
windowFocus.mockReturnValue(true);
41824192
vi.useFakeTimers({
41834193
toFake: [

0 commit comments

Comments
 (0)