teqo-backup/tests/e2e/campaignRegisterDemand.e2e.spec.ts
Francisco Solla a740f1eb16 fix(e2e): first() no getByLabel('Atividade relacionada') sob duplicação transitória (flake pré-existente, precedente cd469857)
D12 (#641): strict-mode violation (2 triggers idênticos) só em runs
completos sob carga. Estado estável tem 1 match (verificado em browser);
o 2º match é duplicação transitória RSC-pending, mesma classe de cd469857.
Mesmo alvo em campaignActivity:52 (único outro uso do label em e2e).
2026-08-11 13:21:21 -03:00

91 lines
4.2 KiB
TypeScript

import { fallbackDemandTitle } from '../../src/lib/demandTitle.js'
import {
CAMPAIGN_DEMAND_ACTIVITY_LABEL,
CAMPAIGN_DEMAND_BODY_LABEL,
CAMPAIGN_DEMAND_KIND_LABEL,
} from '../../src/lib/schemas/campaignDemand.js'
import { expect, test } from './fixtures/campaignE2EFixtures.js'
test.use({ viewport: { width: 390, height: 844 } })
test.describe('Wizard "Registrar pedido" (A5/B195)', () => {
test('creates a demand from the final step and returns to the origin', async ({
campaign,
page,
}) => {
const { fixtures } = campaign
const coordinator = await fixtures.createCampaignUser('coordinator', {
name: fixtures.value('Coordenadora Geral'),
})
const municipality = await fixtures.claimMunicipality()
const description = fixtures.value(
'500 santinhos para a feira de sábado; precisa de transporte para o comício.',
)
await campaign.login(page, coordinator.email!, coordinator.password)
await page.goto(`/campanha/acoes/registrar-pedido?municipio=${municipality.slug}`)
const topBar = page.locator('[data-slot="campaign-mobile-top-bar"][data-mode="wizard"]')
await expect(topBar.getByText('Registrar pedido', { exact: true })).toBeVisible()
await expect(
topBar.getByLabel(new RegExp(`^Município em atualização: ${municipality.name}`, 'i')),
).toBeVisible()
// No big step title, no title input, no municipality selector: the single
// free-text field comes straight after Tipo and Atividade.
await expect(page.getByRole('heading', { name: 'Registrar pedido' })).toHaveCount(0)
await expect(page.getByLabel(CAMPAIGN_DEMAND_KIND_LABEL)).toBeVisible()
// `.first()`: transient RSC-pending duplication also copies the combobox
// trigger (same strict-mode flake as cd469857; observed on loaded machines).
await expect(page.getByLabel(CAMPAIGN_DEMAND_ACTIVITY_LABEL).first()).toBeVisible()
await expect(page.getByLabel(CAMPAIGN_DEMAND_BODY_LABEL)).toBeVisible()
await expect(page.locator('input[name="title"]')).toHaveCount(0)
await expect(page.locator('select[name="municipalityId"]')).toHaveCount(0)
await page.getByLabel(CAMPAIGN_DEMAND_BODY_LABEL).fill(description)
await page.getByRole('button', { name: 'Abrir demanda' }).click()
await page.waitForURL(/\/campanha\/?$/)
// The demand born from the wizard carries the derived title in the demands
// list: without a DEEPSEEK_API_KEY in the e2e app that is the truncated
// free text — asserted via the contract, not the fixture's length.
await page.goto('/campanha/demandas')
await expect(page.getByRole('link', { name: fallbackDemandTitle(description) })).toBeVisible()
})
test('goes back to the municipality search of its own flow', async ({ campaign, page }) => {
const { fixtures } = campaign
const coordinator = await fixtures.createCampaignUser('coordinator', {
name: fixtures.value('Coordenadora Geral'),
})
const municipality = await fixtures.claimMunicipality()
await campaign.login(page, coordinator.email!, coordinator.password)
await page.goto(`/campanha/acoes/registrar-pedido?municipio=${municipality.slug}`)
await expect(page.getByLabel(CAMPAIGN_DEMAND_BODY_LABEL)).toBeVisible()
await page.getByRole('link', { name: /Voltar/ }).click()
await page.waitForURL(/\/campanha\/acoes\/registrar-pedido\/?$/)
await expect(page.getByLabel('Buscar município')).toBeVisible()
})
test('keeps the final step away from leaders', async ({ campaign, page }) => {
const { fixtures } = campaign
const leader = await fixtures.createCampaignUser('leader', {
name: fixtures.value('Líder da comunidade'),
})
const municipality = await fixtures.claimMunicipality()
await campaign.login(page, leader.email!, leader.password)
// The leader lockdown redirects to the contacts home; the redirect aborts
// `goto`'s load event (ERR_ABORTED), so the redirect itself is asserted
// the same way the municipality pages do (B43).
await page
.goto(`${campaign.baseURL}/campanha/acoes/registrar-pedido?municipio=${municipality.slug}`)
.catch(() => {})
await expect(page).toHaveURL(`${campaign.baseURL}/campanha/contatos`)
await expect(page.getByLabel(CAMPAIGN_DEMAND_BODY_LABEL)).toHaveCount(0)
})
})