From c82477ae81ec55237b59da1e86b144269eb2e918 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 12 Oct 2023 11:53:34 +0200 Subject: [PATCH] frontend-plugin-api: add description for SubRouteRefs Signed-off-by: Patrik Oldsberg --- .../src/routing/SubRouteRef.test.ts | 13 +++++++++---- .../frontend-plugin-api/src/routing/SubRouteRef.ts | 10 ++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts b/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts index 54d54f9cf8..bf38bacbf5 100644 --- a/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts +++ b/packages/frontend-plugin-api/src/routing/SubRouteRef.test.ts @@ -20,23 +20,28 @@ import { createSubRouteRef, toInternalSubRouteRef, } from './SubRouteRef'; -import { createRouteRef } from './RouteRef'; +import { createRouteRef, toInternalRouteRef } from './RouteRef'; const parent = createRouteRef(); const parentX = createRouteRef({ params: ['x'] }); describe('SubRouteRef', () => { it('should be created', () => { + const internalParent = toInternalRouteRef(createRouteRef()); const routeRef: SubRouteRef = createSubRouteRef({ - parent, + parent: internalParent, id: 'my-route-ref', path: '/foo', }); const internal = toInternalSubRouteRef(routeRef); expect(internal.path).toBe('/foo'); - expect(internal.getParent()).toBe(parent); + expect(internal.getParent()).toBe(internalParent); expect(internal.getParams()).toEqual([]); - expect(String(internal)).toBe('SubRouteRef{}'); + expect(String(internal)).toMatch( + /SubRouteRef\{at \/foo with parent created at '.*SubRouteRef\.test\.ts.*'\}/, + ); + internalParent.setId('some-id'); + expect(String(internal)).toBe('SubRouteRef{at /foo with parent some-id}'); }); it('should be created with params', () => { diff --git a/packages/frontend-plugin-api/src/routing/SubRouteRef.ts b/packages/frontend-plugin-api/src/routing/SubRouteRef.ts index ed03c17ada..a4becf5e44 100644 --- a/packages/frontend-plugin-api/src/routing/SubRouteRef.ts +++ b/packages/frontend-plugin-api/src/routing/SubRouteRef.ts @@ -45,6 +45,7 @@ export interface InternalSubRouteRef< getParams(): string[]; getParent(): RouteRef; + getDescription(): string; } /** @internal */ @@ -93,8 +94,13 @@ export class SubRouteRefImpl return this.#parent; } - toString() { - return `SubRouteRef{}`; + getDescription(): string { + const parent = toInternalRouteRef(this.#parent); + return `at ${this.path} with parent ${parent.getDescription()}`; + } + + toString(): string { + return `SubRouteRef{${this.getDescription()}}`; } }