From 1be404f2d4539f86edf7a9d96062238a0390e560 Mon Sep 17 00:00:00 2001
From: "pulse-triage[bot]"
<249995291+pulse-triage[bot]@users.noreply.github.com>
Date: Sat, 5 Sep 2026 03:35:58 +0100
Subject: [PATCH] test(web): protect mobile history focus after row removal
History refreshes or filter changes can remove the card that opened an investigation. Cover the existing list-focus fallback so closing the dialog does not strand keyboard focus on the document body. Removing that fallback fails only the new test; all four tests pass after restoration.
Change-source: pulse-maintainer
---
.../__tests__/AlertHistoryMobileList.test.tsx | 43 ++++++++++++++++---
1 file changed, 36 insertions(+), 7 deletions(-)
diff --git a/frontend-modern/src/features/alerts/__tests__/AlertHistoryMobileList.test.tsx b/frontend-modern/src/features/alerts/__tests__/AlertHistoryMobileList.test.tsx
index ab1b171d1..5e0065950 100644
--- a/frontend-modern/src/features/alerts/__tests__/AlertHistoryMobileList.test.tsx
+++ b/frontend-modern/src/features/alerts/__tests__/AlertHistoryMobileList.test.tsx
@@ -43,14 +43,16 @@ function createState() {
);
const closeResourceIncidentPanel = vi.fn(() => setResourceIncidentPanel(null));
+ const [groupedAlerts, setGroupedAlerts] = createSignal([
+ {
+ label: 'Today (August 4th)',
+ fullLabel: 'Today, August 4th 2026',
+ alerts: [alert],
+ },
+ ]);
+
const state = {
- groupedAlerts: () => [
- {
- label: 'Today (August 4th)',
- fullLabel: 'Today, August 4th 2026',
- alerts: [alert],
- },
- ],
+ groupedAlerts,
getIncidentRowKey: () => 'alert-1-row',
expandedIncidents,
incidentLoading: () => ({}),
@@ -81,6 +83,7 @@ function createState() {
closeResourceIncidentPanel,
openResourceIncidentPanel,
state,
+ setGroupedAlerts,
toggleIncidentTimeline,
};
}
@@ -171,3 +174,29 @@ describe('AlertHistoryMobileList', () => {
expect(screen.getByRole('button', { name: 'Resource' })).toHaveFocus();
});
});
+
+describe('AlertHistoryMobileList changing history', () => {
+ it('returns focus to the list when the investigated row disappears', async () => {
+ const { closeResourceIncidentPanel, setGroupedAlerts, state } = createState();
+ render(() => );
+
+ const resourceButton = screen.getByRole('button', { name: 'Resource' });
+ resourceButton.focus();
+ await fireEvent.click(resourceButton);
+ expect(screen.getByRole('dialog', {
+ name: 'Resource incidents for pve-production-01',
+ })).toBeInTheDocument();
+
+ // A refresh or filter change can remove the originating history card.
+ setGroupedAlerts([]);
+ expect(resourceButton).not.toBeInTheDocument();
+ await fireEvent.keyDown(document, { key: 'Escape' });
+ await new Promise((resolve) =>
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve())),
+ );
+
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
+ expect(closeResourceIncidentPanel).toHaveBeenCalledOnce();
+ expect(screen.getByTestId('alert-history-mobile-list')).toHaveFocus();
+ });
+});