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.

Await native history after controlled Backups query ticks

pulse-triage[bot]5951c99b7360
diff --git a/frontend-modern/src/features/proxmox/__tests__/ProxmoxBackupsTable.test.tsx b/frontend-modern/src/features/proxmox/__tests__/ProxmoxBackupsTable.test.tsx
index bd9ee15c90..02b61041f4 100644
--- a/frontend-modern/src/features/proxmox/__tests__/ProxmoxBackupsTable.test.tsx
+++ b/frontend-modern/src/features/proxmox/__tests__/ProxmoxBackupsTable.test.tsx
@@ -2569,6 +2569,11 @@ describe('bare Backups entry retains its assessed workspace', () => {
});
afterEach(() => vi.useRealTimers());
+ // waitFor's interval is frozen with the query timers. Drain the router's
+ // promise-based transition before asserting native history, which need not
+ // cause another DOM mutation for waitFor to observe.
+ const settleNavigation = () => vi.advanceTimersByTimeAsync(1);
+
const responseFor = (
state: 'protected' | 'attention' | 'unknown',
): ProtectionPosturesResponse => ({
@@ -2587,6 +2592,7 @@ describe('bare Backups entry retains its assessed workspace', () => {
apiFetchJSONMock.mockImplementation(() => Promise.resolve(responseFor(state)));
const historyLength = window.history.length;
mountBackupReadState();
+ await settleNavigation();
await waitFor(() => expect(window.location.pathname).toBe(`/proxmox/backups/${view}`));
expect(window.history.length).toBe(historyLength);
const row = document.querySelector(`[data-proxmox-backup-row="${table}"]`)!;
@@ -2626,9 +2632,11 @@ describe('bare Backups entry retains its assessed workspace', () => {
);
const historyLength = window.history.length;
mountBackupReadState();
+ await settleNavigation();
await screen.findByRole('link', { name: /by date/i });
expect(window.location.pathname).toBe('/proxmox/backups/');
pending.resolve(responseFor('attention'));
+ await settleNavigation();
await waitFor(() => expect(window.location.pathname).toBe('/proxmox/backups/coverage'));
expect(window.location.search).toBe('?q=pbs&node=pve-a&type=ct&operator=saved');
expect(window.location.hash).toBe('#evidence');
@@ -2641,14 +2649,17 @@ describe('bare Backups entry retains its assessed workspace', () => {
apiFetchJSONMock.mockRejectedValueOnce(new Error('Posture unavailable'));
apiFetchJSONMock.mockResolvedValue(responseFor('protected'));
mountBackupReadState();
+ await settleNavigation();
await waitFor(() => expect(window.location.pathname).toBe('/proxmox/backups/coverage'));
await screen.findByText(/Protection posture is unavailable/);
await fireEvent.click(screen.getByRole('button', { name: 'Retry protection posture' }));
await screen.findByRole('button', { name: '1 protected' });
expect(window.location.pathname).toBe('/proxmox/backups/coverage');
await fireEvent.click(screen.getByRole('link', { name: /by date/i }));
+ await settleNavigation();
const protectedCount = screen.getByRole('button', { name: '1 protected' });
await fireEvent.click(protectedCount);
+ await settleNavigation();
await waitFor(() => expect(window.location.pathname).toBe('/proxmox/backups/coverage'));
expect(new URLSearchParams(window.location.search).get('posture')).toBe('protected');
});
@@ -2662,15 +2673,42 @@ describe('bare Backups entry retains its assessed workspace', () => {
window.history.replaceState({}, '', path);
apiFetchJSONMock.mockResolvedValue(responseFor('attention'));
mountBackupReadState();
+ await settleNavigation();
await screen.findByRole('button', { name: '1 attention' });
expect(window.location.pathname + window.location.search).toBe(path);
});
+ it('does not apply an old default after the operator has explicitly chosen By date', async () => {
+ const pending = deferred<ProtectionPosturesResponse>();
+ apiFetchJSONMock.mockReturnValue(pending.promise);
+ mountBackupReadState();
+ await settleNavigation();
+ await fireEvent.click(await screen.findByRole('link', { name: /by date/i }));
+ pending.resolve(responseFor('attention'));
+ await settleNavigation();
+ await screen.findByRole('button', { name: '1 attention' });
+ expect(window.location.pathname).toBe('/proxmox/backups/date');
+ expect(screen.getByRole('link', { name: /by date/i })).toHaveAttribute('aria-current', 'page');
+ });
+
+ it('does not navigate after the pending entry is unmounted', async () => {
+ const pending = deferred<ProtectionPosturesResponse>();
+ apiFetchJSONMock.mockReturnValue(pending.promise);
+ const { unmount } = mountBackupReadState();
+ await screen.findByRole('link', { name: /by date/i });
+ unmount();
+ pending.resolve(responseFor('attention'));
+ await settleNavigation();
+ await Promise.resolve();
+ expect(window.location.pathname).toBe('/proxmox/backups');
+ });
+
it('chooses By date after a readable empty inventory without requesting an unscoped assessment', async () => {
apiFetchMock.mockImplementation((url: string) =>
Promise.resolve(jsonResponse(url.endsWith('/pve') ? emptyPVE : emptyPBS)),
);
renderInRouter(() => <ProxmoxBackupsTable emptyIcon={<span />} workloads={[]} />);
+ await settleNavigation();
await waitFor(() => expect(window.location.pathname).toBe('/proxmox/backups/date'));
expect(apiFetchJSONMock).not.toHaveBeenCalled();
await screen.findByText('No backups yet');