Skip to content

Commit 35e369c

Browse files
maria-rcksclaude
andcommitted
test(web): trim tool-call label collapse test
Drop the hand-rolled bubbling and the repeated aria-expanded assertions. The case now expands the row, then calls the label handler twice with a selected and an unselected document, asserting only the selecting click is withheld from the row toggle. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 9e06928 commit 35e369c

1 file changed

Lines changed: 15 additions & 31 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.test.tsx‎

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ describe("MessagesTimeline", () => {
17651765
expect(markup).toContain("text-destructive");
17661766
});
17671767

1768-
it("collapses a standalone tool call from its expanded label unless text is selected", async () => {
1768+
it("only withholds an expanded tool-call label click while text is selected", async () => {
17691769
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
17701770
vi.stubGlobal("requestAnimationFrame", () => 0);
17711771
vi.stubGlobal("cancelAnimationFrame", () => {});
@@ -1795,36 +1795,20 @@ describe("MessagesTimeline", () => {
17951795
/>,
17961796
);
17971797
});
1798-
const row = () => renderer!.root.findByProps({ "aria-label": "pnpm lint" });
1799-
// The label is nested inside the row, so a browser click runs the label
1800-
// handler first and then reaches the row unless the label stops it.
1801-
const clickLabel = async (isCollapsed: boolean) => {
1802-
const label = row().findAll(
1803-
(node) =>
1804-
node.type === "span" &&
1805-
typeof node.props.className === "string" &&
1806-
node.props.className.includes("select-text"),
1807-
)[0];
1808-
let reachedRow = true;
1809-
await act(() =>
1810-
label!.props.onClick({
1811-
currentTarget: { ownerDocument: { getSelection: () => ({ isCollapsed }) } },
1812-
stopPropagation: () => {
1813-
reachedRow = false;
1814-
},
1815-
}),
1816-
);
1817-
if (reachedRow) await act(() => row().props.onClick());
1818-
};
1819-
1820-
await act(() => row().props.onClick());
1821-
expect(row().props["aria-expanded"]).toBe(true);
1822-
1823-
await clickLabel(false);
1824-
expect(row().props["aria-expanded"]).toBe(true);
1825-
1826-
await clickLabel(true);
1827-
expect(row().props["aria-expanded"]).toBe(false);
1798+
await act(() => renderer!.root.findByProps({ "aria-expanded": false }).props.onClick());
1799+
const label = renderer!.root.findAll(
1800+
(node) => node.type === "span" && String(node.props.className).includes("select-text"),
1801+
)[0];
1802+
const stopPropagation = vi.fn();
1803+
// Only the click that ends a selection may be withheld from the row
1804+
// toggle; the plain click has to reach it so the label can collapse.
1805+
for (const isCollapsed of [false, true]) {
1806+
label!.props.onClick({
1807+
currentTarget: { ownerDocument: { getSelection: () => ({ isCollapsed }) } },
1808+
stopPropagation,
1809+
});
1810+
}
1811+
expect(stopPropagation).toHaveBeenCalledTimes(1);
18281812
} finally {
18291813
await act(() => renderer?.unmount());
18301814
}

0 commit comments

Comments
 (0)