OH14 — harden e2e for always-on hybrid sync

- 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
This commit is contained in:
Cursor Agent 2026-08-02 04:53:29 +00:00
parent 80587e33c5
commit fb18bc8044
No known key found for this signature in database
5 changed files with 41 additions and 11 deletions

View file

@ -20,7 +20,7 @@ test.describe('Lideranças — shell (OH8)', () => {
await page.goto(`${campaign.baseURL}/campanha/liderancas`) await page.goto(`${campaign.baseURL}/campanha/liderancas`)
await expect(page.getByRole('heading', { name: 'Lideranças', exact: true })).toBeVisible() await expect(page.getByRole('heading', { name: 'Lideranças', exact: true })).toBeVisible()
await expect(page.getByLabel('Buscar liderança por nome')).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()
}) })
}) })

View file

@ -89,7 +89,7 @@ test.describe('Municípios — jornadas por papel', () => {
// the freshness column the ordering is paired with. `exact` keeps this off // the freshness column the ordering is paired with. `exact` keeps this off
// the table caption, which embeds the same summary plus column glossary. // the table caption, which embeds the same summary plus column glossary.
await expect( 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() ).toBeVisible()
await expect( await expect(
page.getByRole('columnheader', { name: /Ordenar por Frescor do sinal/ }), 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 // (visually a hover-only preview otherwise), so assert against that
// unique, unambiguous string rather than a bare "5.000" substring — // unique, unambiguous string rather than a bare "5.000" substring —
// that also matches the (opacity-0 but DOM-visible) hover-preview span. // 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() 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 page.goto(`${campaign.baseURL}/campanha/municipios/${administered.slug}?tab=leaderships`)
await expect(page.getByRole('link', { name: contact.name })).toBeVisible() 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.getByLabel('Quantos votos a liderança traz neste município?').fill('250')
await page.getByRole('button', { name: 'Declarar' }).click() await Promise.all([
await expect(page.getByText('Declaração de votos registrada.')).toBeVisible() 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. // Advisor records an internal estimate on the overview pledges panel.
await page.goto(`${campaign.baseURL}/campanha/municipios/${administered.slug}`) await page.goto(`${campaign.baseURL}/campanha/municipios/${administered.slug}`)

View file

@ -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. */ /** 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'] })
@ -45,6 +45,7 @@ test.describe('OH6 estimate outbox', () => {
response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET', response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET',
{ timeout: 30_000 }, { timeout: 30_000 },
) )
await waitForCampaignServiceWorker(page)
await page.context().setOffline(true) await page.context().setOffline(true)
await page.getByLabel('Média', { exact: true }).fill('55') 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 page.getByRole('button', { name: 'Salvar estimativa' }).click()
await expect(page.getByText('Pendente', { exact: true })).toBeVisible() await expect(page.getByText('Pendente', { exact: true })).toBeVisible()
await page.reload() await reloadWhileOffline(page)
await expect(page.getByText('Pendente', { exact: true })).toBeVisible() await expect(page.getByText('Pendente', { exact: true })).toBeVisible()
await page.context().setOffline(false) await page.context().setOffline(false)

View file

@ -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. */ /** 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'] })
@ -47,6 +47,7 @@ test.describe('OH9/OH11 campaign ops offline', () => {
response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET', response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET',
{ timeout: 30_000 }, { timeout: 30_000 },
) )
await waitForCampaignServiceWorker(page)
await page.context().setOffline(true) 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', response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET',
{ timeout: 30_000 }, { timeout: 30_000 },
) )
await waitForCampaignServiceWorker(page)
await page.context().setOffline(true) 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 page.getByRole('button', { name: 'Salvar estimativa' }).click()
await expect(page.getByText('Pendente', { exact: true })).toBeVisible() await expect(page.getByText('Pendente', { exact: true })).toBeVisible()
await page.reload() await reloadWhileOffline(page)
await expect(page.getByText('Pendente', { exact: true })).toBeVisible() await expect(page.getByText('Pendente', { exact: true })).toBeVisible()
await page.context().setOffline(false) 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', response.url().includes('/campanha/api/ops-sync') && response.request().method() === 'GET',
{ timeout: 30_000 }, { timeout: 30_000 },
) )
await waitForCampaignServiceWorker(page)
await page.context().setOffline(true) await page.context().setOffline(true)
await expect( await expect(
@ -150,9 +153,11 @@ test.describe('OH12 municipality list Local', () => {
const search = page.getByLabel('Buscar município') const search = page.getByLabel('Buscar município')
await search.fill(municipality.name) 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( await expect(
page.getByText('Edição na lista disponível quando estiveres online.'), page.getByText('Edição na lista disponível quando estiveres online.'),
).toBeVisible() ).toBeVisible()

View file

@ -455,6 +455,27 @@ export const expectPostResponse = (page: Page, urlFragment: string) =>
response.ok(), 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<void> => {
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<void> => {
await waitForCampaignServiceWorker(page)
await page.reload({ waitUntil: 'domcontentloaded' })
}
/** /**
* Checks a Radix Checkbox only once the page has hydrated. A Radix checkbox is * 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 * a button whose hidden input is synced by React, so a click that lands BEFORE