From 8f742612d3e1ebd97453ce3e3085bc1300b740a2 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Wed, 7 Dec 2022 14:55:44 +0000 Subject: [PATCH] revert more test changes Signed-off-by: Brian Fletcher --- .../AboutCard/AboutContent.test.tsx | 194 ++++++------------ .../CatalogTable/CatalogTable.test.tsx | 14 +- .../PlaylistEntitiesTable.test.tsx | 11 +- .../PlaylistPage/PlaylistHeader.test.tsx | 10 +- .../columns/TemplateTitleColumn.test.tsx | 17 +- .../TemplateCard/TemplateCard.test.tsx | 37 ---- .../home/components/Tables/DocsTable.test.tsx | 142 ++++++------- .../TechDocsReaderPageHeader.test.tsx | 17 +- yarn.lock | 16 -- 9 files changed, 129 insertions(+), 329 deletions(-) diff --git a/plugins/catalog/src/components/AboutCard/AboutContent.test.tsx b/plugins/catalog/src/components/AboutCard/AboutContent.test.tsx index cc0b450f46..2a89f2fd92 100644 --- a/plugins/catalog/src/components/AboutCard/AboutContent.test.tsx +++ b/plugins/catalog/src/components/AboutCard/AboutContent.test.tsx @@ -19,19 +19,11 @@ import { RELATION_OWNED_BY, RELATION_PART_OF, } from '@backstage/catalog-model'; -import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react'; -import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils'; +import { entityRouteRef } from '@backstage/plugin-catalog-react'; +import { renderInTestApp } from '@backstage/test-utils'; import { screen } from '@testing-library/react'; import React from 'react'; import { AboutContent } from './AboutContent'; -import { CatalogApi } from '@backstage/catalog-client'; -import { ApiProvider } from '@backstage/core-app-api'; - -const catalogApi: jest.Mocked = { - getEntityByRef: jest.fn(), -} as any; - -const apis = TestApiRegistry.from([catalogApiRef, catalogApi]); describe('', () => { describe('An unknown entity', () => { @@ -71,16 +63,11 @@ describe('', () => { }); it('renders info', async () => { - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -106,16 +93,11 @@ describe('', () => { entity.spec = {}; entity.relations = []; - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -166,16 +148,11 @@ describe('', () => { }); it('renders info', async () => { - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -208,16 +185,11 @@ describe('', () => { delete entity.spec!.system; entity.relations = []; - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -281,16 +253,11 @@ describe('', () => { }); it('renders info', async () => { - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -326,16 +293,11 @@ describe('', () => { delete entity.spec!.system; entity.relations = []; - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -387,16 +349,11 @@ describe('', () => { }); it('renders info', async () => { - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -419,16 +376,11 @@ describe('', () => { delete entity.metadata.tags; entity.relations = []; - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -469,16 +421,11 @@ describe('', () => { }); it('renders info', async () => { - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -506,16 +453,11 @@ describe('', () => { delete entity.metadata.tags; delete entity.spec!.type; - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -567,16 +509,11 @@ describe('', () => { }); it('renders info', async () => { - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -605,16 +542,11 @@ describe('', () => { delete entity.spec!.system; entity.relations = []; - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -668,16 +600,11 @@ describe('', () => { }); it('renders info', async () => { - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( @@ -704,16 +631,11 @@ describe('', () => { delete entity.spec!.domain; entity.relations = []; - await renderInTestApp( - - - , - { - mountedRoutes: { - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + await renderInTestApp(, { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ); + }); expect(screen.getByText('Description')).toBeInTheDocument(); expect(screen.getByText('Description').nextSibling).toHaveTextContent( diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx index a9f6e4846f..652c9f3873 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx @@ -21,7 +21,6 @@ import { } from '@backstage/catalog-model'; import { ApiProvider } from '@backstage/core-app-api'; import { - catalogApiRef, EntityKindFilter, entityRouteRef, MockEntityListContextProvider, @@ -53,15 +52,10 @@ const entities: Entity[] = [ ]; describe('CatalogTable component', () => { - const mockApis = TestApiRegistry.from( - [starredEntitiesApiRef, new MockStarredEntitiesApi()], - [ - catalogApiRef, - { - getEntityByRef: jest.fn(), - } as any, - ], - ); + const mockApis = TestApiRegistry.from([ + starredEntitiesApiRef, + new MockStarredEntitiesApi(), + ]); beforeEach(() => { window.open = jest.fn(); diff --git a/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx b/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx index 19995db710..21658ef36e 100644 --- a/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx +++ b/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx @@ -15,11 +15,7 @@ */ import { ErrorApi, errorApiRef } from '@backstage/core-plugin-api'; -import { - CatalogApi, - catalogApiRef, - entityRouteRef, -} from '@backstage/plugin-catalog-react'; +import { entityRouteRef } from '@backstage/plugin-catalog-react'; import { AuthorizeResult } from '@backstage/plugin-permission-common'; import { PermissionApi, @@ -46,10 +42,6 @@ jest.mock('./AddEntitiesDrawer', () => ({ describe('PlaylistEntitiesTable', () => { const errorApi: Partial = { post: jest.fn() }; - const catalogApi: jest.Mocked = { - getEntityByRef: jest.fn(), - } as any; - const sampleEntities = [ { kind: 'system', @@ -94,7 +86,6 @@ describe('PlaylistEntitiesTable', () => { [errorApiRef, errorApi], [permissionApiRef, permissionApi], [playlistApiRef, playlistApi], - [catalogApiRef, catalogApi], ]} > diff --git a/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx b/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx index e36ec5cfa2..4594a43a88 100644 --- a/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx +++ b/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx @@ -15,11 +15,7 @@ */ import { ErrorApi, errorApiRef } from '@backstage/core-plugin-api'; -import { - CatalogApi, - catalogApiRef, - entityRouteRef, -} from '@backstage/plugin-catalog-react'; +import { entityRouteRef } from '@backstage/plugin-catalog-react'; import { AuthorizeResult, isPermission, @@ -84,9 +80,6 @@ describe('PlaylistHeader', () => { .fn() .mockImplementation(async () => ({ result: AuthorizeResult.ALLOW })); const permissionApi: Partial = { authorize: mockAuthorize }; - const catalogApi: jest.Mocked = { - getEntityByRef: jest.fn(), - } as any; const mockOnUpdate = jest.fn(); @@ -98,7 +91,6 @@ describe('PlaylistHeader', () => { [errorApiRef, errorApi], [permissionApiRef, permissionApi], [playlistApiRef, playlistApi], - [catalogApiRef, catalogApi], ]} > diff --git a/plugins/scaffolder/src/components/ListTasksPage/columns/TemplateTitleColumn.test.tsx b/plugins/scaffolder/src/components/ListTasksPage/columns/TemplateTitleColumn.test.tsx index a5e42b477f..3dc20312aa 100644 --- a/plugins/scaffolder/src/components/ListTasksPage/columns/TemplateTitleColumn.test.tsx +++ b/plugins/scaffolder/src/components/ListTasksPage/columns/TemplateTitleColumn.test.tsx @@ -20,11 +20,7 @@ import React from 'react'; import { TemplateTitleColumn } from './TemplateTitleColumn'; import { scaffolderApiRef } from '../../../api'; import { ScaffolderApi } from '../../../types'; -import { - CatalogApi, - catalogApiRef, - entityRouteRef, -} from '@backstage/plugin-catalog-react'; +import { entityRouteRef } from '@backstage/plugin-catalog-react'; describe('', () => { const scaffolderApiMock: jest.Mocked = { @@ -32,10 +28,6 @@ describe('', () => { getTemplateParameterSchema: jest.fn(), } as any; - const catalogApi: jest.Mocked = { - getEntityByRef: jest.fn(), - } as any; - it('should render the column with the template name', async () => { const props = { entityRef: 'template:default/one-template', @@ -46,12 +38,7 @@ describe('', () => { }); const { getByText } = await renderInTestApp( - + , { mountedRoutes: { '/test': entityRouteRef } }, diff --git a/plugins/scaffolder/src/next/TemplateListPage/TemplateCard/TemplateCard.test.tsx b/plugins/scaffolder/src/next/TemplateListPage/TemplateCard/TemplateCard.test.tsx index aa19970180..4648d47af1 100644 --- a/plugins/scaffolder/src/next/TemplateListPage/TemplateCard/TemplateCard.test.tsx +++ b/plugins/scaffolder/src/next/TemplateListPage/TemplateCard/TemplateCard.test.tsx @@ -15,7 +15,6 @@ */ import { DefaultStarredEntitiesApi } from '@backstage/plugin-catalog'; import { - catalogApiRef, entityRouteRef, starredEntitiesApiRef, } from '@backstage/plugin-catalog-react'; @@ -51,12 +50,6 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], - [ - catalogApiRef, - { - getEntityByRef: jest.fn(), - } as any, - ], ]} > @@ -87,12 +80,6 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], - [ - catalogApiRef, - { - getEntityByRef: jest.fn(), - } as any, - ], ]} > @@ -124,12 +111,6 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], - [ - catalogApiRef, - { - getEntityByRef: jest.fn(), - } as any, - ], ]} > @@ -160,12 +141,6 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], - [ - catalogApiRef, - { - getEntityByRef: jest.fn(), - } as any, - ], ]} > @@ -204,12 +179,6 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], - [ - catalogApiRef, - { - getEntityByRef: jest.fn(), - } as any, - ], ]} > @@ -249,12 +218,6 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], - [ - catalogApiRef, - { - getEntityByRef: jest.fn(), - } as any, - ], ]} > diff --git a/plugins/techdocs/src/home/components/Tables/DocsTable.test.tsx b/plugins/techdocs/src/home/components/Tables/DocsTable.test.tsx index f9a4c03182..098f613773 100644 --- a/plugins/techdocs/src/home/components/Tables/DocsTable.test.tsx +++ b/plugins/techdocs/src/home/components/Tables/DocsTable.test.tsx @@ -15,16 +15,11 @@ */ import React from 'react'; import { render } from '@testing-library/react'; -import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils'; +import { wrapInTestApp } from '@backstage/test-utils'; import { configApiRef } from '@backstage/core-plugin-api'; import { DocsTable } from './DocsTable'; import { rootDocsRouteRef } from '../../../routes'; -import { - CatalogApi, - catalogApiRef, - entityRouteRef, -} from '@backstage/plugin-catalog-react'; -import { ApiProvider } from '@backstage/core-app-api'; +import { entityRouteRef } from '@backstage/plugin-catalog-react'; // Hacky way to mock a specific boolean config value. const getOptionalBooleanMock = jest.fn().mockReturnValue(false); @@ -45,12 +40,6 @@ jest.mock('@backstage/core-plugin-api', () => ({ }, })); -const catalogApi: jest.Mocked = { - getEntityByRef: jest.fn(), -} as any; - -const apis = TestApiRegistry.from([catalogApiRef, catalogApi]); - describe('DocsTable test', () => { beforeEach(() => { jest.resetAllMocks(); @@ -59,44 +48,42 @@ describe('DocsTable test', () => { it('should render documents passed', async () => { const { findByText } = render( wrapInTestApp( - - - , + relations: [ + { + targetRef: 'user:default/owned', + type: 'ownedBy', + }, + ], + }, + { + apiVersion: 'version', + kind: 'TestKind2', + metadata: { + name: 'testName2', + }, + spec: { + owner: 'not-owned@example.com', + }, + relations: [ + { + targetRef: 'user:default/not-owned', + type: 'ownedBy', + }, + ], + }, + ]} + />, { mountedRoutes: { '/docs/:namespace/:kind/:name/*': rootDocsRouteRef, @@ -123,29 +110,27 @@ describe('DocsTable test', () => { const { findByText } = render( wrapInTestApp( - - - , + spec: { + owner: 'user:owned', + }, + relations: [ + { + targetRef: 'user:default/owned', + type: 'ownedBy', + }, + ], + }, + ]} + />, { mountedRoutes: { '/techdocs/:namespace/:kind/:name/*': rootDocsRouteRef, @@ -166,17 +151,12 @@ describe('DocsTable test', () => { it('should render empty state if no owned documents exist', async () => { const { findByText } = render( - wrapInTestApp( - - - , - { - mountedRoutes: { - '/docs/:namespace/:kind/:name/*': rootDocsRouteRef, - '/catalog/:namespace/:kind/:name': entityRouteRef, - }, + wrapInTestApp(, { + mountedRoutes: { + '/docs/:namespace/:kind/:name/*': rootDocsRouteRef, + '/catalog/:namespace/:kind/:name': entityRouteRef, }, - ), + }), ); expect(await findByText('No documents to show')).toBeInTheDocument(); diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx index 96cd55b172..da193430d5 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx @@ -20,11 +20,7 @@ import { ThemeProvider } from '@material-ui/core'; import { lightTheme } from '@backstage/theme'; import { CompoundEntityRef } from '@backstage/catalog-model'; -import { - CatalogApi, - catalogApiRef, - entityRouteRef, -} from '@backstage/plugin-catalog-react'; +import { entityRouteRef } from '@backstage/plugin-catalog-react'; import { techdocsApiRef, TechDocsReaderPageProvider, @@ -64,10 +60,6 @@ const techdocsApiMock = { getTechDocsMetadata, }; -const catalogApi: jest.Mocked = { - getEntityByRef: jest.fn(), -} as any; - const Wrapper = ({ entityRef = { kind: mockEntityMetadata.kind, @@ -80,12 +72,7 @@ const Wrapper = ({ children: React.ReactNode; }) => ( - + {children} diff --git a/yarn.lock b/yarn.lock index 6835e8c03d..2a8f309c17 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12431,22 +12431,6 @@ __metadata: languageName: node linkType: hard -"@react-hookz/web@npm:^20.0.0": - version: 20.0.0 - resolution: "@react-hookz/web@npm:20.0.0" - dependencies: - "@react-hookz/deep-equal": ^1.0.3 - peerDependencies: - js-cookie: ^3.0.1 - react: ^16.8 || ^17 || ^18 - react-dom: ^16.8 || ^17 || ^18 - peerDependenciesMeta: - js-cookie: - optional: true - checksum: 475d03cdd9a9131b7094549602c8a3ab52ad33e99d7ef408ba2ee7897bfdf332ab5228f46187b9a4c42535b4aaaf808e2c9c882949b2ec32d5ad42d53487a723 - languageName: node - linkType: hard - "@remix-run/router@npm:1.0.4": version: 1.0.4 resolution: "@remix-run/router@npm:1.0.4"