From 03e9125c0edfe1c4e9e172ce6b28f72ab4b77a78 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 27 Aug 2024 13:11:00 +0200 Subject: [PATCH] chore: fixing tests for RouterBlueprint Signed-off-by: blam --- .../frontend-app-api/src/wiring/createApp.tsx | 4 +- .../src/blueprints/RouterBlueprint.test.tsx | 79 ++++++++----------- 2 files changed, 35 insertions(+), 48 deletions(-) diff --git a/packages/frontend-app-api/src/wiring/createApp.tsx b/packages/frontend-app-api/src/wiring/createApp.tsx index 9148ffe527..37b7d2758a 100644 --- a/packages/frontend-app-api/src/wiring/createApp.tsx +++ b/packages/frontend-app-api/src/wiring/createApp.tsx @@ -274,9 +274,7 @@ export function createSpecializedApp(options?: { config = new ConfigReader({}, 'empty-config'), } = options ?? {}; - const duplicatedFeatures = [appPlugin, ...featuresWithoutApp]; - - const features = deduplicateFeatures(duplicatedFeatures); + const features = deduplicateFeatures([appPlugin, ...featuresWithoutApp]); const tree = resolveAppTree( 'root', diff --git a/packages/frontend-plugin-api/src/blueprints/RouterBlueprint.test.tsx b/packages/frontend-plugin-api/src/blueprints/RouterBlueprint.test.tsx index 0ce21b5d6d..e8be1cc0ae 100644 --- a/packages/frontend-plugin-api/src/blueprints/RouterBlueprint.test.tsx +++ b/packages/frontend-plugin-api/src/blueprints/RouterBlueprint.test.tsx @@ -16,14 +16,17 @@ import React from 'react'; import { RouterBlueprint } from './RouterBlueprint'; import { MemoryRouter } from 'react-router-dom'; -import { waitFor } from '@testing-library/react'; +import { render, waitFor } from '@testing-library/react'; import { coreExtensionData, createExtension, createExtensionInput, } from '../wiring'; import { PageBlueprint } from './PageBlueprint'; -import { renderInTestApp } from '@backstage/frontend-test-utils'; +import { + createExtensionTester, + renderInTestApp, +} from '@backstage/frontend-test-utils'; describe('RouterBlueprint', () => { it('should return an extension when calling make with sensible defaults', () => { @@ -70,18 +73,14 @@ describe('RouterBlueprint', () => { }, }); - const { getByTestId } = renderInTestApp(
, { - extensions: [ - extension, - PageBlueprint.make({ - namespace: 'test', - params: { - defaultPath: '/', - loader: async () =>
, - }, - }), - ], - }); + const tester = createExtensionTester(extension); + const Component = tester.get(RouterBlueprint.dataRefs.component); + + const { getByTestId } = render( + +
+ , + ); await waitFor(() => { expect(getByTestId('test-contents')).toBeInTheDocument(); @@ -116,38 +115,28 @@ describe('RouterBlueprint', () => { }, }); - const { getByTestId } = renderInTestApp(
, { - extensions: [ - extension, - createExtension({ - namespace: 'test', - attachTo: { - id: 'app-router-component:test/test', - input: 'children', - }, - output: [coreExtensionData.reactElement], - *factory() { - yield coreExtensionData.reactElement(
); - }, - }), - PageBlueprint.make({ - namespace: 'test', - params: { - defaultPath: '/', - loader: async () =>
, - }, - }), - ], - config: { - app: { - extensions: [ - { - 'app-router-component:test/test': { config: { name: 'Robin' } }, - }, - ], + const tester = createExtensionTester(extension, { + config: { name: 'Robin' }, + }).add( + createExtension({ + namespace: 'test', + attachTo: { + id: 'app-router-component:test/test', + input: 'children', }, - }, - }); + output: [coreExtensionData.reactElement], + *factory() { + yield coreExtensionData.reactElement(
); + }, + }), + ); + const Component = tester.get(RouterBlueprint.dataRefs.component); + + const { getByTestId } = render( + +
+ , + ); await waitFor(() => { expect(getByTestId('test-contents')).toBeInTheDocument();