Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

test(alerts): exercise history retry inside mobile drawer

pulse-triage[bot]45e0170f77d5
diff --git a/frontend-modern/src/features/alerts/__tests__/AlertResourceIncidentsPanel.test.tsx b/frontend-modern/src/features/alerts/__tests__/AlertResourceIncidentsPanel.test.tsx
index 8c3a539631..c1eaedd601 100644
--- a/frontend-modern/src/features/alerts/__tests__/AlertResourceIncidentsPanel.test.tsx
+++ b/frontend-modern/src/features/alerts/__tests__/AlertResourceIncidentsPanel.test.tsx
@@ -2,6 +2,7 @@ import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-li
import { createSignal, type JSX } from 'solid-js';
import { afterEach, describe, expect, it, vi } from 'vitest';
+import { MobileAlertHistoryInvestigationDialog } from '../MobileAlertHistoryInvestigationDialog';
import { AlertResourceIncidentsPanel } from '../AlertResourceIncidentsPanel';
import { AlertsAPI } from '@/api/alerts';
import type { Incident } from '@/types/api';
@@ -26,58 +27,75 @@ describe('AlertResourceIncidentsPanel', () => {
vi.restoreAllMocks();
});
- it('retries through the real hook and retains cached history after a refresh failure', async () => {
- let state!: ReturnType<typeof useAlertResourceIncidentsState>;
- const read = vi.spyOn(AlertsAPI, 'getIncidentsForResource');
- read.mockRejectedValueOnce(new Error('history unavailable'));
- render(() => {
- state = useAlertResourceIncidentsState();
- return <AlertResourceIncidentsPanel state={state as AlertHistoryState} />;
- });
+ it.each(['inline', 'mobile drawer'] as const)(
+ 'retries through the real hook in the %s and retains cached history after a refresh failure',
+ async (surface) => {
+ let state!: ReturnType<typeof useAlertResourceIncidentsState>;
+ const read = vi.spyOn(AlertsAPI, 'getIncidentsForResource');
+ read.mockRejectedValueOnce(new Error('history unavailable'));
+ render(() => {
+ state = useAlertResourceIncidentsState();
+ return surface === 'inline' ? (
+ <AlertResourceIncidentsPanel state={state as AlertHistoryState} />
+ ) : (
+ <MobileAlertHistoryInvestigationDialog
+ investigation={{
+ kind: 'resource',
+ rowKey: 'row-1',
+ alert: { resourceName: 'Resource' } as Parameters<
+ typeof MobileAlertHistoryInvestigationDialog
+ >[0]['investigation']['alert'],
+ }}
+ state={state as AlertHistoryState}
+ onClose={() => state.setResourceIncidentPanel(null)}
+ />
+ );
+ });
- await state.openResourceIncidentPanel('resource-1', 'Resource', 'row-1');
- expect(screen.getByRole('alert')).toHaveTextContent('Use Refresh');
- expect(screen.queryByText('No incidents recorded for this resource yet.')).toBeNull();
+ await state.openResourceIncidentPanel('resource-1', 'Resource', 'row-1');
+ expect(screen.getByRole('alert')).toHaveTextContent('Use Refresh');
+ expect(screen.queryByText('No incidents recorded for this resource yet.')).toBeNull();
- let resolve!: (incidents: Incident[]) => void;
- read.mockImplementationOnce(
- () =>
- new Promise((done) => {
- resolve = done;
- }),
- );
- fireEvent.click(screen.getByRole('button', { name: 'Refresh' }));
- expect(screen.queryByRole('alert')).toBeNull();
- expect(screen.getByRole('button', { name: /Refresh/ })).toBeDisabled();
- resolve([
- {
- id: 'retained',
- alertType: 'connectivity',
- level: 'critical',
- status: 'resolved',
- acknowledged: false,
- events: [],
- openedAt: '2026-09-08T00:00:00Z',
- message: 'Retained connection incident',
- } as Incident,
- ]);
- await waitFor(() => expect(screen.getByText('Retained connection incident')).toBeVisible());
- expect(read).toHaveBeenLastCalledWith('resource-1', 10);
+ let resolve!: (incidents: Incident[]) => void;
+ read.mockImplementationOnce(
+ () =>
+ new Promise((done) => {
+ resolve = done;
+ }),
+ );
+ fireEvent.click(screen.getByRole('button', { name: 'Refresh' }));
+ expect(screen.queryByRole('alert')).toBeNull();
+ expect(screen.getByRole('button', { name: /Refresh/ })).toBeDisabled();
+ resolve([
+ {
+ id: 'retained',
+ alertType: 'connectivity',
+ level: 'critical',
+ status: 'resolved',
+ acknowledged: false,
+ events: [],
+ openedAt: '2026-09-08T00:00:00Z',
+ message: 'Retained connection incident',
+ } as Incident,
+ ]);
+ await waitFor(() => expect(screen.getByText('Retained connection incident')).toBeVisible());
+ expect(read).toHaveBeenLastCalledWith('resource-1', 10);
- read.mockRejectedValueOnce(new Error('refresh unavailable'));
- fireEvent.click(screen.getByRole('button', { name: 'Refresh' }));
- await waitFor(() => expect(screen.getByRole('alert')).toHaveTextContent('Use Refresh'));
- expect(screen.getByText('Retained connection incident')).toBeVisible();
- expect(screen.queryByText('No incidents recorded for this resource yet.')).toBeNull();
+ read.mockRejectedValueOnce(new Error('refresh unavailable'));
+ fireEvent.click(screen.getByRole('button', { name: 'Refresh' }));
+ await waitFor(() => expect(screen.getByRole('alert')).toHaveTextContent('Use Refresh'));
+ expect(screen.getByText('Retained connection incident')).toBeVisible();
+ expect(screen.queryByText('No incidents recorded for this resource yet.')).toBeNull();
- read.mockResolvedValueOnce([]);
- fireEvent.click(screen.getByRole('button', { name: 'Refresh' }));
- await waitFor(() =>
- expect(screen.getByText('No incidents recorded for this resource yet.')).toBeVisible(),
- );
- expect(screen.queryByRole('alert')).toBeNull();
- expect(screen.queryByText('Retained connection incident')).toBeNull();
- });
+ read.mockResolvedValueOnce([]);
+ fireEvent.click(screen.getByRole('button', { name: 'Refresh' }));
+ await waitFor(() =>
+ expect(screen.getByText('No incidents recorded for this resource yet.')).toBeVisible(),
+ );
+ expect(screen.queryByRole('alert')).toBeNull();
+ expect(screen.queryByText('Retained connection incident')).toBeNull();
+ },
+ );
it('shows persistent read failure without claiming an empty history', () => {
const [failed, setFailed] = createSignal(true);