From 961512dc5b028fdffe8d61dcf8b70e2a242c857e Mon Sep 17 00:00:00 2001 From: griest024 Date: Wed, 7 Aug 2024 11:21:45 -0400 Subject: [PATCH] fix(external-router): extract daff paths ignoring full path (#2955) --- .../src/util/extract-daff-path-data.spec.ts | 45 +++++++++++++++++++ .../src/util/extract-daff-path-data.ts | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 libs/external-router/src/util/extract-daff-path-data.spec.ts diff --git a/libs/external-router/src/util/extract-daff-path-data.spec.ts b/libs/external-router/src/util/extract-daff-path-data.spec.ts new file mode 100644 index 0000000000..c076c8f81c --- /dev/null +++ b/libs/external-router/src/util/extract-daff-path-data.spec.ts @@ -0,0 +1,45 @@ +import { ActivatedRouteSnapshot } from '@angular/router'; + +import { daffExtractDaffPathData } from './extract-daff-path-data'; + +describe('@daffodil/external-router | daffExtractDaffPathData', () => { + let snapshot: ActivatedRouteSnapshot; + + beforeEach(() => { + snapshot = { + data: { + daffPaths: { + '00/01/02/10/11/12': { + test: 'test', + }, + }, + }, + pathFromRoot: [ + { + url: [], + }, + { + url: [ + { path: '00' }, + { path: '01' }, + { path: '02' }, + ], + }, + { + url: [ + { path: '10' }, + { path: '11' }, + { path: '12' }, + ], + }, + { + url: [], + }, + ], + }; + }); + + it('should return the correct data', () => { + expect(daffExtractDaffPathData(snapshot, 'test')).toEqual('test'); + }); +}); diff --git a/libs/external-router/src/util/extract-daff-path-data.ts b/libs/external-router/src/util/extract-daff-path-data.ts index 284b7ca040..20d849ea15 100644 --- a/libs/external-router/src/util/extract-daff-path-data.ts +++ b/libs/external-router/src/util/extract-daff-path-data.ts @@ -8,6 +8,6 @@ import { * RouteSnapshot. */ export const daffExtractDaffPathData = (snapshot: ActivatedRouteSnapshot, key: K): T[K] => { - const pathFromRoot = snapshot.pathFromRoot[snapshot.pathFromRoot.length - 1].url.map((seg) => seg.path).join('/'); + const pathFromRoot = snapshot.pathFromRoot.flatMap((route) => route.url).map((seg) => seg.path).join('/'); return snapshot.data?.daffPaths?.[pathFromRoot]?.[key] ?? null; };