From 9765b19691d09455ad887f57d5f6642fea5e4c59 Mon Sep 17 00:00:00 2001 From: Bryandero98 Date: Thu, 3 Sep 2026 14:36:34 -0500 Subject: [PATCH] test: fix flaky BrowseTab Save-button query racing the Edit transition (#6051) openEditor and clickSave used synchronous getByRole/getByText queries right after a fireEvent.click that triggers an async state transition. Under full- suite CPU contention that occasionally ran before React committed the new state, even though it reliably passed in isolation. Both helpers now await findByRole so the query itself waits for the transition to settle instead of racing it. Co-Authored-By: Claude Sonnet 5 --- client/src/components/wiki/tabs/BrowseTab.test.jsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/src/components/wiki/tabs/BrowseTab.test.jsx b/client/src/components/wiki/tabs/BrowseTab.test.jsx index 9f21a9f4a5..bd9541f495 100644 --- a/client/src/components/wiki/tabs/BrowseTab.test.jsx +++ b/client/src/components/wiki/tabs/BrowseTab.test.jsx @@ -104,11 +104,16 @@ describe('BrowseTab iCloud force save', () => { renderTab(); fireEvent.click(screen.getByText('Example Source')); fireEvent.click(await screen.findByRole('button', { name: 'Edit' })); + // Clicking Edit swaps the button row for the Save/Cancel pair — under + // full-suite contention that re-render doesn't always land before the + // next synchronous query runs, so wait for it here rather than assuming + // it's already mounted at every clickSave() call site (#6051). + await screen.findByRole('button', { name: /Save/ }); }; const clickSave = async () => { const before = api.updateNote.mock.calls.length; - fireEvent.click(screen.getByRole('button', { name: /Save/ })); + fireEvent.click(await screen.findByRole('button', { name: /Save/ })); await waitFor(() => expect(api.updateNote.mock.calls.length).toBe(before + 1)); };