teqo-backup/tests/unit/municipalityV2StatusView.unit.spec.ts
Cursor Agent 6b8aa8b6cf
fix(campanha): B147 simplify — sinal empty body + cold select
Allow empty motivo on sinal through collection beforeValidate; distinguish
warm-typeless vs cold in the v2 signal select; reuse list signal form action.

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-02 23:33:46 +00:00

77 lines
2.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
buildMunicipalityV2StatusAggregate,
MUNICIPALITY_V2_SIGNAL_COLD_VALUE,
resolveMunicipalityV2SignalSelectState,
} from '@/utilities/municipality/municipalityV2StatusView'
describe('municipalityV2StatusView', () => {
it('uses cold sentinel when there is no recent signal', () => {
const state = resolveMunicipalityV2SignalSelectState(
{ signalType: null, lastSignalAt: null },
new Date('2026-08-02T12:00:00.000Z'),
)
expect(state.value).toBe(MUNICIPALITY_V2_SIGNAL_COLD_VALUE)
expect(state.isCold).toBe(true)
expect(state.label).toContain('Sem sinal')
})
it('does not claim frio when frescor is warm but typeless', () => {
const state = resolveMunicipalityV2SignalSelectState(
{
signalType: null,
lastSignalAt: '2026-08-01T12:00:00.000Z',
},
new Date('2026-08-02T12:00:00.000Z'),
)
expect(state.value).toBe(MUNICIPALITY_V2_SIGNAL_COLD_VALUE)
expect(state.isCold).toBe(false)
expect(state.label).toBe('Sem tipo de sinal')
})
it('keeps the typed signal when still warm', () => {
const state = resolveMunicipalityV2SignalSelectState(
{
signalType: 'invasao',
lastSignalAt: '2026-08-01T12:00:00.000Z',
},
new Date('2026-08-02T12:00:00.000Z'),
)
expect(state.value).toBe('invasao')
expect(state.isCold).toBe(false)
expect(state.label).toBe('Invasão')
})
it('builds the aggregate from the three note axes', () => {
const aggregate = buildMunicipalityV2StatusAggregate(
{
engagementLevel: 'n2',
levelNote: 'Subiu o nível',
trendNote: 'Tendência melhor',
signalType: 'esfriamento',
signalBody: 'Rede parou',
lastSignalAt: '2026-08-01T12:00:00.000Z',
},
new Date('2026-08-02T12:00:00.000Z'),
)
expect(aggregate).toBe('Subiu o nível · Tendência melhor · Rede parou')
})
it('names absences when notes are empty', () => {
const aggregate = buildMunicipalityV2StatusAggregate(
{
engagementLevel: 'n1',
levelNote: null,
trendNote: null,
signalType: null,
signalBody: null,
lastSignalAt: null,
},
new Date('2026-08-02T12:00:00.000Z'),
)
expect(aggregate).toContain('sem motivo')
expect(aggregate).toContain('Tendência sem nota')
expect(aggregate).toContain('Sem sinal')
})
})