From fb18bc8044b67f571c38b2a82e1f0f7cb826f6b8 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Aug 2026 04:53:29 +0000 Subject: [PATCH] =?UTF-8?q?OH14=20=E2=80=94=20harden=20e2e=20for=20always-?= =?UTF-8?q?on=20hybrid=20sync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add SW wait + offline-safe reload helpers for OH6/OH11 - Fix strict-mode duplicate locators (OH8, coordinator journey) - Declare-votes journey asserts CAS POST + Atualizar (no legacy toast) - OH12 local list: debounced search instead of Enter navigation --- tests/e2e/campaignLeaderships.e2e.spec.ts | 2 +- tests/e2e/campaignMunicipalities.e2e.spec.ts | 11 ++++++---- .../e2e/campaignOpsEstimateOutbox.e2e.spec.ts | 5 +++-- tests/e2e/campaignOpsOffline.e2e.spec.ts | 13 ++++++++---- tests/e2e/fixtures/campaignE2EFixtures.ts | 21 +++++++++++++++++++ 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/tests/e2e/campaignLeaderships.e2e.spec.ts b/tests/e2e/campaignLeaderships.e2e.spec.ts index 2a311546..4e37600e 100644 --- a/tests/e2e/campaignLeaderships.e2e.spec.ts +++ b/tests/e2e/campaignLeaderships.e2e.spec.ts @@ -20,7 +20,7 @@ test.describe('Lideranças — shell (OH8)', () => { await page.goto(`${campaign.baseURL}/campanha/liderancas`) await expect(page.getByRole('heading', { name: 'Lideranças', exact: true })).toBeVisible() await expect(page.getByLabel('Buscar liderança por nome')).toBeVisible() - await expect(page.getByText(/\d+ lideranças/)).toBeVisible() + await expect(page.getByText(/\d+ lideranças/).first()).toBeVisible() }) }) diff --git a/tests/e2e/campaignMunicipalities.e2e.spec.ts b/tests/e2e/campaignMunicipalities.e2e.spec.ts index 769b5a22..2a9f4900 100644 --- a/tests/e2e/campaignMunicipalities.e2e.spec.ts +++ b/tests/e2e/campaignMunicipalities.e2e.spec.ts @@ -89,7 +89,7 @@ test.describe('Municípios — jornadas por papel', () => { // the freshness column the ordering is paired with. `exact` keeps this off // the table caption, which embeds the same summary plus column glossary. await expect( - page.getByText('Ordenado por Cobertura (maior déficit primeiro)', { exact: true }), + page.getByText('Ordenado por Cobertura (maior déficit primeiro)', { exact: true }).first(), ).toBeVisible() await expect( page.getByRole('columnheader', { name: /Ordenar por Frescor do sinal/ }), @@ -118,7 +118,7 @@ test.describe('Municípios — jornadas por papel', () => { // (visually a hover-only preview otherwise), so assert against that // unique, unambiguous string rather than a bare "5.000" substring — // that also matches the (opacity-0 but DOM-visible) hover-preview span. - await expect(page.getByText('Otimista: 5.000')).toBeVisible() + await expect(page.getByText('Otimista: 5.000').first()).toBeVisible() await expect(page.getByText(`Assessoria: ${advisor.name}`)).toBeVisible() }) @@ -337,8 +337,11 @@ test.describe('Municípios — jornadas por papel', () => { await page.goto(`${campaign.baseURL}/campanha/municipios/${administered.slug}?tab=leaderships`) await expect(page.getByRole('link', { name: contact.name })).toBeVisible() await page.getByLabel('Quantos votos a liderança traz neste município?').fill('250') - await page.getByRole('button', { name: 'Declarar' }).click() - await expect(page.getByText('Declaração de votos registrada.')).toBeVisible() + await Promise.all([ + expectPostResponse(page, `/campanha/municipios/${administered.slug}`), + page.getByRole('button', { name: 'Declarar' }).click(), + ]) + await expect(page.getByRole('button', { name: 'Atualizar' })).toBeVisible() // Advisor records an internal estimate on the overview pledges panel. await page.goto(`${campaign.baseURL}/campanha/municipios/${administered.slug}`) diff --git a/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts b/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts index 88436948..d7f2a650 100644 --- a/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts +++ b/tests/e2e/campaignOpsEstimateOutbox.e2e.spec.ts @@ -1,4 +1,4 @@ -import { expect, test } from './fixtures/campaignE2EFixtures.js' +import { expect, reloadWhileOffline, test, waitForCampaignServiceWorker } from './fixtures/campaignE2EFixtures.js' /** Offline specs intentionally hit blocked network resources — allowlist for the guard. */ test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] }) @@ -45,6 +45,7 @@ test.describe('OH6 estimate outbox', () => { response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET', { timeout: 30_000 }, ) + await waitForCampaignServiceWorker(page) await page.context().setOffline(true) await page.getByLabel('Média', { exact: true }).fill('55') @@ -52,7 +53,7 @@ test.describe('OH6 estimate outbox', () => { await page.getByRole('button', { name: 'Salvar estimativa' }).click() await expect(page.getByText('Pendente', { exact: true })).toBeVisible() - await page.reload() + await reloadWhileOffline(page) await expect(page.getByText('Pendente', { exact: true })).toBeVisible() await page.context().setOffline(false) diff --git a/tests/e2e/campaignOpsOffline.e2e.spec.ts b/tests/e2e/campaignOpsOffline.e2e.spec.ts index 5174d0e1..6aa34c75 100644 --- a/tests/e2e/campaignOpsOffline.e2e.spec.ts +++ b/tests/e2e/campaignOpsOffline.e2e.spec.ts @@ -1,4 +1,4 @@ -import { expect, test } from './fixtures/campaignE2EFixtures.js' +import { expect, reloadWhileOffline, test, waitForCampaignServiceWorker } from './fixtures/campaignE2EFixtures.js' /** Offline specs intentionally hit blocked network resources — allowlist for the guard. */ test.use({ expectedRequestFailurePaths: ['/campanha/api/ops-sync', '/favicon.ico'] }) @@ -47,6 +47,7 @@ test.describe('OH9/OH11 campaign ops offline', () => { response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET', { timeout: 30_000 }, ) + await waitForCampaignServiceWorker(page) await page.context().setOffline(true) @@ -101,6 +102,7 @@ test.describe('OH9/OH11 campaign ops offline', () => { response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET', { timeout: 30_000 }, ) + await waitForCampaignServiceWorker(page) await page.context().setOffline(true) @@ -110,7 +112,7 @@ test.describe('OH9/OH11 campaign ops offline', () => { await page.getByRole('button', { name: 'Salvar estimativa' }).click() await expect(page.getByText('Pendente', { exact: true })).toBeVisible() - await page.reload() + await reloadWhileOffline(page) await expect(page.getByText('Pendente', { exact: true })).toBeVisible() await page.context().setOffline(false) @@ -142,6 +144,7 @@ test.describe('OH12 municipality list Local', () => { response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET', { timeout: 30_000 }, ) + await waitForCampaignServiceWorker(page) await page.context().setOffline(true) await expect( @@ -150,9 +153,11 @@ test.describe('OH12 municipality list Local', () => { const search = page.getByLabel('Buscar município') await search.fill(municipality.name) - await search.press('Enter') + await expect(page.getByRole('link', { name: municipality.name })).toBeVisible({ + timeout: 15_000, + }) - await expect(page.getByRole('heading', { name: 'Municípios' })).toBeVisible() + await expect(page.getByRole('heading', { name: 'Municípios', exact: true }).first()).toBeVisible() await expect( page.getByText('Edição na lista disponível quando estiveres online.'), ).toBeVisible() diff --git a/tests/e2e/fixtures/campaignE2EFixtures.ts b/tests/e2e/fixtures/campaignE2EFixtures.ts index 643da103..d5534238 100644 --- a/tests/e2e/fixtures/campaignE2EFixtures.ts +++ b/tests/e2e/fixtures/campaignE2EFixtures.ts @@ -455,6 +455,27 @@ export const expectPostResponse = (page: Page, urlFragment: string) => response.ok(), ) +/** + * Production e2e (`pnpm start`) registers the campaign SW; offline reload + * specs need a controlling worker so navigation is served from Cache Storage. + */ +export const waitForCampaignServiceWorker = async (page: Page): Promise => { + await expect(async () => { + const ready = await page.evaluate(async () => { + if (!('serviceWorker' in navigator)) return false + await navigator.serviceWorker.ready + return navigator.serviceWorker.controller !== null + }) + expect(ready).toBe(true) + }).toPass({ timeout: 30_000 }) +} + +/** Reload while the browser context is offline — requires SW (production e2e). */ +export const reloadWhileOffline = async (page: Page): Promise => { + await waitForCampaignServiceWorker(page) + await page.reload({ waitUntil: 'domcontentloaded' }) +} + /** * Checks a Radix Checkbox only once the page has hydrated. A Radix checkbox is * a button whose hidden input is synced by React, so a click that lands BEFORE