From 4f99834965899184321377c6814b98e41f229390 Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 29 Jul 2026 14:37:36 +0200 Subject: [PATCH] test(admin): stop the plugin sheet test racing its own Escape MSheet binds the Escape listener in an effect, so a key fired the moment the sheet content appears can land before the listener exists. Under a loaded full-suite run that made the test fail on its own timing. It retries until the sheet is gone rather than pressing once. --- .../unit/mobile/admin/MAdminPluginsPanel.test.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/client/tests/unit/mobile/admin/MAdminPluginsPanel.test.tsx b/client/tests/unit/mobile/admin/MAdminPluginsPanel.test.tsx index ce205ecf5..cf3fa5356 100644 --- a/client/tests/unit/mobile/admin/MAdminPluginsPanel.test.tsx +++ b/client/tests/unit/mobile/admin/MAdminPluginsPanel.test.tsx @@ -77,6 +77,15 @@ function toastMessages() { return toasts.map(t => t.message); } +// MSheet binds its Escape listener in an effect, so a key fired the moment the +// sheet's content appears can land before the listener exists. Retry until the +// sheet is actually gone rather than pressing once and hoping. +const escapeUntilGone = (text: string) => + waitFor(() => { + fireEvent.keyDown(document, { key: 'Escape' }); + expect(screen.queryByText(text)).not.toBeInTheDocument(); + }); + describe('MAdminPluginsPanel — load states', () => { it('FE-MOB-PLUGP-001: shows the load error when the plugin list cannot be fetched', async () => { server.use(http.get('*/api/admin/plugins', () => HttpResponse.json({ error: 'boom' }, { status: 500 }))); @@ -1290,14 +1299,12 @@ describe('MAdminPluginsPanel — edge paths', () => { fireEvent.click(screen.getByTestId('plugin-row-menu-btn-trek-gotify')); fireEvent.click(screen.getByText('View error log')); await screen.findByText('No errors logged.'); - fireEvent.keyDown(document, { key: 'Escape' }); - await waitFor(() => expect(screen.queryByText('No errors logged.')).not.toBeInTheDocument()); + await escapeUntilGone('No errors logged.'); // Allowed hosts → Escape, from the row chip. fireEvent.click(screen.getByRole('button', { name: '1 allowed host(s)' })); await screen.findByText('No hosts added yet.'); - fireEvent.keyDown(document, { key: 'Escape' }); - await waitFor(() => expect(screen.queryByText('No hosts added yet.')).not.toBeInTheDocument()); + await escapeUntilGone('No hosts added yet.'); }); it('FE-MOB-PLUGP-087: the hosts sheet closes from its own close button too', async () => {