frontend-plugin-api: add description for SubRouteRefs
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -45,6 +45,7 @@ export interface InternalSubRouteRef<
|
||||
|
||||
getParams(): string[];
|
||||
getParent(): RouteRef;
|
||||
getDescription(): string;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@@ -93,8 +94,13 @@ export class SubRouteRefImpl<TParams extends AnyRouteParams>
|
||||
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()}}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user