diff --git a/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts b/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts index 9f544373..4b117f70 100644 --- a/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts +++ b/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts @@ -6,7 +6,11 @@ import { } from './fixtures/campaignE2EFixtures.js' /** Offline specs intentionally hit blocked network resources — allowlist for the guard. */ -test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] }) +test.use({ + expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'], + expectedRequestFailurePathPrefixes: ['/campanha'], + allowOfflineRscPrefetchErrors: true, +}) /** OH6 — flaky-network outbox for estimateVotes. */ test.describe('OH6 estimate outbox', () => { diff --git a/tests/e2e/campaignOpsOffline.e2e.spec.ts b/tests/e2e/campaignOpsOffline.e2e.spec.ts index ca9f5eb3..95e6f71a 100644 --- a/tests/e2e/campaignOpsOffline.e2e.spec.ts +++ b/tests/e2e/campaignOpsOffline.e2e.spec.ts @@ -6,7 +6,11 @@ import { } from './fixtures/campaignE2EFixtures.js' /** Offline specs intentionally hit blocked network resources — allowlist for the guard. */ -test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] }) +test.use({ + expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'], + expectedRequestFailurePathPrefixes: ['/campanha'], + allowOfflineRscPrefetchErrors: true, +}) /** OH9/OH11/OH12 — dual-path municipality detail + offline journey + list Local. */ test.describe('OH9/OH11 campaign ops offline', () => { diff --git a/tests/e2e/campaignTerritories.e2e.spec.ts b/tests/e2e/campaignTerritories.e2e.spec.ts index 165a12ad..1687946e 100644 --- a/tests/e2e/campaignTerritories.e2e.spec.ts +++ b/tests/e2e/campaignTerritories.e2e.spec.ts @@ -40,11 +40,11 @@ test.describe('Territórios de Identidade', () => { await campaign.login(page, coordinator.email!, coordinator.password) await page.goto('/campanha/territorios') - await expect(page.getByText(/27 territórios encontrados/)).toBeVisible() + await expect(page.getByText(/27 territórios encontrados/).first()).toBeVisible() await page.getByRole('link', { name: 'Ir para a página 2' }).click() await expect(page).toHaveURL(/\/campanha\/territorios\?page=2/) - await expect(page.getByText(/27 territórios encontrados/)).toBeVisible() + await expect(page.getByText(/27 territórios encontrados/).first()).toBeVisible() }) test('parent territory rows expose hash anchor ids for deep links', async ({ @@ -61,8 +61,8 @@ test.describe('Territórios de Identidade', () => { await campaign.login(page, email, password) await page.goto('/campanha/territorios') - await expect(page.locator('#ti-irece')).toBeVisible() - await expect(page.locator('#ti-velho-chico')).toBeVisible() + await expect(page.locator('#ti-irece').first()).toBeVisible() + await expect(page.locator('#ti-velho-chico').first()).toBeVisible() }) test('leader cannot open the territories page', async ({ campaign, page }) => { diff --git a/tests/e2e/campaignWebAuthn.e2e.spec.ts b/tests/e2e/campaignWebAuthn.e2e.spec.ts index db6d0b59..51e6fc5e 100644 --- a/tests/e2e/campaignWebAuthn.e2e.spec.ts +++ b/tests/e2e/campaignWebAuthn.e2e.spec.ts @@ -74,7 +74,7 @@ test('enrolls a passkey, signs in with it, then revokes it', async ({ await expectCampaignBiometricsReady(page) await page.goto('/campanha/perfil') - await expect(page.getByText('Nenhum aparelho cadastrado ainda.')).toBeVisible() + await expect(page.getByRole('main').getByText('Nenhum aparelho cadastrado ainda.')).toBeVisible() const deviceLabel = page.getByLabel('Nome deste aparelho') await expect(deviceLabel).toBeVisible() @@ -82,7 +82,7 @@ test('enrolls a passkey, signs in with it, then revokes it', async ({ await page.getByRole('button', { name: 'Ativar neste aparelho' }).click() await expect(page.getByText('Celular da assessora')).toBeVisible({ timeout: CEREMONY_TIMEOUT }) - await expect(page.getByText('Nenhum aparelho cadastrado ainda.')).toBeHidden() + await expect(page.getByRole('main').getByText('Nenhum aparelho cadastrado ainda.')).toBeHidden() // 2. Password-less sign-in issues the 14-day cookie — enrolling the device IS // the "remember me" opt-in, so there is no checkbox in this path. @@ -103,7 +103,7 @@ test('enrolls a passkey, signs in with it, then revokes it', async ({ // the profile and it has to actually stop the credential. await page.goto('/campanha/perfil') await page.getByRole('button', { name: 'Remover Celular da assessora' }).click() - await expect(page.getByText('Nenhum aparelho cadastrado ainda.')).toBeVisible() + await expect(page.getByRole('main').getByText('Nenhum aparelho cadastrado ainda.')).toBeVisible() await context.clearCookies() await page.goto('/campanha/login') diff --git a/tests/e2e/fixtures/e2eTest.ts b/tests/e2e/fixtures/e2eTest.ts index 77f53434..d6046a74 100644 --- a/tests/e2e/fixtures/e2eTest.ts +++ b/tests/e2e/fixtures/e2eTest.ts @@ -27,6 +27,10 @@ type E2EFailureGuardFixtures = { * mid-test. */ expectedRequestFailurePaths: string[] + /** Pathname prefix allowlist for intentional offline prefetch failures. */ + expectedRequestFailurePathPrefixes: string[] + /** Next.js RSC prefetch console noise while the browser context is offline. */ + allowOfflineRscPrefetchErrors: boolean } const loadFailurePrefix = 'Failed to load resource' @@ -49,6 +53,8 @@ const isAllowedConsoleError = ( message: ConsoleMessage, origin: string | null, expectedRequestFailurePaths: string[], + expectedRequestFailurePathPrefixes: string[], + allowOfflineRscPrefetchErrors: boolean, ): boolean => { const { url } = message.location() if (!url || origin === null) return false @@ -59,23 +65,50 @@ const isAllowedConsoleError = ( // The app intentionally has no /favicon.ico asset yet. if (message.text() === missingFaviconConsoleError) return location.pathname === '/favicon.ico' - return ( - message.text().startsWith(loadFailurePrefix) && - expectedRequestFailurePaths.includes(location.pathname) - ) + if ( + allowOfflineRscPrefetchErrors && + message.text().includes('Failed to fetch RSC payload') && + message.text().includes('/campanha') + ) { + return true + } + + const pathAllowed = + expectedRequestFailurePaths.includes(location.pathname) || + expectedRequestFailurePathPrefixes.some((prefix) => location.pathname.startsWith(prefix)) + + return message.text().startsWith(loadFailurePrefix) && pathAllowed } export const test = base.extend({ expectedRequestFailurePaths: [[], { option: true }], + expectedRequestFailurePathPrefixes: [[], { option: true }], + allowOfflineRscPrefetchErrors: [false, { option: true }], e2eFailureGuard: [ - async ({ baseURL, context, expectedRequestFailurePaths, page }, use) => { + async ( + { + baseURL, + context, + expectedRequestFailurePaths, + expectedRequestFailurePathPrefixes, + allowOfflineRscPrefetchErrors, + page, + }, + use, + ) => { const failures: BrowserFailure[] = [] const origin = baseURL ? new URL(baseURL).origin : null const onConsole = (message: ConsoleMessage) => { if ( message.type() !== 'error' || - isAllowedConsoleError(message, origin, expectedRequestFailurePaths) + isAllowedConsoleError( + message, + origin, + expectedRequestFailurePaths, + expectedRequestFailurePathPrefixes, + allowOfflineRscPrefetchErrors, + ) ) { return }