fix: improve alert notification navigation test reliability

Changed from arbitrary 500ms timeout to waitForURL with 10s timeout.
Properly skip test when no alerts are present instead of failing.
Wait for link to be fully visible before clicking to avoid race conditions.

This should fix the flaky test failure where clicking the alert link
wasn't navigating properly.
This commit is contained in:
Graham McIntire 2026-03-08 14:13:06 -05:00
parent 8fd18b08ab
commit d8fb4373db
No known key found for this signature in database

View file

@ -211,13 +211,22 @@ test.describe('Alert Workflows', () => {
test('can navigate to alerts from notification', async ({ page }) => {
await page.goto('/dashboard');
// Wait for alert link to be present (defensive check for no alerts case)
const alertLink = page.locator('a[href*="/alerts"]').first();
const hasAlertLink = await alertLink.isVisible({ timeout: 2000 }).catch(() => false);
if (await alertLink.isVisible({ timeout: 2000 }).catch(() => false)) {
await alertLink.click();
await page.waitForTimeout(500);
await expect(page).toHaveURL(/\/alerts/);
// Skip test if no alerts are present (not a failure, just no data to test)
if (!hasAlertLink) {
test.skip();
return;
}
// Ensure link is ready for interaction and click it
await alertLink.waitFor({ state: 'visible' });
await alertLink.click();
// Wait for navigation to complete (not arbitrary timeout)
await page.waitForURL(/\/alerts/, { timeout: 10000 });
});
});