teqo-backup/tests/unit/nucleusElectoralBaselineUi.unit.spec.ts
Francisco Ignácio Fontoura Solla 94f0bd51f8 Deliver A5 ticket leverage and flip insights with simplify cleanup.
Surface majoritarian base conversion and proportional flip opportunity on nucleus detail and list overview, precompute ticketFlip on the baseline VM, and register post-simplify scale debts in A7 F5 and E7.
2026-07-19 17:34:06 -03:00

104 lines
3.8 KiB
TypeScript

import { createElement } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it } from 'vitest'
import { NucleusElectoralBaseline } from '@/components/campaign/NucleusElectoralBaseline'
import { NucleusInsights } from '@/components/campaign/NucleusInsights'
import { computeTicketFlipOpportunity } from '@/lib/electionInsights'
import type { NucleusElectoralBaselineViewModel } from '@/utilities/nucleusViewModels'
const baseline: NucleusElectoralBaselineViewModel = {
candidate: { votes: 850, rank: 2 },
president: { votes: 1480, turn: 2 },
governor: { votes: 1310, turn: 2 },
electorate: {
aptos: 4700,
validos: 2490,
brancos: 142,
nulos: 87,
abstencoes: 680,
},
winnerFederal: { name: 'Dep. Fulano de Tal', votes: 2100, party: 'PP' },
winnerPresident: { name: 'LULA', party: 'PT', votes: 8000 },
winnerGovernor: { name: 'JERÔNIMO', party: 'PT', votes: 6000 },
federalVotesByParty: { PT: 850, PP: 2100 },
ticketFlip: computeTicketFlipOpportunity({
winnerPresident: { name: 'LULA', party: 'PT', votes: 8000 },
winnerGovernor: { name: 'JERÔNIMO', party: 'PT', votes: 6000 },
winnerFederal: { name: 'Dep. Fulano de Tal', votes: 2100, party: 'PP' },
federalVotesByParty: { PT: 850, PP: 2100 },
}),
series: { y2014: 700, y2018: 800, y2022: 850 },
}
describe('NucleusElectoralBaseline', () => {
it('renders the empty geography state', () => {
const html = renderToStaticMarkup(createElement(NucleusElectoralBaseline, { baseline: null }))
expect(html).toContain('Baseline eleitoral 2022')
expect(html).toContain('Sem baseline TSE (informe território/município)')
})
it('renders the candidate, ticket, electorate, and local winner rows', () => {
const html = renderToStaticMarkup(createElement(NucleusElectoralBaseline, { baseline }))
expect(html).toContain('Jorge Solla')
expect(html).toContain('850')
expect(html).toContain('Lula')
expect(html).toContain('1.480')
expect(html).toContain('Jerônimo Rodrigues')
expect(html).toContain('Eleitorado 2022')
expect(html).toContain('2.490')
expect(html).toContain('Mais votado aqui em 2022')
expect(html).toContain('Dep. Fulano de Tal (PP)')
expect(html).toContain('Série histórica')
expect(html).toContain('2014: 700')
})
})
describe('NucleusInsights', () => {
it('renders the amber below alert for Gap vs 2022', () => {
const html = renderToStaticMarkup(
createElement(NucleusInsights, {
baseline,
confirmedVoteEstimate: 500,
}),
)
expect(html).toContain('data-insight="gap-vs-2022"')
expect(html).toContain('Faltam 350 votos para o patamar de 2022')
expect(html).toContain('Estimativa atual (500)')
})
it('renders the green above alert when the estimate clears 2022', () => {
const html = renderToStaticMarkup(
createElement(NucleusInsights, {
baseline,
confirmedVoteEstimate: 952,
}),
)
expect(html).toContain('Já superamos 2022 em 12%')
})
it('renders the vote-trend insight when the series is comparable', () => {
const html = renderToStaticMarkup(
createElement(NucleusInsights, {
baseline,
confirmedVoteEstimate: 500,
}),
)
expect(html).toContain('data-insight="vote-trend"')
expect(html).toContain('Tendência:')
})
it('renders ticket leverage and flip opportunity insights', () => {
const html = renderToStaticMarkup(
createElement(NucleusInsights, {
baseline,
confirmedVoteEstimate: 500,
}),
)
expect(html).toContain('data-insight="ticket-leverage"')
expect(html).toContain('Alavancagem da chapa:')
expect(html).toContain('data-insight="ticket-flip"')
expect(html).toContain('completar a chapa')
expect(html).not.toMatch(/direita/i)
})
})