mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-26 21:53:06 +00:00
OH8 — pins de caracterização (detalhe município + listas-chave)
- int: view model do detalhe, painel de pledges e tabs resolvidas - e2e: header/tab/pledges/editar (staff) e lockdown do leader - e2e: shell das listas municipios e liderancas (titulo, busca, paginacao) Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
parent
d909e3d28d
commit
ce68a46f21
4 changed files with 235 additions and 0 deletions
|
|
@ -6,6 +6,24 @@ import { expect, expectPostResponse, test } from './fixtures/campaignE2EFixtures
|
|||
* pointer — no "Salvar", the "×" only on hover).
|
||||
*/
|
||||
|
||||
/**
|
||||
* OH8 — list shell pins (title, search, result count) before OH12 reuses the factory.
|
||||
*/
|
||||
test.describe('Lideranças — shell (OH8)', () => {
|
||||
test('exposes title, search, and result count on the list', async ({ campaign, page }) => {
|
||||
const { fixtures } = campaign
|
||||
const coordinator = await fixtures.createCampaignUser('coordinator', {
|
||||
name: fixtures.value('Coordenador Shell Lideranças'),
|
||||
})
|
||||
|
||||
await campaign.login(page, coordinator.email!, coordinator.password)
|
||||
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()
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('campaign leaderships list', () => {
|
||||
test('coordinator edits support status in the cell with auto-save (B32)', async ({
|
||||
campaign,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,25 @@ import {
|
|||
* delete the row a parallel spec is using.
|
||||
*/
|
||||
|
||||
/**
|
||||
* OH8 — list shell pins (title, search, pagination footer) before OH12 reuses the factory.
|
||||
*/
|
||||
test.describe('Municípios — shell (OH8)', () => {
|
||||
test('exposes title, search, and pagination on the list', async ({ campaign, page }) => {
|
||||
const { fixtures } = campaign
|
||||
const coordinator = await fixtures.createCampaignUser('coordinator', {
|
||||
name: fixtures.value('Coordenador Shell'),
|
||||
})
|
||||
|
||||
await campaign.login(page, coordinator.email!, coordinator.password)
|
||||
await page.goto(`${campaign.baseURL}/campanha/municipios`)
|
||||
await expect(page.getByRole('heading', { name: 'Municípios', exact: true })).toBeVisible()
|
||||
await expect(page.getByLabel('Buscar município')).toBeVisible()
|
||||
await expect(page.getByText(/\d+ municípios encontrados/)).toBeVisible()
|
||||
await expect(page.getByRole('link', { name: 'Ir para a próxima página' })).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
test.describe('Municípios — jornadas por papel', () => {
|
||||
test('coordinator opens the municipalities list, edits strategy and assigns an advisor', async ({
|
||||
campaign,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
import { expect, test } from './fixtures/campaignE2EFixtures.js'
|
||||
|
||||
/**
|
||||
* OH8 — characterization pins for `/campanha/municipios/[slug]`: header chrome,
|
||||
* default tab, pledges panel (staff estimate form), and the `/editar` affordance.
|
||||
* Leaders never reach this route — the noLeader gate sends them to `/campanha/contatos`.
|
||||
*/
|
||||
|
||||
test.describe('Município detalhe — caracterização (OH8)', () => {
|
||||
test('staff sees header, overview tab, pledges panel, and edit link', async ({
|
||||
campaign,
|
||||
page,
|
||||
}) => {
|
||||
const { fixtures } = campaign
|
||||
const coordinator = await fixtures.createCampaignUser('coordinator', {
|
||||
name: fixtures.value('Coordenador OH8'),
|
||||
})
|
||||
const municipality = await fixtures.claimMunicipality()
|
||||
|
||||
const { leadershipId } = await fixtures.createStaffLeadership({
|
||||
namePrefix: 'Liderança OH8',
|
||||
municipalities: [municipality],
|
||||
supportStatus: 'engajado',
|
||||
})
|
||||
await campaign.payload.create({
|
||||
collection: 'votePledge',
|
||||
data: {
|
||||
leadership: leadershipId,
|
||||
municipality: municipality.id,
|
||||
declaredVotes: 120,
|
||||
},
|
||||
depth: 0,
|
||||
})
|
||||
|
||||
await campaign.login(page, coordinator.email!, coordinator.password)
|
||||
await page.goto(`${campaign.baseURL}/campanha/municipios/${municipality.slug}`)
|
||||
await expect(page.getByRole('heading', { name: municipality.name })).toBeVisible()
|
||||
|
||||
const overviewTab = page.getByRole('link', { name: 'Visão geral' })
|
||||
await expect(overviewTab).toHaveAttribute('aria-current', 'page')
|
||||
|
||||
const pledgesPanel = page.getByRole('region', { name: 'Votos declarados pelas lideranças' })
|
||||
await expect(pledgesPanel).toBeVisible()
|
||||
await expect(pledgesPanel.getByRole('button', { name: 'Salvar estimativa' })).toBeVisible()
|
||||
|
||||
await expect(page.getByRole('link', { name: 'Editar' })).toHaveAttribute(
|
||||
'href',
|
||||
`/campanha/municipios/${municipality.slug}/editar`,
|
||||
)
|
||||
})
|
||||
|
||||
test('leader is locked out of municipality detail (no edit link)', async ({ campaign, page }) => {
|
||||
const { fixtures } = campaign
|
||||
const municipality = await fixtures.claimMunicipality()
|
||||
const leaderPhone = fixtures.phone()
|
||||
const leaderAccount = await fixtures.createCampaignUser('leader', {
|
||||
name: fixtures.value('Liderança OH8'),
|
||||
username: leaderPhone,
|
||||
})
|
||||
|
||||
await campaign.login(page, leaderPhone, leaderAccount.password)
|
||||
await page.goto(`${campaign.baseURL}/campanha/municipios/${municipality.slug}`).catch(() => {})
|
||||
await expect(page).toHaveURL(`${campaign.baseURL}/campanha/contatos`)
|
||||
await expect(page.getByRole('link', { name: 'Editar' })).toHaveCount(0)
|
||||
})
|
||||
})
|
||||
132
tests/int/municipalityDetailCharacterization.int.spec.ts
Normal file
132
tests/int/municipalityDetailCharacterization.int.spec.ts
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
// @vitest-environment node
|
||||
|
||||
import type { Payload } from 'payload'
|
||||
import { getPayload } from 'payload'
|
||||
import { beforeAll, describe, expect, it } from 'vitest'
|
||||
|
||||
import { formatVoteEstimateRange } from '@/lib/voteEstimate'
|
||||
import config from '@/payload.config'
|
||||
import {
|
||||
buildMunicipalityDetailTabHref,
|
||||
resolveMunicipalityDetailTab,
|
||||
} from '@/utilities/municipality/municipalityDetailTabUi'
|
||||
import {
|
||||
formatMunicipalityGeographyLabel,
|
||||
municipalityKindLabels,
|
||||
} from '@/utilities/municipality/municipalityLabels'
|
||||
import {
|
||||
getMunicipalityDetailViewModel,
|
||||
resolveAccessibleMunicipalityContext,
|
||||
} from '@/utilities/municipality/municipalityPageData'
|
||||
import { loadAdvisorSummaries } from '@/utilities/municipality/municipalityViewModels'
|
||||
import { loadMunicipalityPledges } from '@/utilities/votePledgeData'
|
||||
import {
|
||||
aggregateMunicipalityPledgesFromRows,
|
||||
toMunicipalityPledgeCoverageView,
|
||||
} from '@/utilities/votePledgeViews'
|
||||
|
||||
import { installCampaignFixtures } from '../helpers/campaignFixtures'
|
||||
|
||||
let payload: Payload
|
||||
const campaignFixtures = installCampaignFixtures({
|
||||
getPayload: () => payload,
|
||||
setPayload: (nextPayload) => {
|
||||
payload = nextPayload
|
||||
},
|
||||
})
|
||||
|
||||
describe('municipality detail characterization (OH8)', () => {
|
||||
beforeAll(async () => {
|
||||
payload = await getPayload({ config: await config })
|
||||
})
|
||||
|
||||
it('pins the detail view model header fields staff surfaces reuse', async () => {
|
||||
const fixtures = campaignFixtures()
|
||||
const coordinator = await fixtures.createCampaignUser('coordinator')
|
||||
const advisor = await fixtures.createCampaignUser('advisor', {
|
||||
name: fixtures.value('Assessor Detalhe'),
|
||||
})
|
||||
const municipality = await fixtures.getMunicipality()
|
||||
const lastUpdateAt = '2026-07-15T12:00:00.000Z'
|
||||
|
||||
await payload.update({
|
||||
collection: 'municipality',
|
||||
id: municipality.id,
|
||||
data: {
|
||||
advisors: [advisor.id],
|
||||
lastUpdateAt,
|
||||
},
|
||||
depth: 0,
|
||||
overrideAccess: true,
|
||||
})
|
||||
fixtures.touchMunicipality(municipality.id)
|
||||
|
||||
const context = await resolveAccessibleMunicipalityContext(
|
||||
payload,
|
||||
coordinator,
|
||||
municipality.slug,
|
||||
)
|
||||
const view = await getMunicipalityDetailViewModel(payload, context, coordinator)
|
||||
const advisorSummaries = await loadAdvisorSummaries(payload, coordinator, view.advisorIDs)
|
||||
|
||||
expect(view.name).toBe(municipality.name)
|
||||
expect(municipalityKindLabels[view.kind]).toBeTruthy()
|
||||
expect(formatMunicipalityGeographyLabel(view)).toBe(
|
||||
formatMunicipalityGeographyLabel({
|
||||
region: view.region,
|
||||
kind: view.kind,
|
||||
zoneNumber: view.zoneNumber,
|
||||
}),
|
||||
)
|
||||
expect(view.advisorIDs).toEqual([advisor.id])
|
||||
expect(advisorSummaries.map((entry) => entry.name)).toEqual([advisor.name])
|
||||
expect(view.lastUpdateAt).toBe(lastUpdateAt)
|
||||
expect(view.strategy).not.toBeNull()
|
||||
})
|
||||
|
||||
it('pins pledge panel totals, scenario rollups, and estimate range', async () => {
|
||||
const fixtures = campaignFixtures()
|
||||
const coordinator = await fixtures.createCampaignUser('coordinator')
|
||||
const municipality = await fixtures.getMunicipality()
|
||||
fixtures.touchMunicipality(municipality.id)
|
||||
|
||||
const contact = await fixtures.createContact()
|
||||
const leadership = await fixtures.createLeadership({
|
||||
contact: contact.id,
|
||||
municipalities: [municipality.id],
|
||||
supportStatus: 'engajado',
|
||||
})
|
||||
await fixtures.createVotePledge({
|
||||
leadership: leadership.id,
|
||||
municipality: municipality.id,
|
||||
declaredVotes: 200,
|
||||
estimatedVotes: { pessimistic: 150, central: 180, optimistic: 220 },
|
||||
})
|
||||
|
||||
const pledges = await loadMunicipalityPledges(payload, coordinator, municipality.id)
|
||||
const aggregate = aggregateMunicipalityPledgesFromRows(pledges)
|
||||
const coverage = toMunicipalityPledgeCoverageView(aggregate, 'central')
|
||||
|
||||
expect(pledges).toHaveLength(1)
|
||||
expect(aggregate.declaredTotal).toBe(200)
|
||||
expect(aggregate.effectiveByScenario.pessimistic).toBe(150)
|
||||
expect(aggregate.effectiveByScenario.central).toBe(180)
|
||||
expect(aggregate.effectiveByScenario.optimistic).toBe(220)
|
||||
expect(coverage).toEqual({
|
||||
pledgeCount: 1,
|
||||
missingEstimateCount: 0,
|
||||
declaredTotal: 200,
|
||||
effectiveTotal: 180,
|
||||
})
|
||||
expect(formatVoteEstimateRange(pledges[0]!.estimatedVotes)).toBe('150–220')
|
||||
})
|
||||
|
||||
it('pins resolved detail tabs and canonical hrefs', () => {
|
||||
expect(resolveMunicipalityDetailTab({})).toBe('overview')
|
||||
expect(resolveMunicipalityDetailTab({ tab: 'elections' })).toBe('elections')
|
||||
expect(resolveMunicipalityDetailTab({ newUpdate: '1' })).toBe('updates')
|
||||
expect(buildMunicipalityDetailTabHref('salvador-ze-01', 'leaderships', {})).toBe(
|
||||
'/campanha/municipios/salvador-ze-01?tab=leaderships',
|
||||
)
|
||||
})
|
||||
})
|
||||
Loading…
Reference in a new issue