teqo/tests/e2e/campaignConcepts.e2e.spec.ts
Francisco Ignácio Fontoura Solla 4806c417c8 Engineering Pass 3: consolidate patterns and lock them with guards.
Fold duplicated campanha access, loaders, list/filter/form shells, and scripts into shared modules; reorganize utilities by domain; stabilize e2e; and document prevention-first audit workflow so the same smells cannot creep back in.
2026-07-29 06:11:29 -03:00

74 lines
3.2 KiB
TypeScript

import { campaignConceptHref } from '../../src/lib/campaignIntelligenceConcepts.js'
import { expect, test } from './fixtures/campaignE2EFixtures.js'
/**
* E18 — `/campanha/conceitos` documents staff-only numbers (estimates, goals,
* field ceiling), so the route gate and the "Saiba mais" path out of the
* "Conta da cadeira" card are what these tests protect.
*/
test.describe('Conceitos de inteligência', () => {
test('staff reads the concepts page and reaches it from the goal-account card', async ({
campaign,
page,
}) => {
const { fixtures } = campaign
const coordinator = await fixtures.createCampaignUser('coordinator', {
name: fixtures.value('Coordenadora Conceitos'),
})
const password = coordinator.password
const email = coordinator.email!
const municipality = await fixtures.claimMunicipality()
await campaign.login(page, email, password)
// Always-visible way in, at the foot of the sidebar.
await page.getByRole('link', { name: 'Conceitos', exact: true }).click()
await expect(page).toHaveURL(/\/campanha\/conceitos$/)
await page.goto(`/campanha/municipios/${municipality.slug}`)
const goalAccount = page.getByRole('region', { name: 'Conta da cadeira' })
await expect(goalAccount).toBeVisible()
// Per-metric tooltips carry a deep link to the matching anchor.
await goalAccount.getByRole('button', { name: /Captura \(2022\): mais informações/ }).hover()
// Radix mirrors tooltip content for screen readers, so the link renders twice.
await expect(page.getByRole('link', { name: 'Saiba mais' }).first()).toHaveAttribute(
'href',
campaignConceptHref('captura'),
)
// The card-level Popover is the keyboard-reachable path (tooltip content is not tabbable).
await goalAccount.getByRole('button', { name: 'Sobre a conta da cadeira' }).click()
await page.getByRole('link', { name: 'Como cada número é calculado' }).click()
await expect(page).toHaveURL(/\/campanha\/conceitos$/)
await expect(
page.getByRole('heading', { level: 1, name: 'Conceitos de inteligência' }),
).toBeVisible()
await expect(page.getByRole('heading', { name: 'Cobertura da meta' })).toBeVisible()
await expect(page.getByRole('heading', { name: 'Teto do campo (projetado)' })).toBeVisible()
// Deep link lands on the documented concept, not just on the page.
await page.goto(campaignConceptHref('captura'))
await expect(page.locator('article:target')).toHaveAttribute('id', 'captura')
})
test('leader cannot open the concepts page', async ({ campaign, page }) => {
const { fixtures } = campaign
const phone = fixtures.phone()
const leader = await fixtures.createCampaignUser('leader', {
name: fixtures.value('Liderança Conceitos'),
username: phone,
})
const password = leader.password
await campaign.login(page, phone, password)
await expect(page.getByRole('link', { name: 'Conceitos', exact: true })).toHaveCount(0)
await page.goto('/campanha/conceitos')
await expect(page).toHaveURL(/\/campanha\/?$/)
await expect(
page.getByRole('heading', { level: 1, name: 'Conceitos de inteligência' }),
).toHaveCount(0)
})
})