diff --git a/app/src/layouts/NavBar.test.tsx b/app/src/layouts/NavBar.test.tsx index c9f70d45ea3..9fc91706241 100644 --- a/app/src/layouts/NavBar.test.tsx +++ b/app/src/layouts/NavBar.test.tsx @@ -61,4 +61,22 @@ describe('NavBar', () => { }); expect(navigate).toHaveBeenCalledWith('/plots?focus=search'); }); + + it('navigates to debug on 5 clicks and stays there on 6', async () => { + const user = userEvent.setup(); + const { container } = render(); + + // 5 clicks + for (let i = 0; i < 5; i++) { + await user.click(container.querySelector('a[href="/"]')!); + } + expect(navigate).toHaveBeenCalledWith('/debug'); + navigate.mockClear(); + + // 1 more click (6 total) within the time window + await user.click(container.querySelector('a[href="/"]')!); + + // should still navigate to debug, preventing default link to / + expect(navigate).toHaveBeenCalledWith('/debug'); + }); }); diff --git a/app/src/layouts/NavBar.tsx b/app/src/layouts/NavBar.tsx index 16475be33f7..f01a51285d6 100644 --- a/app/src/layouts/NavBar.tsx +++ b/app/src/layouts/NavBar.tsx @@ -102,8 +102,6 @@ export function NavBar() { }, DEBUG_CLICK_WINDOW_MS); if (clickCountRef.current >= DEBUG_CLICK_COUNT) { e.preventDefault(); - clickCountRef.current = 0; - if (clickTimerRef.current) clearTimeout(clickTimerRef.current); navigate(paths.debug); } }, diff --git a/changelog.d/navbar-debug-click-fix.md b/changelog.d/navbar-debug-click-fix.md new file mode 100644 index 00000000000..35493935eb1 --- /dev/null +++ b/changelog.d/navbar-debug-click-fix.md @@ -0,0 +1,3 @@ +### Fixed + +- **NavBar debug rapid clicks.** Fixed an issue where clicking the logo a 6th time rapidly navigated to home instead of staying in debug. The counter no longer resets when reaching 5 clicks.