frontend-test-utils: update extension tester to drop v1 support
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -18,10 +18,10 @@ import React, { useCallback } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react';
|
||||
import {
|
||||
ApiBlueprint,
|
||||
analyticsApiRef,
|
||||
configApiRef,
|
||||
coreExtensionData,
|
||||
createApiExtension,
|
||||
createApiFactory,
|
||||
createExtension,
|
||||
createExtensionDataRef,
|
||||
@@ -64,8 +64,8 @@ describe('createExtensionTester', () => {
|
||||
it("should fail to render an extension that doesn't output a react element", async () => {
|
||||
const extension = createExtension({
|
||||
...defaultDefinition,
|
||||
output: { path: coreExtensionData.routePath },
|
||||
factory: () => ({ path: '/foo' }),
|
||||
output: [coreExtensionData.routePath],
|
||||
factory: () => [coreExtensionData.routePath('/foo')],
|
||||
});
|
||||
const tester = createExtensionTester(extension);
|
||||
expect(() => tester.render()).toThrowErrorMatchingInlineSnapshot(
|
||||
@@ -122,7 +122,7 @@ describe('createExtensionTester', () => {
|
||||
const appTitle = configApi.getOptionalString('app.title');
|
||||
return (
|
||||
<div>
|
||||
<h2>{appTitle ?? 'Backstafe app'}</h2>
|
||||
<h2>{appTitle ?? 'Backstage app'}</h2>
|
||||
<h3>{config.title ?? 'Index page'}</h3>
|
||||
<Link to="/details">See details</Link>
|
||||
</div>
|
||||
@@ -186,12 +186,14 @@ describe('createExtensionTester', () => {
|
||||
// Mocking the analytics api implementation
|
||||
const analyticsApiMock = new MockAnalyticsApi();
|
||||
|
||||
const analyticsApiOverride = createApiExtension({
|
||||
factory: createApiFactory({
|
||||
api: analyticsApiRef,
|
||||
deps: {},
|
||||
factory: () => analyticsApiMock,
|
||||
}),
|
||||
const analyticsApiOverride = ApiBlueprint.make({
|
||||
params: {
|
||||
factory: createApiFactory({
|
||||
api: analyticsApiRef,
|
||||
deps: {},
|
||||
factory: () => analyticsApiMock,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const indexPageExtension = createExtension({
|
||||
|
||||
@@ -26,13 +26,13 @@ import {
|
||||
ExtensionDataRef,
|
||||
ExtensionDefinition,
|
||||
IconComponent,
|
||||
NavItemBlueprint,
|
||||
RouteRef,
|
||||
RouterBlueprint,
|
||||
coreExtensionData,
|
||||
createExtension,
|
||||
createExtensionInput,
|
||||
createExtensionOverrides,
|
||||
createNavItemExtension,
|
||||
createRouterExtension,
|
||||
useRouteRef,
|
||||
} from '@backstage/frontend-plugin-api';
|
||||
import { Config, ConfigReader } from '@backstage/config';
|
||||
@@ -74,30 +74,29 @@ const TestAppNavExtension = createExtension({
|
||||
name: 'nav',
|
||||
attachTo: { id: 'app/layout', input: 'nav' },
|
||||
inputs: {
|
||||
items: createExtensionInput({
|
||||
target: createNavItemExtension.targetDataRef,
|
||||
}),
|
||||
},
|
||||
output: {
|
||||
element: coreExtensionData.reactElement,
|
||||
items: createExtensionInput([NavItemBlueprint.dataRefs.target]),
|
||||
},
|
||||
output: [coreExtensionData.reactElement],
|
||||
factory({ inputs }) {
|
||||
return {
|
||||
element: (
|
||||
return [
|
||||
coreExtensionData.reactElement(
|
||||
<nav>
|
||||
<ul>
|
||||
{inputs.items.map((item, index) => (
|
||||
<NavItem
|
||||
key={index}
|
||||
icon={item.output.target.icon}
|
||||
title={item.output.target.title}
|
||||
routeRef={item.output.target.routeRef}
|
||||
/>
|
||||
))}
|
||||
{inputs.items.map((item, index) => {
|
||||
const target = item.get(NavItemBlueprint.dataRefs.target);
|
||||
return (
|
||||
<NavItem
|
||||
key={index}
|
||||
icon={target.icon}
|
||||
title={target.title}
|
||||
routeRef={target.routeRef}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</nav>
|
||||
</nav>,
|
||||
),
|
||||
};
|
||||
];
|
||||
},
|
||||
});
|
||||
|
||||
@@ -253,18 +252,7 @@ export class ExtensionTester<UOutput extends AnyExtensionDataRef> {
|
||||
let subjectOverride;
|
||||
// attaching to app/routes to render as index route
|
||||
if (subjectInternal.version === 'v1') {
|
||||
subjectOverride = createExtension({
|
||||
...subjectInternal,
|
||||
attachTo: { id: 'app/routes', input: 'routes' },
|
||||
output: {
|
||||
...subjectInternal.output,
|
||||
path: coreExtensionData.routePath,
|
||||
},
|
||||
factory: params => ({
|
||||
...subjectInternal.factory(params as any),
|
||||
path: '/',
|
||||
}),
|
||||
});
|
||||
throw new Error('The extension tester does not support v1 extensions');
|
||||
} else if (subjectInternal.version === 'v2') {
|
||||
subjectOverride = createExtension({
|
||||
...subjectInternal,
|
||||
@@ -282,6 +270,7 @@ export class ExtensionTester<UOutput extends AnyExtensionDataRef> {
|
||||
return [...parentOutput, coreExtensionData.routePath('/')];
|
||||
},
|
||||
});
|
||||
(subjectOverride as any).configSchema = subjectInternal.configSchema;
|
||||
} else {
|
||||
throw new Error('Unsupported extension version');
|
||||
}
|
||||
@@ -293,11 +282,13 @@ export class ExtensionTester<UOutput extends AnyExtensionDataRef> {
|
||||
subjectOverride,
|
||||
...this.#extensions.slice(1).map(extension => extension.definition),
|
||||
TestAppNavExtension,
|
||||
createRouterExtension({
|
||||
RouterBlueprint.make({
|
||||
namespace: 'test',
|
||||
Component: ({ children }) => (
|
||||
<MemoryRouter>{children}</MemoryRouter>
|
||||
),
|
||||
params: {
|
||||
Component: ({ children }) => (
|
||||
<MemoryRouter>{children}</MemoryRouter>
|
||||
),
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user