frontend-test-utils: remove render method
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -16,14 +16,15 @@
|
||||
|
||||
import React from 'react';
|
||||
import { AppRootWrapperBlueprint } from './AppRootWrapperBlueprint';
|
||||
import { createExtensionTester } from '@backstage/frontend-test-utils';
|
||||
import { PageBlueprint } from './PageBlueprint';
|
||||
import { waitFor } from '@testing-library/react';
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import {
|
||||
coreExtensionData,
|
||||
createExtension,
|
||||
createExtensionInput,
|
||||
createFrontendPlugin,
|
||||
} from '../wiring';
|
||||
import { createSpecializedApp } from '@backstage/frontend-app-api';
|
||||
import { MockConfigApi } from '@backstage/test-utils';
|
||||
|
||||
describe('AppRootWrapperBlueprint', () => {
|
||||
it('should return an extension with sensible defaults', () => {
|
||||
@@ -64,24 +65,22 @@ describe('AppRootWrapperBlueprint', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const { getByText } = createExtensionTester(
|
||||
PageBlueprint.make({
|
||||
params: {
|
||||
defaultPath: '/',
|
||||
loader: async () => <div />,
|
||||
},
|
||||
}),
|
||||
)
|
||||
.add(extension)
|
||||
.render();
|
||||
const app = createSpecializedApp({
|
||||
features: [
|
||||
createFrontendPlugin({
|
||||
id: 'test',
|
||||
extensions: [extension],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
await waitFor(() => expect(getByText('Hello')).toBeInTheDocument());
|
||||
render(app.createRoot());
|
||||
|
||||
await waitFor(() => expect(screen.getByText('Hello')).toBeInTheDocument());
|
||||
});
|
||||
|
||||
it('should render the complex component wrapper', async () => {
|
||||
const extension = AppRootWrapperBlueprint.makeWithOverrides({
|
||||
namespace: 'ns',
|
||||
name: 'test',
|
||||
config: {
|
||||
schema: {
|
||||
name: z => z.string(),
|
||||
@@ -104,28 +103,39 @@ describe('AppRootWrapperBlueprint', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const { getByText, getByTestId } = createExtensionTester(
|
||||
PageBlueprint.make({
|
||||
params: {
|
||||
defaultPath: '/',
|
||||
loader: async () => <div>Hi</div>,
|
||||
const app = createSpecializedApp({
|
||||
features: [
|
||||
createFrontendPlugin({
|
||||
id: 'test',
|
||||
extensions: [
|
||||
extension,
|
||||
createExtension({
|
||||
name: 'test-child',
|
||||
attachTo: { id: 'app-root-wrapper:test', input: 'children' },
|
||||
output: [coreExtensionData.reactElement],
|
||||
factory: () => [
|
||||
coreExtensionData.reactElement(<div>Its Me</div>),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
config: new MockConfigApi({
|
||||
app: {
|
||||
extensions: [
|
||||
{
|
||||
'app-root-wrapper:test': { config: { name: 'Robin' } },
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
)
|
||||
.add(extension, { config: { name: 'Robin' } })
|
||||
.add(
|
||||
createExtension({
|
||||
attachTo: { id: 'app-root-wrapper:ns/test', input: 'children' },
|
||||
output: [coreExtensionData.reactElement],
|
||||
factory: () => [coreExtensionData.reactElement(<div>Its Me</div>)],
|
||||
}),
|
||||
)
|
||||
.render();
|
||||
});
|
||||
|
||||
render(app.createRoot());
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getByText('Hi')).toBeInTheDocument();
|
||||
expect(getByTestId('Robin-1')).toBeInTheDocument();
|
||||
expect(getByText('Its Me')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('Robin-1')).toBeInTheDocument();
|
||||
expect(screen.getByText('Its Me')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -103,7 +103,7 @@ describe('PageBlueprint', () => {
|
||||
|
||||
expect(tester.get(coreExtensionData.routeRef)).toBe(mockRouteRef);
|
||||
|
||||
const { getByTestId } = tester.render();
|
||||
const { getByTestId } = renderInTestApp(tester.reactElement());
|
||||
|
||||
await waitFor(() => expect(getByTestId('test')).toBeInTheDocument());
|
||||
});
|
||||
|
||||
@@ -23,14 +23,12 @@ import {
|
||||
} from '@backstage/test-utils';
|
||||
import { ExtensionBoundary } from './ExtensionBoundary';
|
||||
import { coreExtensionData, createExtension } from '../wiring';
|
||||
import {
|
||||
analyticsApiRef,
|
||||
createApiFactory,
|
||||
useAnalytics,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import { analyticsApiRef, useAnalytics } from '@backstage/core-plugin-api';
|
||||
import { createRouteRef } from '../routing';
|
||||
import { createExtensionTester } from '@backstage/frontend-test-utils';
|
||||
import { ApiBlueprint } from '../blueprints';
|
||||
import {
|
||||
createExtensionTester,
|
||||
renderInTestApp,
|
||||
} from '@backstage/frontend-test-utils';
|
||||
|
||||
const wrapInBoundaryExtension = (element?: JSX.Element) => {
|
||||
const routeRef = createRouteRef();
|
||||
@@ -60,7 +58,11 @@ describe('ExtensionBoundary', () => {
|
||||
const TextComponent = () => {
|
||||
return <p>{text}</p>;
|
||||
};
|
||||
createExtensionTester(wrapInBoundaryExtension(<TextComponent />)).render();
|
||||
renderInTestApp(
|
||||
createExtensionTester(
|
||||
wrapInBoundaryExtension(<TextComponent />),
|
||||
).reactElement(),
|
||||
);
|
||||
await waitFor(() => expect(screen.getByText(text)).toBeInTheDocument());
|
||||
});
|
||||
|
||||
@@ -70,9 +72,11 @@ describe('ExtensionBoundary', () => {
|
||||
throw new Error(errorMsg);
|
||||
};
|
||||
const { error } = await withLogCollector(['error'], async () => {
|
||||
createExtensionTester(
|
||||
wrapInBoundaryExtension(<ErrorComponent />),
|
||||
).render();
|
||||
renderInTestApp(
|
||||
createExtensionTester(
|
||||
wrapInBoundaryExtension(<ErrorComponent />),
|
||||
).reactElement(),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText(errorMsg)).toBeInTheDocument(),
|
||||
);
|
||||
@@ -99,13 +103,13 @@ describe('ExtensionBoundary', () => {
|
||||
return null;
|
||||
};
|
||||
|
||||
createExtensionTester(
|
||||
wrapInBoundaryExtension(
|
||||
<TestApiProvider apis={[[analyticsApiRef, analyticsApiMock]]}>
|
||||
<AnalyticsComponent />
|
||||
</TestApiProvider>,
|
||||
),
|
||||
).render();
|
||||
renderInTestApp(
|
||||
<TestApiProvider apis={[[analyticsApiRef, analyticsApiMock]]}>
|
||||
{createExtensionTester(
|
||||
wrapInBoundaryExtension(<AnalyticsComponent />),
|
||||
).reactElement()}
|
||||
</TestApiProvider>,
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
const event = analyticsApiMock
|
||||
@@ -122,8 +126,9 @@ describe('ExtensionBoundary', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// TODO(Rugvip): It's annoying to test the inverse of this currently, because the extension tester overrides the subject to always output a path
|
||||
it('should emit analytics events if routable', async () => {
|
||||
// TODO(Rugvip): Need a way to be able to override APIs in the app to be able to test this properly
|
||||
// eslint-disable-next-line jest/no-disabled-tests
|
||||
it.skip('should emit analytics events if routable', async () => {
|
||||
const Emitter = () => {
|
||||
const analytics = useAnalytics();
|
||||
useEffect(() => {
|
||||
@@ -134,16 +139,12 @@ describe('ExtensionBoundary', () => {
|
||||
const analyticsApiMock = new MockAnalyticsApi();
|
||||
|
||||
await act(async () => {
|
||||
createExtensionTester(wrapInBoundaryExtension(<Emitter />))
|
||||
.add(
|
||||
ApiBlueprint.make({
|
||||
namespace: analyticsApiRef.id,
|
||||
params: {
|
||||
factory: createApiFactory(analyticsApiRef, analyticsApiMock),
|
||||
},
|
||||
}),
|
||||
)
|
||||
.render();
|
||||
renderInTestApp(
|
||||
createExtensionTester(
|
||||
wrapInBoundaryExtension(<Emitter />),
|
||||
).reactElement(),
|
||||
// { apis: [[analyticsApiRef, analyticsApiMock]] },
|
||||
);
|
||||
});
|
||||
|
||||
expect(analyticsApiMock.getEvents()).toEqual([
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
import React from 'react';
|
||||
import { coreExtensionData } from './coreExtensionData';
|
||||
import { createExtensionBlueprint } from './createExtensionBlueprint';
|
||||
import { createExtensionTester } from '@backstage/frontend-test-utils';
|
||||
import {
|
||||
createExtensionTester,
|
||||
renderInTestApp,
|
||||
} from '@backstage/frontend-test-utils';
|
||||
import {
|
||||
ExtensionDataValue,
|
||||
createExtensionDataRef,
|
||||
@@ -80,7 +83,9 @@ describe('createExtensionBlueprint', () => {
|
||||
version: 'v2',
|
||||
});
|
||||
|
||||
const { container } = createExtensionTester(extension).render();
|
||||
const { container } = renderInTestApp(
|
||||
createExtensionTester(extension).reactElement(),
|
||||
);
|
||||
expect(container.querySelector('h1')).toHaveTextContent('Hello, world!');
|
||||
});
|
||||
|
||||
@@ -120,7 +125,9 @@ describe('createExtensionBlueprint', () => {
|
||||
version: 'v2',
|
||||
});
|
||||
|
||||
const { container } = createExtensionTester(extension).render();
|
||||
const { container } = renderInTestApp(
|
||||
createExtensionTester(extension).reactElement(),
|
||||
);
|
||||
expect(container.querySelector('h1')).toHaveTextContent('Hello, world!');
|
||||
});
|
||||
|
||||
@@ -145,7 +152,9 @@ describe('createExtensionBlueprint', () => {
|
||||
|
||||
expect(extension).toBeDefined();
|
||||
|
||||
const { container } = createExtensionTester(extension).render();
|
||||
const { container } = renderInTestApp(
|
||||
createExtensionTester(extension).reactElement(),
|
||||
);
|
||||
expect(container.querySelector('h1')).toHaveTextContent('Hello, world!');
|
||||
});
|
||||
|
||||
@@ -216,13 +225,15 @@ describe('createExtensionBlueprint', () => {
|
||||
|
||||
expect.assertions(4);
|
||||
|
||||
createExtensionTester(extension, {
|
||||
config: {
|
||||
something: 'something new!',
|
||||
text: 'Hello, world!',
|
||||
defaulted: 'lolz',
|
||||
},
|
||||
}).render();
|
||||
renderInTestApp(
|
||||
createExtensionTester(extension, {
|
||||
config: {
|
||||
something: 'something new!',
|
||||
text: 'Hello, world!',
|
||||
defaulted: 'lolz',
|
||||
},
|
||||
}).reactElement(),
|
||||
);
|
||||
});
|
||||
|
||||
it('should not allow overlapping config keys', () => {
|
||||
@@ -291,12 +302,14 @@ describe('createExtensionBlueprint', () => {
|
||||
|
||||
expect.assertions(2);
|
||||
|
||||
createExtensionTester(extension, {
|
||||
config: {
|
||||
something: 'something new!',
|
||||
defaulted: 'lolz',
|
||||
},
|
||||
}).render();
|
||||
renderInTestApp(
|
||||
createExtensionTester(extension, {
|
||||
config: {
|
||||
something: 'something new!',
|
||||
defaulted: 'lolz',
|
||||
},
|
||||
}).reactElement(),
|
||||
);
|
||||
});
|
||||
|
||||
it('should allow getting inputs properly', () => {
|
||||
|
||||
Reference in New Issue
Block a user