core-compat-api: add test for legacy API access

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-01-08 12:13:44 +01:00
parent 4c1f50cbd2
commit 4ffb18a507
3 changed files with 40 additions and 0 deletions
+1
View File
@@ -35,6 +35,7 @@
},
"devDependencies": {
"@backstage/cli": "workspace:^",
"@backstage/frontend-app-api": "workspace:^",
"@backstage/frontend-test-utils": "workspace:^",
"@backstage/plugin-catalog": "workspace:^",
"@backstage/plugin-puppetdb": "workspace:^",
@@ -32,6 +32,14 @@ import { Route, Routes } from 'react-router-dom';
import { collectLegacyRoutes } from './collectLegacyRoutes';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import { toInternalBackstagePlugin } from '../../frontend-plugin-api/src/wiring/createPlugin';
import {
createPlugin,
createRoutableExtension,
createRouteRef,
useApp,
} from '@backstage/core-plugin-api';
import { createSpecializedApp } from '@backstage/frontend-app-api';
import { render, screen } from '@testing-library/react';
describe('collectLegacyRoutes', () => {
it('should collect legacy routes', () => {
@@ -241,4 +249,34 @@ describe('collectLegacyRoutes', () => {
},
]);
});
it('should make legacy APIs available', async () => {
const plugin = createPlugin({
id: 'test',
});
const routeRef = createRouteRef({ id: 'test' });
const Page = plugin.provide(
createRoutableExtension({
name: 'Test',
mountPoint: routeRef,
component: () =>
Promise.resolve(() => {
const app = useApp();
return <div>plugins: {app.getPlugins().map(p => p.getId())}</div>;
}),
}),
);
const features = collectLegacyRoutes(
<FlatRoutes>
<Route path="/" element={<Page />} />
</FlatRoutes>,
);
render(createSpecializedApp({ features }).createRoot());
await expect(
screen.findByText('plugins: test'),
).resolves.toBeInTheDocument();
});
});
+1
View File
@@ -3797,6 +3797,7 @@ __metadata:
"@backstage/cli": "workspace:^"
"@backstage/core-app-api": "workspace:^"
"@backstage/core-plugin-api": "workspace:^"
"@backstage/frontend-app-api": "workspace:^"
"@backstage/frontend-plugin-api": "workspace:^"
"@backstage/frontend-test-utils": "workspace:^"
"@backstage/plugin-catalog": "workspace:^"