diff --git a/src/components/campaign/municipality/WizardTrendChoiceStep.tsx b/src/components/campaign/municipality/WizardTrendChoiceStep.tsx index 1af8dc1a..fed07511 100644 --- a/src/components/campaign/municipality/WizardTrendChoiceStep.tsx +++ b/src/components/campaign/municipality/WizardTrendChoiceStep.tsx @@ -27,7 +27,6 @@ import { resolveWizardTrendSkip, selectablePoliticalTrendStatuses, wizardTrendChoiceStepTitle, - type WizardTrendSkipAction, } from '@/lib/politicalTrendWizardUi' import type { PoliticalTrendStatusValue } from '@/lib/schemas/municipality' import { cn } from '@/lib/utils' @@ -50,7 +49,7 @@ export const WizardTrendChoiceStep = ({ prefillExtraParams, }: WizardTrendChoiceStepProps) => { const [infoEntry, setInfoEntry] = useState(null) - const skip: WizardTrendSkipAction = resolveWizardTrendSkip() + const skip = resolveWizardTrendSkip(entryAction) const options = selectablePoliticalTrendStatuses(currentStatus) return ( @@ -62,7 +61,7 @@ export const WizardTrendChoiceStep = ({ previousHref={wizardActionHref(actionSlug, municipalitySlug, { entryAction })} municipalityLabel={municipalityName} skip={skip} - trailingAction={} + trailingAction={skip ? : undefined} >
    {options.map((status) => { diff --git a/src/components/campaign/municipality/WizardTrendNoteStep.tsx b/src/components/campaign/municipality/WizardTrendNoteStep.tsx index 2f897973..fb7992cd 100644 --- a/src/components/campaign/municipality/WizardTrendNoteStep.tsx +++ b/src/components/campaign/municipality/WizardTrendNoteStep.tsx @@ -49,7 +49,7 @@ export const WizardTrendNoteStep = ({ setMunicipalityPoliticalTrendFormAction, {}, ) - const skip = resolveWizardTrendSkip() + const skip = resolveWizardTrendSkip(entryAction) const stepTitle = `Mudar tendĂȘncia para ${politicalTrendLabels[trendStatus]}` useCampaignFormSuccessToast(state, () => { @@ -65,7 +65,7 @@ export const WizardTrendNoteStep = ({ previousHref={wizardTrendHref(actionSlug, municipalitySlug, undefined, entryAction)} municipalityLabel={municipalityName} skip={skip} - trailingAction={} + trailingAction={skip ? : undefined} >
    ({ - label: WIZARD_TREND_SKIP_LABEL, - href: CAMPAIGN_HOME, -}) +export const shouldShowWizardTrendSkip = ( + entryAction: CampaignWizardActionId | undefined, +): boolean => entryAction != null && entryAction !== 'change-trend' + +export const resolveWizardTrendSkip = ( + entryAction: CampaignWizardActionId | undefined, +): WizardTrendSkipAction | undefined => + shouldShowWizardTrendSkip(entryAction) + ? { label: WIZARD_TREND_SKIP_LABEL, href: CAMPAIGN_HOME } + : undefined export type PoliticalTrendNotePrefillSource = | { kind: 'none' } diff --git a/tests/unit/politicalTrendWizardUi.unit.spec.ts b/tests/unit/politicalTrendWizardUi.unit.spec.ts index 95f0d3a7..7c9d0d12 100644 --- a/tests/unit/politicalTrendWizardUi.unit.spec.ts +++ b/tests/unit/politicalTrendWizardUi.unit.spec.ts @@ -11,6 +11,7 @@ import { resolveWizardTrendNoteDestination, resolveWizardTrendSkip, selectablePoliticalTrendStatuses, + shouldShowWizardTrendSkip, WIZARD_TREND_SKIP_LABEL, WIZARD_TREND_UNREGISTERED_TITLE, wizardTrendChoiceStepTitle, @@ -35,8 +36,17 @@ describe('politicalTrendWizardUi', () => { expect(resolveWizardTrendNoteDestination('favoravel', null)).toBe('note') }) - it('always exposes skip to abandon the trend change', () => { - expect(resolveWizardTrendSkip()).toEqual({ + it('hides skip for standalone change-trend entry', () => { + expect(shouldShowWizardTrendSkip(undefined)).toBe(false) + expect(shouldShowWizardTrendSkip('change-trend')).toBe(false) + expect(resolveWizardTrendSkip(undefined)).toBeUndefined() + expect(resolveWizardTrendSkip('change-trend')).toBeUndefined() + }) + + it('shows skip when embedded from another wizard action', () => { + expect(shouldShowWizardTrendSkip('update-votes')).toBe(true) + expect(shouldShowWizardTrendSkip('register-signal')).toBe(true) + expect(resolveWizardTrendSkip('update-votes')).toEqual({ label: WIZARD_TREND_SKIP_LABEL, href: CAMPAIGN_HOME, })