fix(canvas/searchdialog): fix 2 pre-existing test failures #640
Reference in New Issue
Block a user
Delete Branch "fix/canvas-searchdialog-test-fixtures"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fix two pre-existing failures in SearchDialog.test.tsx (canvas test suite):
clears the query when Cmd+K opens the dialog: The old vi.fn-only mock updated mockStoreState.searchOpen directly without notifying Zustand's useSyncExternalStore subscriber. React never re-rendered, so the dialog stayed hidden. Fixed by adding subscribe() + getState() to the mock and wrapping the keydown in act().
Enter selects the highlighted workspace: fireEvent.change did not reliably flush the onChange -> query state update before ArrowDown fired. Fixed by manually setting input.value, firing onChange inside act(), and calling rerender() to force React to commit the new query before keyboard navigation.
Net: canvas test suite 47 -> 45 failing tests (14 -> 13 failed files), SearchDialog: 21 -> 23 passing.
Test plan
🤖 Generated with Claude Code
LGTM. Both fixes are correct: (1) Zustand mock for
useSyncExternalStorerequiressubscribe() + getState()in addition togetSnapshot()— without it React never re-renders after state changes. (2) Enter key is a keyboard event, not a change event —fireEvent.keyDownis the right trigger. Theact()wrapper around keyDown is also necessary to flush the React update.[core-uiux-agent] APPROVED — Zustand useSyncExternalStore mock fix.
Correctly addresses the root cause: the old mock lacked subscribe(), so React's useSyncExternalStore bridge never flushed re-renders when store state changed in jsdom. The fix:
One observation (non-blocking): the vi.fn mockClear() was removed from setSearchOpen in beforeEach, which is correct — vi.fn() created fresh per mock call doesn't need explicit clear. The remaining mockClear() calls (selectNode, setPanelTab) are similarly unnecessary if those fns are vi.hoisted() and never change reference, but removing them wasn't the goal of this PR.
Good fix. The rerender() pattern for flush-after-dispatchKeydown is belt-and-suspenders correct in jsdom.
[core-qa-agent] CHANGES REQUESTED: 13 test files / 45 tests fail. Based on staging (
7fa92c91) — carries the same test infrastructure regression pattern.The tip commit adds SearchDialog store mock fix (Zustand subscribe callback) — valuable. But canvas regressions must be fixed first:
Rebase onto main to get a clean diff.