diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx index 652c9f3873..a9f6e4846f 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx @@ -21,6 +21,7 @@ import { } from '@backstage/catalog-model'; import { ApiProvider } from '@backstage/core-app-api'; import { + catalogApiRef, EntityKindFilter, entityRouteRef, MockEntityListContextProvider, @@ -52,10 +53,15 @@ const entities: Entity[] = [ ]; describe('CatalogTable component', () => { - const mockApis = TestApiRegistry.from([ - starredEntitiesApiRef, - new MockStarredEntitiesApi(), - ]); + const mockApis = TestApiRegistry.from( + [starredEntitiesApiRef, new MockStarredEntitiesApi()], + [ + catalogApiRef, + { + getEntityByRef: jest.fn(), + } as any, + ], + ); beforeEach(() => { window.open = jest.fn(); diff --git a/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx b/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx index 547c636d22..abfe2a17ed 100644 --- a/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx +++ b/plugins/org/src/components/Cards/User/UserProfileCard/UserProfileCard.test.tsx @@ -16,12 +16,25 @@ import { UserEntity } from '@backstage/catalog-model'; import { + CatalogApi, + catalogApiRef, EntityProvider, entityRouteRef, } from '@backstage/plugin-catalog-react'; -import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils'; +import { + renderWithEffects, + TestApiRegistry, + wrapInTestApp, +} from '@backstage/test-utils'; import React from 'react'; import { UserProfileCard } from './UserProfileCard'; +import { ApiProvider } from '@backstage/core-app-api'; + +const catalogApi: jest.Mocked = { + getEntityByRef: jest.fn(), +} as any; + +const apis = TestApiRegistry.from([catalogApiRef, catalogApi]); describe('UserSummary Test', () => { const userEntity: UserEntity = { @@ -50,9 +63,11 @@ describe('UserSummary Test', () => { it('Display Profile Card', async () => { const rendered = await renderWithEffects( wrapInTestApp( - - - , + + + + + , { mountedRoutes: { '/catalog/:namespace/:kind/:name': entityRouteRef, @@ -100,9 +115,11 @@ describe('Edit Button', () => { const rendered = await renderWithEffects( wrapInTestApp( - - - , + + + + + , { mountedRoutes: { '/catalog/:namespace/:kind/:name': entityRouteRef, @@ -143,9 +160,11 @@ describe('Edit Button', () => { const rendered = await renderWithEffects( wrapInTestApp( - - - , + + + + + , { mountedRoutes: { '/catalog/:namespace/:kind/:name': entityRouteRef, @@ -196,9 +215,11 @@ describe('Edit Button', () => { const rendered = await renderWithEffects( wrapInTestApp( - - - , + + + + + , { mountedRoutes: { '/catalog/:namespace/:kind/:name': entityRouteRef, @@ -250,9 +271,11 @@ describe('Edit Button', () => { const rendered = await renderWithEffects( wrapInTestApp( - - - , + + + + + , { mountedRoutes: { '/catalog/:namespace/:kind/:name': entityRouteRef, diff --git a/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx b/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx index 21658ef36e..19995db710 100644 --- a/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx +++ b/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx @@ -15,7 +15,11 @@ */ import { ErrorApi, errorApiRef } from '@backstage/core-plugin-api'; -import { entityRouteRef } from '@backstage/plugin-catalog-react'; +import { + CatalogApi, + catalogApiRef, + entityRouteRef, +} from '@backstage/plugin-catalog-react'; import { AuthorizeResult } from '@backstage/plugin-permission-common'; import { PermissionApi, @@ -42,6 +46,10 @@ jest.mock('./AddEntitiesDrawer', () => ({ describe('PlaylistEntitiesTable', () => { const errorApi: Partial = { post: jest.fn() }; + const catalogApi: jest.Mocked = { + getEntityByRef: jest.fn(), + } as any; + const sampleEntities = [ { kind: 'system', @@ -86,6 +94,7 @@ 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 4594a43a88..e36ec5cfa2 100644 --- a/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx +++ b/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx @@ -15,7 +15,11 @@ */ import { ErrorApi, errorApiRef } from '@backstage/core-plugin-api'; -import { entityRouteRef } from '@backstage/plugin-catalog-react'; +import { + CatalogApi, + catalogApiRef, + entityRouteRef, +} from '@backstage/plugin-catalog-react'; import { AuthorizeResult, isPermission, @@ -80,6 +84,9 @@ 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(); @@ -91,6 +98,7 @@ 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 3dc20312aa..a5e42b477f 100644 --- a/plugins/scaffolder/src/components/ListTasksPage/columns/TemplateTitleColumn.test.tsx +++ b/plugins/scaffolder/src/components/ListTasksPage/columns/TemplateTitleColumn.test.tsx @@ -20,7 +20,11 @@ import React from 'react'; import { TemplateTitleColumn } from './TemplateTitleColumn'; import { scaffolderApiRef } from '../../../api'; import { ScaffolderApi } from '../../../types'; -import { entityRouteRef } from '@backstage/plugin-catalog-react'; +import { + CatalogApi, + catalogApiRef, + entityRouteRef, +} from '@backstage/plugin-catalog-react'; describe('', () => { const scaffolderApiMock: jest.Mocked = { @@ -28,6 +32,10 @@ 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', @@ -38,7 +46,12 @@ 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 4648d47af1..aa19970180 100644 --- a/plugins/scaffolder/src/next/TemplateListPage/TemplateCard/TemplateCard.test.tsx +++ b/plugins/scaffolder/src/next/TemplateListPage/TemplateCard/TemplateCard.test.tsx @@ -15,6 +15,7 @@ */ import { DefaultStarredEntitiesApi } from '@backstage/plugin-catalog'; import { + catalogApiRef, entityRouteRef, starredEntitiesApiRef, } from '@backstage/plugin-catalog-react'; @@ -50,6 +51,12 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], + [ + catalogApiRef, + { + getEntityByRef: jest.fn(), + } as any, + ], ]} > @@ -80,6 +87,12 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], + [ + catalogApiRef, + { + getEntityByRef: jest.fn(), + } as any, + ], ]} > @@ -111,6 +124,12 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], + [ + catalogApiRef, + { + getEntityByRef: jest.fn(), + } as any, + ], ]} > @@ -141,6 +160,12 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], + [ + catalogApiRef, + { + getEntityByRef: jest.fn(), + } as any, + ], ]} > @@ -179,6 +204,12 @@ describe('TemplateCard', () => { storageApi: MockStorageApi.create(), }), ], + [ + catalogApiRef, + { + getEntityByRef: jest.fn(), + } as any, + ], ]} > @@ -218,6 +249,12 @@ 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 098f613773..f9a4c03182 100644 --- a/plugins/techdocs/src/home/components/Tables/DocsTable.test.tsx +++ b/plugins/techdocs/src/home/components/Tables/DocsTable.test.tsx @@ -15,11 +15,16 @@ */ import React from 'react'; import { render } from '@testing-library/react'; -import { wrapInTestApp } from '@backstage/test-utils'; +import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils'; import { configApiRef } from '@backstage/core-plugin-api'; import { DocsTable } from './DocsTable'; import { rootDocsRouteRef } from '../../../routes'; -import { entityRouteRef } from '@backstage/plugin-catalog-react'; +import { + CatalogApi, + catalogApiRef, + entityRouteRef, +} from '@backstage/plugin-catalog-react'; +import { ApiProvider } from '@backstage/core-app-api'; // Hacky way to mock a specific boolean config value. const getOptionalBooleanMock = jest.fn().mockReturnValue(false); @@ -40,6 +45,12 @@ 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(); @@ -48,42 +59,44 @@ 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, @@ -110,27 +123,29 @@ describe('DocsTable test', () => { const { findByText } = render( wrapInTestApp( - + , + spec: { + owner: 'user:owned', + }, + relations: [ + { + targetRef: 'user:default/owned', + type: 'ownedBy', + }, + ], + }, + ]} + /> + , { mountedRoutes: { '/techdocs/:namespace/:kind/:name/*': rootDocsRouteRef, @@ -151,12 +166,17 @@ 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 da193430d5..96cd55b172 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx @@ -20,7 +20,11 @@ import { ThemeProvider } from '@material-ui/core'; import { lightTheme } from '@backstage/theme'; import { CompoundEntityRef } from '@backstage/catalog-model'; -import { entityRouteRef } from '@backstage/plugin-catalog-react'; +import { + CatalogApi, + catalogApiRef, + entityRouteRef, +} from '@backstage/plugin-catalog-react'; import { techdocsApiRef, TechDocsReaderPageProvider, @@ -60,6 +64,10 @@ const techdocsApiMock = { getTechDocsMetadata, }; +const catalogApi: jest.Mocked = { + getEntityByRef: jest.fn(), +} as any; + const Wrapper = ({ entityRef = { kind: mockEntityMetadata.kind, @@ -72,7 +80,12 @@ const Wrapper = ({ children: React.ReactNode; }) => ( - + {children}