Revert "frontend-test-utils: render the element as Page"

This reverts commit 23c72e7e65.

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2025-10-07 17:04:39 +02:00
parent ae1dad0e73
commit 1013eb72cb
2 changed files with 27 additions and 35 deletions
@@ -20,19 +20,15 @@ import {
MockAnalyticsApi,
TestApiProvider,
} from '@backstage/frontend-test-utils';
import {
analyticsApiRef,
PageBlueprint,
useAnalytics,
} from '@backstage/frontend-plugin-api';
import { analyticsApiRef, useAnalytics } from '@backstage/frontend-plugin-api';
import { Routes, Route } from 'react-router-dom';
import { renderInTestApp } from './renderInTestApp';
import { Route, Routes } from 'react-router-dom';
describe('renderInTestApp', () => {
it('should render the given component in a page', async () => {
const IndexPage = () => <div>Index Page</div>;
renderInTestApp(<IndexPage />);
expect(await screen.findByText('Index Page')).toBeInTheDocument();
expect(screen.getByText('Index Page')).toBeInTheDocument();
});
it('should works with apis provider', async () => {
@@ -59,7 +55,7 @@ describe('renderInTestApp', () => {
</TestApiProvider>,
);
fireEvent.click(await screen.findByRole('link', { name: 'See details' }));
fireEvent.click(screen.getByRole('link', { name: 'See details' }));
expect(analyticsApiMock.getEvents()).toEqual(
expect.arrayContaining([
@@ -72,25 +68,16 @@ describe('renderInTestApp', () => {
});
it('should support setting different locations in the history stack', async () => {
renderInTestApp(<h1>Index page</h1>, {
extensions: [
PageBlueprint.make({
name: 'second-page',
params: defineParams =>
defineParams({
path: '/second-page',
loader: async () => (
<Routes>
<Route path="/" element={<h1>Second page</h1>} />
<Route path="/subpage" element={<h1>Subpage</h1>} />
</Routes>
),
}),
}),
],
initialRouteEntries: ['/second-page/subpage'],
});
renderInTestApp(
<Routes>
<Route path="/" element={<h1>Index Page</h1>} />
<Route path="/second-page" element={<h1>Second Page</h1>} />
</Routes>,
{
initialRouteEntries: ['/second-page'],
},
);
expect(await screen.findByText('Subpage')).toBeInTheDocument();
expect(screen.getByText('Second Page')).toBeInTheDocument();
});
});
@@ -31,7 +31,6 @@ import {
NavItemBlueprint,
createFrontendPlugin,
FrontendFeature,
PageBlueprint,
} from '@backstage/frontend-plugin-api';
import appPlugin from '@backstage/plugin-app';
@@ -108,6 +107,12 @@ const appPluginOverride = appPlugin.withOverrides({
appPlugin.getExtension('sign-in-page:app').override({
disabled: true,
}),
appPlugin.getExtension('app/layout').override({
disabled: true,
}),
appPlugin.getExtension('app/routes').override({
disabled: true,
}),
appPlugin.getExtension('app/nav').override({
output: [coreExtensionData.reactElement],
factory(_originalFactory, { inputs }) {
@@ -147,6 +152,13 @@ export function renderInTestApp(
options?: TestAppOptions,
): RenderResult {
const extensions: Array<ExtensionDefinition> = [
createExtension({
attachTo: { id: 'app/root', input: 'children' },
output: [coreExtensionData.reactElement],
factory: () => {
return [coreExtensionData.reactElement(element)];
},
}),
RouterBlueprint.make({
params: {
component: ({ children }) => (
@@ -185,13 +197,6 @@ export function renderInTestApp(
extensions.push(...options.extensions);
}
extensions.push(
PageBlueprint.make({
name: 'mocked-root-page',
params: define => define({ path: '/', loader: async () => element }),
}),
);
const features: FrontendFeature[] = [
createFrontendPlugin({
pluginId: 'test',