teqo-backup/tests/unit/politicalTrendWizardUi.unit.spec.ts
Francisco Solla 212a1f2423 feat(campaign): C87 — atualização unificada (texto + polaridade + urgente)
Substitui o modelo de MunicipalityUpdate (kind/semanal/urgente/nota/sinal + signalType)
por um modelo unificado: body obrigatório + polarity (boa/neutra/ruim) + urgent + adversarySignal.

- Schema: polarity enum obrigatório, urgent boolean default false, adversarySignal boolean
- Wizard: novo WizardUpdateBodyStep com campo de texto + polaridade + urgente
- Lista: controle unificado de atualização com polaridade inline
- Feed: exibe polaridade como badge colorido + indicador de urgência
- V2 status strip: atualização rápida de polaridade
- E11: queries atualizadas para polarity + adversarySignal
- Migração: 20260807_030000_unify_municipality_update (backfill polarity=neutra, urgent de kind, adversarySignal de kind+signalType)
- Testes: 18/18 integração C87, 593/593 total, 1399/1399 unitários
- Fix: testes de state deputy usavam nomes fixos que colidiam entre execuções
2026-08-07 05:04:41 -03:00

105 lines
4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { CAMPAIGN_ACTIONS_HOME } from '@/lib/campaignActionRoutes'
import { WIZARD_CHAIN_SKIP_LABEL } from '@/lib/campaignWizardCopy'
import {
politicalTrendWizardMeta,
politicalTrendWizardMetaByStatus,
} from '@/lib/politicalTrendWizardMeta'
import {
buildPoliticalTrendNotePrefill,
resolvePoliticalTrendNotePrefillSource,
resolveWizardTrendNoteDestination,
resolveWizardTrendSkip,
selectablePoliticalTrendStatuses,
shouldShowWizardTrendSkip,
WIZARD_TREND_UNREGISTERED_TITLE,
wizardTrendChoiceStepTitle,
} from '@/lib/politicalTrendWizardUi'
import { politicalTrendStatuses } from '@/lib/schemas/municipality'
describe('politicalTrendWizardUi', () => {
it('titles the choice step from the current status', () => {
expect(wizardTrendChoiceStepTitle(null)).toBe(WIZARD_TREND_UNREGISTERED_TITLE)
expect(wizardTrendChoiceStepTitle('favoravel')).toBe('Tendência Favorável')
})
it('filters out the current trend from selectable options', () => {
expect(selectablePoliticalTrendStatuses(null)).toEqual(politicalTrendStatuses)
expect(selectablePoliticalTrendStatuses('neutra')).toEqual(['favoravel', 'desfavoravel'])
expect(selectablePoliticalTrendStatuses('desfavoravel')).toEqual(['favoravel', 'neutra'])
})
it('resolves the note-step destination without looping to choice after save', () => {
expect(resolveWizardTrendNoteDestination('favoravel', 'neutra')).toBe('note')
expect(resolveWizardTrendNoteDestination('favoravel', 'favoravel')).toBe('home')
expect(resolveWizardTrendNoteDestination('favoravel', null)).toBe('note')
})
it('hides skip for standalone change-trend entry', () => {
expect(shouldShowWizardTrendSkip(undefined)).toBe(false)
expect(shouldShowWizardTrendSkip('change-trend')).toBe(false)
expect(resolveWizardTrendSkip(undefined, 'cairu')).toBeUndefined()
expect(resolveWizardTrendSkip('change-trend', 'cairu')).toBeUndefined()
})
it('shows skip to the next chain step when embedded from another wizard', () => {
expect(shouldShowWizardTrendSkip('update-votes')).toBe(true)
expect(shouldShowWizardTrendSkip('register-update')).toBe(true)
expect(resolveWizardTrendSkip('update-votes', 'cairu')).toEqual({
label: WIZARD_CHAIN_SKIP_LABEL,
href: `${CAMPAIGN_ACTIONS_HOME}/registrar-atualizacao?municipio=cairu&entry=update-votes`,
})
})
it('builds note prefills from embedded wizard sources', () => {
expect(buildPoliticalTrendNotePrefill({ kind: 'none' })).toBe('')
expect(
buildPoliticalTrendNotePrefill({
kind: 'voteAdjustment',
previousValue: 120,
newValue: 180,
}),
).toBe('Ajuste de votos: 120 → 180')
expect(buildPoliticalTrendNotePrefill({ kind: 'custom', text: 'Contexto do fluxo' })).toBe(
'Contexto do fluxo',
)
})
it('resolves prefill sources from entry action and query params', () => {
expect(
resolvePoliticalTrendNotePrefillSource({
entryAction: 'update-votes',
voteFrom: '100',
voteTo: '150',
}),
).toEqual({ kind: 'voteAdjustment', previousValue: 100, newValue: 150 })
expect(
resolvePoliticalTrendNotePrefillSource({
entryAction: 'register-update',
}),
).toEqual({ kind: 'none' })
expect(
resolvePoliticalTrendNotePrefillSource({
notePrefill: 'Texto direto',
}),
).toEqual({ kind: 'custom', text: 'Texto direto' })
})
})
describe('politicalTrendWizardMeta', () => {
it('covers every trend with icon, copy and info content', () => {
expect(politicalTrendWizardMeta).toHaveLength(politicalTrendStatuses.length)
for (const status of politicalTrendStatuses) {
const entry = politicalTrendWizardMetaByStatus[status]
expect(entry.label.length).toBeGreaterThan(0)
expect(entry.changeDescription).toContain(entry.label)
expect(entry.infoContent.length).toBeGreaterThan(20)
expect(entry.icon).toBeTruthy()
expect(entry.tileClassName.length).toBeGreaterThan(0)
}
})
})