refactor(breadcrumbs): map step-back route branches into renderer group

This commit is contained in:
2026-04-09 15:03:19 +01:00
parent 0b905f9374
commit cebd47bf1c
6 changed files with 163 additions and 48 deletions
+45
View File
@@ -709,6 +709,51 @@ Follow-ups:
- Next smaller slice candidate: add a focused helper test for empty-string/whitespace path lookups to assert strict null behavior for non-exact keys.
- Next larger slice candidate: evaluate whether `/newappeal/[appealtypes]` and `/myportal/[appealtypes]` back-link branches can be extracted with explicit callback/setter injection while preserving state-step semantics.
### CL-22541-W: breadcrumbs larger slice — step-back route-group extraction (`/newappeal/[appealtypes]`, `/myportal/[appealtypes]`)
date: 2026-04-09
author: Cline
scope: `lib/routing/{breadcrumbRendererFactories,breadcrumbRouteMaps}.js`, `components/breadcrumbs.js`, `tests/phase22/{breadcrumb-route-maps-helper,breadcrumbs-route-map-structure}.test.cjs`
type: change
rationale: Execute the next larger extraction slice by moving step-based back-link branches into a dedicated mapped route group with explicit setter callback injection, preserving section-navigation semantics.
impact: Structural refactor with preserved back-link and step-state behavior; no intended route/auth/session/API/EN-CY/a11y behavior change.
status: completed
Summary:
- Added `createStepBackRouteRenderers(...)` in `lib/routing/breadcrumbRendererFactories.js` to map:
- `/newappeal/[appealtypes]`
- `/myportal/[appealtypes]`
- Preserved existing step semantics in mapped handlers:
- no crumb when `currentSection <= 1`
- service-name crumb when `currentSection === 9999`
- back-link crumb with existing class parity (`govuk-breadcrumbs__link-item` for new-appeal flow)
- Introduced explicit injected handlers (`onStepBack`, `onStepBackWithInlineClass`) and injected crumb renderer dependency (`renderBackCrumb`) into grouped factory composition.
- Extended map builder in `lib/routing/breadcrumbRouteMaps.js` with `stepBackRouteRenderersByPath` and updated precedence order:
- simple -> link-text -> myportal -> new-appeal -> callback -> step-back -> case detail -> detail/account.
- Updated `components/breadcrumbs.js`:
- pass `currentSection` and step-back callbacks into `createMappedRouteRendererGroups(...)`
- include step-back map in `buildBreadcrumbRendererMaps(...)`
- remove inline `isPath("/newappeal/[appealtypes]")` and `isPath("/myportal/[appealtypes]")` branches.
- Expanded tests:
- `tests/phase22/breadcrumb-route-maps-helper.test.cjs`
- updated grouped map count/order to include step-back map (8 total)
- `tests/phase22/breadcrumbs-route-map-structure.test.cjs`
- assert step-back factory export + mapped route presence
- assert grouped destructuring includes step-back map
- assert inline step-back branches are removed
- assert updated map-order invariant includes step-back group.
Validation:
- `npx eslint lib/routing/breadcrumbRendererFactories.js lib/routing/breadcrumbRouteMaps.js components/breadcrumbs.js tests/phase22/breadcrumb-route-maps-helper.test.cjs tests/phase22/breadcrumbs-route-map-structure.test.cjs tests/phase22/index.test.cjs` -> pass.
- `node tests/phase22/index.test.cjs` -> pass (combined suite).
Follow-ups:
- Next smaller slice candidate: add focused helper test for strict null behavior on empty-string/whitespace/non-exact path keys.
- Next larger slice candidate: evaluate extractability of `/myportal/representation` back-link states via explicit callback injection, only if questionnaire/submit side-effects remain parity-safe and readable.
### CL-00X: 22500 `components/elements/index.js` Phase 1 helper extraction
date: 2026-04-07