teqo-backup/tests/e2e/campaignRegisterDemand.e2e.spec.ts
Francisco Solla 1daaaf9f4e feat(C139): domínio de contatos — URL state, loader com vínculos e invariante de nome
Fase 2 do plano aprovado. Três módulos em src/utilities/contacts/:
- contactListUrl: contrato de params (q|gender|state|city|ausencia|vinculo|sort|dir|page),
  canonicalize, hrefs de sort e where de fonte com 'phones.value' like (ILIKE verificado
  no Postgres local).
- contactListData: loader com UM find em contact (user threadado, overrideAccess false),
  vínculos (liderancas/dobradinhas/assessores/equipe) como facets sobre o conjunto
  legível, filtro/sort/paginação em memória, nulos no fim (precedente B15).
- contactNameInvariant: lock contact-name:{normalized} + prefilter ILIKE + veredito
  exato em memória; mensagem de conflito pt-BR.

38 testes unit novos; format + tsc limpos.
2026-08-13 14:05:24 -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/meus-contatos`)
await expect(page.getByLabel(CAMPAIGN_DEMAND_BODY_LABEL)).toHaveCount(0)
})
})