teqo/tests/unit/campaignQuickActionLeadership.unit.spec.ts
Cursor Agent d5697bcfcb
B110 — wizard return path via allowlisted from query
Propagate return path from quick actions through the B98 wizard chain so
dismiss, skip, and chain end navigate back to the originating page instead
of always redirecting to Início.

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-01 20:39:24 +00:00

53 lines
2.3 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { CAMPAIGN_ACTIONS_HOME } from '@/lib/campaignActionRoutes'
import { resolveLeadershipQuickActions } from '@/lib/campaignQuickActionLeadership'
describe('resolveLeadershipQuickActions', () => {
it('returns only update-leadership on the list without prefill', () => {
const actions = resolveLeadershipQuickActions('/campanha/liderancas', 'coordinator', {})
expect(actions).toHaveLength(1)
expect(actions?.[0]?.id).toBe('update-leadership')
expect(actions?.[0]?.href).toBe(
`${CAMPAIGN_ACTIONS_HOME}/atualizar-lideranca?from=%2Fcampanha%2Fliderancas`,
)
})
it('returns five wizard actions on detail with municipality prefill when N=1', () => {
const actions = resolveLeadershipQuickActions('/campanha/liderancas/42', 'coordinator', {
leadershipId: 42,
municipalitySlug: 'cairu',
})
expect(actions?.map((action) => action.id)).toEqual([
'update-votes',
'register-signal',
'change-trend',
'update-leadership',
'register-demand',
])
expect(actions?.find((action) => action.id === 'update-votes')?.href).toBe(
`${CAMPAIGN_ACTIONS_HOME}/atualizar-votos?municipio=cairu&from=%2Fcampanha%2Fliderancas%2F42`,
)
expect(actions?.find((action) => action.id === 'update-leadership')?.href).toBe(
`${CAMPAIGN_ACTIONS_HOME}/atualizar-lideranca?municipio=cairu&leadershipId=42&from=%2Fcampanha%2Fliderancas%2F42`,
)
})
it('degrades update-leadership to ficha when N>1 (no municipality slug)', () => {
const actions = resolveLeadershipQuickActions('/campanha/liderancas/7', 'advisor', {
leadershipId: 7,
})
expect(actions?.find((action) => action.id === 'update-leadership')?.href).toBe(
'/campanha/liderancas/7',
)
expect(actions?.find((action) => action.id === 'update-votes')?.href).toBe(
`${CAMPAIGN_ACTIONS_HOME}/atualizar-votos?from=%2Fcampanha%2Fliderancas%2F7`,
)
})
it('returns null outside leadership routes', () => {
expect(resolveLeadershipQuickActions('/campanha/municipios', 'coordinator', {})).toBeNull()
expect(resolveLeadershipQuickActions('/campanha/liderancas/nova', 'coordinator', {})).toBeNull()
expect(resolveLeadershipQuickActions('/campanha/liderancas', 'leader', {})).toBeNull()
})
})