mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-29 17:43:05 +00:00
B81 — register staff Início quick actions on /campanha/territorios
Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
parent
e61e80b6dc
commit
8c9eeaf273
3 changed files with 53 additions and 5 deletions
|
|
@ -124,6 +124,18 @@ export type ResolvedCampaignHomeAction = CampaignHomeAction & {
|
||||||
href?: string
|
href?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Mirrors Início `buildMunicipalityListHref({ coverage: 'sem_assessor', sort: 'votos' }, 1)`. */
|
||||||
|
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+). */
|
||||||
|
export const resolveStaffHomeQuickActions = (
|
||||||
|
role: CampaignRole,
|
||||||
|
): readonly ResolvedCampaignHomeAction[] => {
|
||||||
|
if (!isStaffCampaignRole(role)) return []
|
||||||
|
return toHomeActionButtonProps(homeActionsForRole(role), UNCOVERED_MUNICIPALITIES_LIST_HREF)
|
||||||
|
}
|
||||||
|
|
||||||
export const toHomeActionButtonProps = (
|
export const toHomeActionButtonProps = (
|
||||||
actions: readonly CampaignHomeAction[],
|
actions: readonly CampaignHomeAction[],
|
||||||
uncoveredMunicipalitiesHref?: string,
|
uncoveredMunicipalitiesHref?: string,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,25 @@
|
||||||
import type { ResolvedCampaignHomeAction } from '@/lib/campaignHomeActions'
|
import {
|
||||||
|
resolveStaffHomeQuickActions,
|
||||||
|
type ResolvedCampaignHomeAction,
|
||||||
|
} from '@/lib/campaignHomeActions'
|
||||||
import type { CampaignQuickActionContext } from '@/lib/campaignQuickActionContext'
|
import type { CampaignQuickActionContext } from '@/lib/campaignQuickActionContext'
|
||||||
import type { CampaignRole } from '@/lib/campaignRoles'
|
import type { CampaignRole } from '@/lib/campaignRoles'
|
||||||
|
|
||||||
|
const isTerritoriesListPath = (pathname: string): boolean =>
|
||||||
|
pathname === '/campanha/territorios' || pathname.startsWith('/campanha/territorios/')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pathname + role + page context → contextual quick actions.
|
* Pathname + role + page context → contextual quick actions.
|
||||||
* Catalogs per vertical land in B80–B90; the B79 chassis renders whatever
|
* Catalogs per vertical land in B80–B90; the B79 chassis renders whatever
|
||||||
* this helper returns (empty until those items register providers).
|
* this helper returns (empty until those items register providers).
|
||||||
*/
|
*/
|
||||||
export const resolveQuickActionsForPath = (
|
export const resolveQuickActionsForPath = (
|
||||||
_pathname: string,
|
pathname: string,
|
||||||
_role: CampaignRole,
|
role: CampaignRole,
|
||||||
_context: CampaignQuickActionContext,
|
_context: CampaignQuickActionContext,
|
||||||
): readonly ResolvedCampaignHomeAction[] => []
|
): readonly ResolvedCampaignHomeAction[] => {
|
||||||
|
if (isTerritoriesListPath(pathname)) {
|
||||||
|
return resolveStaffHomeQuickActions(role)
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,10 @@ import {
|
||||||
QUICK_ACTIONS_SNAP_EXPANDED,
|
QUICK_ACTIONS_SNAP_EXPANDED,
|
||||||
quickActionsSnapIsExpanded,
|
quickActionsSnapIsExpanded,
|
||||||
} from '@/lib/campaignQuickActionSnap'
|
} from '@/lib/campaignQuickActionSnap'
|
||||||
|
import {
|
||||||
|
UNCOVERED_MUNICIPALITIES_LIST_HREF,
|
||||||
|
homeActionsForRole,
|
||||||
|
} from '@/lib/campaignHomeActions'
|
||||||
|
|
||||||
describe('campaignQuickActionMount', () => {
|
describe('campaignQuickActionMount', () => {
|
||||||
it('treats Início as exact match only', () => {
|
it('treats Início as exact match only', () => {
|
||||||
|
|
@ -34,6 +38,7 @@ describe('campaignQuickActionMount', () => {
|
||||||
|
|
||||||
it('mounts for staff outside Início and acoes', () => {
|
it('mounts for staff outside Início and acoes', () => {
|
||||||
expect(shouldMountQuickActionsDrawer('/campanha/municipios', 'coordinator')).toBe(true)
|
expect(shouldMountQuickActionsDrawer('/campanha/municipios', 'coordinator')).toBe(true)
|
||||||
|
expect(shouldMountQuickActionsDrawer('/campanha/territorios', 'coordinator')).toBe(true)
|
||||||
expect(shouldMountQuickActionsDrawer('/campanha', 'coordinator')).toBe(false)
|
expect(shouldMountQuickActionsDrawer('/campanha', 'coordinator')).toBe(false)
|
||||||
expect(shouldMountQuickActionsDrawer('/campanha/acoes/registrar-sinal', 'advisor')).toBe(false)
|
expect(shouldMountQuickActionsDrawer('/campanha/acoes/registrar-sinal', 'advisor')).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
@ -45,13 +50,33 @@ describe('campaignQuickActionMount', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('campaignQuickActionRegistry', () => {
|
describe('campaignQuickActionRegistry', () => {
|
||||||
it('returns empty catalog until B80+ register providers', () => {
|
const staffActionIds = homeActionsForRole('coordinator').map((action) => action.id)
|
||||||
|
|
||||||
|
it('returns empty catalog for unregistered paths', () => {
|
||||||
expect(
|
expect(
|
||||||
resolveQuickActionsForPath('/campanha/municipios/foo', 'coordinator', {
|
resolveQuickActionsForPath('/campanha/municipios/foo', 'coordinator', {
|
||||||
municipalitySlug: 'foo',
|
municipalitySlug: 'foo',
|
||||||
}),
|
}),
|
||||||
).toEqual([])
|
).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('returns staff Início catalog on territorios without municipality prefill (B81)', () => {
|
||||||
|
const actions = resolveQuickActionsForPath('/campanha/territorios', 'coordinator', {})
|
||||||
|
expect(actions.map((action) => action.id)).toEqual(staffActionIds)
|
||||||
|
expect(actions.find((action) => action.id === 'update-votes')?.href).toBe(
|
||||||
|
'/campanha/acoes/atualizar-votos',
|
||||||
|
)
|
||||||
|
expect(actions.find((action) => action.id === 'uncovered-municipalities')?.href).toBe(
|
||||||
|
UNCOVERED_MUNICIPALITIES_LIST_HREF,
|
||||||
|
)
|
||||||
|
for (const action of actions) {
|
||||||
|
expect(action.href).not.toContain('municipio=')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns empty catalog on territorios for leader lockdown', () => {
|
||||||
|
expect(resolveQuickActionsForPath('/campanha/territorios', 'leader', {})).toEqual([])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('campaignQuickActionSnap', () => {
|
describe('campaignQuickActionSnap', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue