test-utils: Attach mountPoint to Page

Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Johan Haals
2021-02-16 16:08:08 +01:00
parent dc12852c9e
commit 34b710f0c0
@@ -23,8 +23,7 @@ import privateExports, {
BootErrorPageProps,
RouteRef,
ExternalRouteRef,
createPlugin,
createRoutableExtension,
attachComponentData,
} from '@backstage/core-api';
import { RenderResult } from '@testing-library/react';
import { renderWithEffects } from '@backstage/test-utils-core';
@@ -110,16 +109,10 @@ export function wrapInTestApp(
Wrapper = () => Component as React.ReactElement;
}
const routePlugin = createPlugin({ id: 'mock-route-plugin' });
const routeElements = Object.entries(options.mountedRoutes ?? {}).map(
([path, routeRef]) => {
const PageComponent = () => <div>Mounted at {path}</div>;
const Page = routePlugin.provide(
createRoutableExtension({
component: async () => PageComponent,
mountPoint: routeRef,
}),
);
const Page = () => <div>Mounted at {path}</div>;
attachComponentData(Page, 'core.mountPoint', routeRef);
return <Route key={path} path={path} element={<Page />} />;
},
);