B81 — simplify: path constant, role cache, href parity test

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-08-01 04:09:35 +00:00
parent 8c9eeaf273
commit 7f2ac29368
No known key found for this signature in database
4 changed files with 38 additions and 8 deletions

View file

@ -16,8 +16,7 @@ import {
type CampaignWizardActionId,
} from '@/lib/campaignActionRoutes'
import { LEADER_CONTACTS_HOME } from '@/lib/campaignPaths'
import type { CampaignRole } from '@/lib/campaignRoles'
import { isStaffCampaignRole } from '@/lib/campaignRoles'
import { isStaffCampaignRole, type CampaignRole } from '@/lib/campaignRoles'
type CampaignHomeActionId =
| 'update-votes'
@ -129,11 +128,23 @@ export const UNCOVERED_MUNICIPALITIES_LIST_HREF =
'/campanha/municipios?coverage=sem_assessor&sort=votos' as const
/** Staff Início catalog with hrefs — shared by quick-action registries (B81+). */
const staffHomeQuickActionsByRole = new Map<
CampaignRole,
readonly ResolvedCampaignHomeAction[]
>()
export const resolveStaffHomeQuickActions = (
role: CampaignRole,
): readonly ResolvedCampaignHomeAction[] => {
if (!isStaffCampaignRole(role)) return []
return toHomeActionButtonProps(homeActionsForRole(role), UNCOVERED_MUNICIPALITIES_LIST_HREF)
const cached = staffHomeQuickActionsByRole.get(role)
if (cached) return cached
const actions = toHomeActionButtonProps(
homeActionsForRole(role),
UNCOVERED_MUNICIPALITIES_LIST_HREF,
)
staffHomeQuickActionsByRole.set(role, actions)
return actions
}
export const toHomeActionButtonProps = (

View file

@ -1,4 +1,6 @@
/** Client-safe `/campanha` route paths shared by nav, gates, and home actions. */
export const CAMPAIGN_HOME = '/campanha' as const
export const CAMPAIGN_TERRITORIES_HOME = '/campanha/territorios' as const
export const LEADER_CONTACTS_HOME = '/campanha/contatos' as const

View file

@ -3,10 +3,12 @@ import {
type ResolvedCampaignHomeAction,
} from '@/lib/campaignHomeActions'
import type { CampaignQuickActionContext } from '@/lib/campaignQuickActionContext'
import { CAMPAIGN_TERRITORIES_HOME } from '@/lib/campaignPaths'
import type { CampaignRole } from '@/lib/campaignRoles'
const isTerritoriesListPath = (pathname: string): boolean =>
pathname === '/campanha/territorios' || pathname.startsWith('/campanha/territorios/')
pathname === CAMPAIGN_TERRITORIES_HOME ||
pathname.startsWith(`${CAMPAIGN_TERRITORIES_HOME}/`)
/**
* Pathname + role + page context → contextual quick actions.

View file

@ -1,7 +1,12 @@
import { describe, expect, it } from 'vitest'
import { homeActionsForRole, toHomeActionButtonProps } from '@/lib/campaignHomeActions'
import {
homeActionsForRole,
toHomeActionButtonProps,
UNCOVERED_MUNICIPALITIES_LIST_HREF,
} from '@/lib/campaignHomeActions'
import { LEADER_CONTACTS_HOME } from '@/lib/campaignPaths'
import { buildMunicipalityListHref } from '@/utilities/municipality/municipalityListUrl'
const staffActionIds = [
'update-votes',
@ -48,10 +53,12 @@ describe('toHomeActionButtonProps', () => {
})
it('wires uncovered-municipalities when href is provided', () => {
const href = '/campanha/municipios?coverage=sem_assessor&sort=votos'
const props = toHomeActionButtonProps(homeActionsForRole('coordinator'), href)
const props = toHomeActionButtonProps(
homeActionsForRole('coordinator'),
UNCOVERED_MUNICIPALITIES_LIST_HREF,
)
const uncovered = props.find((action) => action.id === 'uncovered-municipalities')
expect(uncovered?.href).toBe(href)
expect(uncovered?.href).toBe(UNCOVERED_MUNICIPALITIES_LIST_HREF)
const updateVotes = props.find((action) => action.id === 'update-votes')
expect(updateVotes?.href).toBe('/campanha/acoes/atualizar-votos')
const registerSignal = props.find((action) => action.id === 'register-signal')
@ -63,3 +70,11 @@ describe('toHomeActionButtonProps', () => {
expect(props.find((action) => action.id === 'uncovered-municipalities')?.href).toBeUndefined()
})
})
describe('UNCOVERED_MUNICIPALITIES_LIST_HREF', () => {
it('matches canonical municipality list builder (client/server parity)', () => {
expect(
buildMunicipalityListHref({ page: 1, coverage: 'sem_assessor', sort: 'votos' }, 1),
).toBe(UNCOVERED_MUNICIPALITIES_LIST_HREF)
})
})