diff --git a/packages/frontend-app-api/src/routing/extractRouteInfoFromInstanceTree.test.ts b/packages/frontend-app-api/src/routing/extractRouteInfoFromInstanceTree.test.ts index 1b7f12391c..fbc3c95fa8 100644 --- a/packages/frontend-app-api/src/routing/extractRouteInfoFromInstanceTree.test.ts +++ b/packages/frontend-app-api/src/routing/extractRouteInfoFromInstanceTree.test.ts @@ -22,6 +22,7 @@ import { } from '@backstage/core-plugin-api'; import { extractRouteInfoFromInstanceTree } from './extractRouteInfoFromInstanceTree'; import { + Extension, coreExtensionData, createExtensionInput, createPageExtension, @@ -59,6 +60,19 @@ function createTestExtension(options: { }); } +function routeInfoFromExtensions(extensions: Extension[]) { + const plugin = createPlugin({ + id: 'test', + extensions, + }); + const { rootInstances } = createInstances({ + config: new MockConfigApi({}), + plugins: [plugin], + }); + + return extractRouteInfoFromInstanceTree(rootInstances); +} + function sortedEntries(map: Map): [RouteRef, T][] { return Array.from(map).sort( ([a], [b]) => refOrder.indexOf(a) - refOrder.indexOf(b), @@ -93,7 +107,7 @@ function routeObj( describe('discovery', () => { it('should collect routes', () => { - const extensions = [ + const info = routeInfoFromExtensions([ createTestExtension({ id: 'nothing', path: 'nothing', @@ -126,18 +140,7 @@ describe('discovery', () => { path: 'blop', routeRef: ref5, }), - ]; - - const plugin = createPlugin({ - id: 'test', - extensions, - }); - const { rootInstances } = createInstances({ - config: new MockConfigApi({}), - plugins: [plugin], - }); - - const info = extractRouteInfoFromInstanceTree(rootInstances); + ]); expect(sortedEntries(info.routePaths)).toEqual([ [ref1, 'foo'], @@ -175,45 +178,53 @@ describe('discovery', () => { ]); }); - // it('should handle all react router Route patterns', () => { - // const root = ( - // - // - // }> - // - // } /> - // - // - // }> - // } /> - // } /> - // - // - // - // ); + it('should handle all react router Route patterns', () => { + const info = routeInfoFromExtensions([ + createTestExtension({ + id: 'page1', + path: 'foo', + routeRef: ref1, + }), + createTestExtension({ + id: 'page2', + at: 'page1/routes', + path: 'bar/:id', + routeRef: ref2, + }), + createTestExtension({ + id: 'page3', + path: 'baz', + routeRef: ref3, + }), + createTestExtension({ + id: 'page4', + at: 'page3/routes', + path: 'divsoup', + routeRef: ref4, + }), + createTestExtension({ + id: 'page5', + at: 'page3/routes', + path: 'blop', + routeRef: ref5, + }), + ]); - // const { routing } = traverseElementTree({ - // root, - // discoverers: [childDiscoverer, routeElementDiscoverer], - // collectors: { - // routing: routingV2Collector, - // }, - // }); - // expect(sortedEntries(routing.paths)).toEqual([ - // [ref1, 'foo'], - // [ref2, 'bar/:id'], - // [ref3, 'baz'], - // [ref4, 'divsoup'], - // [ref5, 'blop'], - // ]); - // expect(sortedEntries(routing.parents)).toEqual([ - // [ref1, undefined], - // [ref2, ref1], - // [ref3, undefined], - // [ref4, ref3], - // [ref5, ref3], - // ]); - // }); + expect(sortedEntries(info.routePaths)).toEqual([ + [ref1, 'foo'], + [ref2, 'bar/:id'], + [ref3, 'baz'], + [ref4, 'divsoup'], + [ref5, 'blop'], + ]); + expect(sortedEntries(info.routeParents)).toEqual([ + [ref1, undefined], + [ref2, ref1], + [ref3, undefined], + [ref4, ref3], + [ref5, ref3], + ]); + }); // it('should handle absolute route paths', () => { // const root = (