diff --git a/components/breadcrumbs.js b/components/breadcrumbs.js index f7e0d251..250e40f3 100644 --- a/components/breadcrumbs.js +++ b/components/breadcrumbs.js @@ -94,7 +94,10 @@ const Breadcrumbs = (props) => { mySubmittedReps: "Submitted representations" }; - return labelsByKey[viewKey] || null; + const viewAllLabelResolver = labelsByKey[viewKey]; + return typeof viewAllLabelResolver === "function" + ? viewAllLabelResolver() + : viewAllLabelResolver || null; }; const getStaticTextCrumbLabel = (path) => { @@ -116,7 +119,8 @@ const Breadcrumbs = (props) => { "/auth/error": () => t("auth:auth-error-signin-error-title") }; - return staticTextCrumbByPath[path] || null; + const staticTextCrumbResolver = staticTextCrumbByPath[path]; + return staticTextCrumbResolver ? staticTextCrumbResolver() : null; }; const renderMyPortalCrumb = () => ( @@ -175,7 +179,7 @@ const Breadcrumbs = (props) => { const renderBackCrumb = ( onClick, - listItemClass = "govuk-breadcrumbs__link-item backChevron" + listItemClass = "govuk-breadcrumbs__list-item backChevron" ) => renderAnchorCrumb("#", t("common:back-link"), onClick, listItemClass); const renderDnsCaseReferenceCrumbs = (referenceValue) => ( diff --git a/tests/phase22/breadcrumbs-route-map-structure.test.cjs b/tests/phase22/breadcrumbs-route-map-structure.test.cjs index b6632cf1..4dfd31a3 100644 --- a/tests/phase22/breadcrumbs-route-map-structure.test.cjs +++ b/tests/phase22/breadcrumbs-route-map-structure.test.cjs @@ -284,6 +284,34 @@ test("breadcrumbs/component composes mapped routes via imported factories and sh "Expected breadcrumb JSX to use single mapped route render invocation" ); + assert.strictEqual( + source.includes("const viewAllLabelResolver = labelsByKey[viewKey];"), + true, + "Expected view-all label lookup to resolve callable/non-callable map entries" + ); + + assert.strictEqual( + source.includes('return typeof viewAllLabelResolver === "function"'), + true, + "Expected view-all label resolver to invoke function-backed labels" + ); + + assert.strictEqual( + source.includes( + "const staticTextCrumbResolver = staticTextCrumbByPath[path];" + ), + true, + "Expected static text breadcrumb path lookup to resolve a callable label renderer" + ); + + assert.strictEqual( + source.includes( + "return staticTextCrumbResolver ? staticTextCrumbResolver() : null;" + ), + true, + "Expected static text breadcrumb resolver to invoke mapped label function" + ); + assert.strictEqual( source.includes('isPath("/myportal/advancedsearchresults")'), false,