@@ -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();
|
||||
|
||||
@@ -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<CatalogApi> = {
|
||||
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(
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard variant="gridItem" />
|
||||
</EntityProvider>,
|
||||
<ApiProvider apis={apis}>
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard variant="gridItem" />
|
||||
</EntityProvider>
|
||||
</ApiProvider>,
|
||||
{
|
||||
mountedRoutes: {
|
||||
'/catalog/:namespace/:kind/:name': entityRouteRef,
|
||||
@@ -100,9 +115,11 @@ describe('Edit Button', () => {
|
||||
|
||||
const rendered = await renderWithEffects(
|
||||
wrapInTestApp(
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard variant="gridItem" />
|
||||
</EntityProvider>,
|
||||
<ApiProvider apis={apis}>
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard variant="gridItem" />
|
||||
</EntityProvider>
|
||||
</ApiProvider>,
|
||||
{
|
||||
mountedRoutes: {
|
||||
'/catalog/:namespace/:kind/:name': entityRouteRef,
|
||||
@@ -143,9 +160,11 @@ describe('Edit Button', () => {
|
||||
|
||||
const rendered = await renderWithEffects(
|
||||
wrapInTestApp(
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard variant="gridItem" />
|
||||
</EntityProvider>,
|
||||
<ApiProvider apis={apis}>
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard variant="gridItem" />
|
||||
</EntityProvider>
|
||||
</ApiProvider>,
|
||||
{
|
||||
mountedRoutes: {
|
||||
'/catalog/:namespace/:kind/:name': entityRouteRef,
|
||||
@@ -196,9 +215,11 @@ describe('Edit Button', () => {
|
||||
|
||||
const rendered = await renderWithEffects(
|
||||
wrapInTestApp(
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard variant="gridItem" />
|
||||
</EntityProvider>,
|
||||
<ApiProvider apis={apis}>
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard variant="gridItem" />
|
||||
</EntityProvider>
|
||||
</ApiProvider>,
|
||||
{
|
||||
mountedRoutes: {
|
||||
'/catalog/:namespace/:kind/:name': entityRouteRef,
|
||||
@@ -250,9 +271,11 @@ describe('Edit Button', () => {
|
||||
|
||||
const rendered = await renderWithEffects(
|
||||
wrapInTestApp(
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard showLinks variant="gridItem" />
|
||||
</EntityProvider>,
|
||||
<ApiProvider apis={apis}>
|
||||
<EntityProvider entity={userEntity}>
|
||||
<UserProfileCard showLinks variant="gridItem" />
|
||||
</EntityProvider>
|
||||
</ApiProvider>,
|
||||
{
|
||||
mountedRoutes: {
|
||||
'/catalog/:namespace/:kind/:name': entityRouteRef,
|
||||
|
||||
@@ -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<ErrorApi> = { post: jest.fn() };
|
||||
const catalogApi: jest.Mocked<CatalogApi> = {
|
||||
getEntityByRef: jest.fn(),
|
||||
} as any;
|
||||
|
||||
const sampleEntities = [
|
||||
{
|
||||
kind: 'system',
|
||||
@@ -86,6 +94,7 @@ describe('PlaylistEntitiesTable', () => {
|
||||
[errorApiRef, errorApi],
|
||||
[permissionApiRef, permissionApi],
|
||||
[playlistApiRef, playlistApi],
|
||||
[catalogApiRef, catalogApi],
|
||||
]}
|
||||
>
|
||||
<PlaylistEntitiesTable playlistId="playlist-id" />
|
||||
|
||||
@@ -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<PermissionApi> = { authorize: mockAuthorize };
|
||||
const catalogApi: jest.Mocked<CatalogApi> = {
|
||||
getEntityByRef: jest.fn(),
|
||||
} as any;
|
||||
|
||||
const mockOnUpdate = jest.fn();
|
||||
|
||||
@@ -91,6 +98,7 @@ describe('PlaylistHeader', () => {
|
||||
[errorApiRef, errorApi],
|
||||
[permissionApiRef, permissionApi],
|
||||
[playlistApiRef, playlistApi],
|
||||
[catalogApiRef, catalogApi],
|
||||
]}
|
||||
>
|
||||
<PlaylistHeader playlist={testPlaylist} onUpdate={mockOnUpdate} />
|
||||
|
||||
+15
-2
@@ -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('<TemplateTitleColumn />', () => {
|
||||
const scaffolderApiMock: jest.Mocked<ScaffolderApi> = {
|
||||
@@ -28,6 +32,10 @@ describe('<TemplateTitleColumn />', () => {
|
||||
getTemplateParameterSchema: jest.fn(),
|
||||
} as any;
|
||||
|
||||
const catalogApi: jest.Mocked<CatalogApi> = {
|
||||
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('<TemplateTitleColumn />', () => {
|
||||
});
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<TestApiProvider apis={[[scaffolderApiRef, scaffolderApiMock]]}>
|
||||
<TestApiProvider
|
||||
apis={[
|
||||
[scaffolderApiRef, scaffolderApiMock],
|
||||
[catalogApiRef, catalogApi],
|
||||
]}
|
||||
>
|
||||
<TemplateTitleColumn {...props} />
|
||||
</TestApiProvider>,
|
||||
{ mountedRoutes: { '/test': entityRouteRef } },
|
||||
|
||||
@@ -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,
|
||||
],
|
||||
]}
|
||||
>
|
||||
<TemplateCard template={mockTemplate} />
|
||||
@@ -80,6 +87,12 @@ describe('TemplateCard', () => {
|
||||
storageApi: MockStorageApi.create(),
|
||||
}),
|
||||
],
|
||||
[
|
||||
catalogApiRef,
|
||||
{
|
||||
getEntityByRef: jest.fn(),
|
||||
} as any,
|
||||
],
|
||||
]}
|
||||
>
|
||||
<TemplateCard template={mockTemplate} />
|
||||
@@ -111,6 +124,12 @@ describe('TemplateCard', () => {
|
||||
storageApi: MockStorageApi.create(),
|
||||
}),
|
||||
],
|
||||
[
|
||||
catalogApiRef,
|
||||
{
|
||||
getEntityByRef: jest.fn(),
|
||||
} as any,
|
||||
],
|
||||
]}
|
||||
>
|
||||
<TemplateCard template={mockTemplate} />
|
||||
@@ -141,6 +160,12 @@ describe('TemplateCard', () => {
|
||||
storageApi: MockStorageApi.create(),
|
||||
}),
|
||||
],
|
||||
[
|
||||
catalogApiRef,
|
||||
{
|
||||
getEntityByRef: jest.fn(),
|
||||
} as any,
|
||||
],
|
||||
]}
|
||||
>
|
||||
<TemplateCard template={mockTemplate} />
|
||||
@@ -179,6 +204,12 @@ describe('TemplateCard', () => {
|
||||
storageApi: MockStorageApi.create(),
|
||||
}),
|
||||
],
|
||||
[
|
||||
catalogApiRef,
|
||||
{
|
||||
getEntityByRef: jest.fn(),
|
||||
} as any,
|
||||
],
|
||||
]}
|
||||
>
|
||||
<TemplateCard template={mockTemplate} />
|
||||
@@ -218,6 +249,12 @@ describe('TemplateCard', () => {
|
||||
storageApi: MockStorageApi.create(),
|
||||
}),
|
||||
],
|
||||
[
|
||||
catalogApiRef,
|
||||
{
|
||||
getEntityByRef: jest.fn(),
|
||||
} as any,
|
||||
],
|
||||
]}
|
||||
>
|
||||
<TemplateCard template={mockTemplate} />
|
||||
|
||||
@@ -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<CatalogApi> = {
|
||||
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(
|
||||
<DocsTable
|
||||
entities={[
|
||||
{
|
||||
apiVersion: 'version',
|
||||
kind: 'TestKind',
|
||||
metadata: {
|
||||
name: 'testName',
|
||||
},
|
||||
spec: {
|
||||
owner: 'user:owned',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'user:default/owned',
|
||||
type: 'ownedBy',
|
||||
<ApiProvider apis={apis}>
|
||||
<DocsTable
|
||||
entities={[
|
||||
{
|
||||
apiVersion: 'version',
|
||||
kind: 'TestKind',
|
||||
metadata: {
|
||||
name: 'testName',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
apiVersion: 'version',
|
||||
kind: 'TestKind2',
|
||||
metadata: {
|
||||
name: 'testName2',
|
||||
},
|
||||
spec: {
|
||||
owner: 'not-owned@example.com',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'user:default/not-owned',
|
||||
type: 'ownedBy',
|
||||
spec: {
|
||||
owner: 'user:owned',
|
||||
},
|
||||
],
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
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',
|
||||
},
|
||||
],
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</ApiProvider>,
|
||||
{
|
||||
mountedRoutes: {
|
||||
'/docs/:namespace/:kind/:name/*': rootDocsRouteRef,
|
||||
@@ -110,27 +123,29 @@ describe('DocsTable test', () => {
|
||||
|
||||
const { findByText } = render(
|
||||
wrapInTestApp(
|
||||
<DocsTable
|
||||
entities={[
|
||||
{
|
||||
apiVersion: 'version',
|
||||
kind: 'TestKind',
|
||||
metadata: {
|
||||
name: 'testName',
|
||||
namespace: 'SomeNamespace',
|
||||
},
|
||||
spec: {
|
||||
owner: 'user:owned',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'user:default/owned',
|
||||
type: 'ownedBy',
|
||||
<ApiProvider apis={apis}>
|
||||
<DocsTable
|
||||
entities={[
|
||||
{
|
||||
apiVersion: 'version',
|
||||
kind: 'TestKind',
|
||||
metadata: {
|
||||
name: 'testName',
|
||||
namespace: 'SomeNamespace',
|
||||
},
|
||||
],
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
spec: {
|
||||
owner: 'user:owned',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'user:default/owned',
|
||||
type: 'ownedBy',
|
||||
},
|
||||
],
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</ApiProvider>,
|
||||
{
|
||||
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(<DocsTable entities={[]} />, {
|
||||
mountedRoutes: {
|
||||
'/docs/:namespace/:kind/:name/*': rootDocsRouteRef,
|
||||
'/catalog/:namespace/:kind/:name': entityRouteRef,
|
||||
wrapInTestApp(
|
||||
<ApiProvider apis={apis}>
|
||||
<DocsTable entities={[]} />
|
||||
</ApiProvider>,
|
||||
{
|
||||
mountedRoutes: {
|
||||
'/docs/:namespace/:kind/:name/*': rootDocsRouteRef,
|
||||
'/catalog/:namespace/:kind/:name': entityRouteRef,
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
expect(await findByText('No documents to show')).toBeInTheDocument();
|
||||
|
||||
+15
-2
@@ -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<CatalogApi> = {
|
||||
getEntityByRef: jest.fn(),
|
||||
} as any;
|
||||
|
||||
const Wrapper = ({
|
||||
entityRef = {
|
||||
kind: mockEntityMetadata.kind,
|
||||
@@ -72,7 +80,12 @@ const Wrapper = ({
|
||||
children: React.ReactNode;
|
||||
}) => (
|
||||
<ThemeProvider theme={lightTheme}>
|
||||
<TestApiProvider apis={[[techdocsApiRef, techdocsApiMock]]}>
|
||||
<TestApiProvider
|
||||
apis={[
|
||||
[techdocsApiRef, techdocsApiMock],
|
||||
[catalogApiRef, catalogApi],
|
||||
]}
|
||||
>
|
||||
<TechDocsReaderPageProvider entityRef={entityRef}>
|
||||
{children}
|
||||
</TechDocsReaderPageProvider>
|
||||
|
||||
Reference in New Issue
Block a user