revert more test changes

Signed-off-by: Brian Fletcher <brian@roadie.io>
This commit is contained in:
Brian Fletcher
2022-12-07 14:55:44 +00:00
parent 347648d8a2
commit 8f742612d3
9 changed files with 129 additions and 329 deletions
@@ -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<CatalogApi> = {
getEntityByRef: jest.fn(),
} as any;
const apis = TestApiRegistry.from([catalogApiRef, catalogApi]);
describe('<AboutContent />', () => {
describe('An unknown entity', () => {
@@ -71,16 +63,11 @@ describe('<AboutContent />', () => {
});
it('renders info', async () => {
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -106,16 +93,11 @@ describe('<AboutContent />', () => {
entity.spec = {};
entity.relations = [];
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -166,16 +148,11 @@ describe('<AboutContent />', () => {
});
it('renders info', async () => {
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -208,16 +185,11 @@ describe('<AboutContent />', () => {
delete entity.spec!.system;
entity.relations = [];
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -281,16 +253,11 @@ describe('<AboutContent />', () => {
});
it('renders info', async () => {
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -326,16 +293,11 @@ describe('<AboutContent />', () => {
delete entity.spec!.system;
entity.relations = [];
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -387,16 +349,11 @@ describe('<AboutContent />', () => {
});
it('renders info', async () => {
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -419,16 +376,11 @@ describe('<AboutContent />', () => {
delete entity.metadata.tags;
entity.relations = [];
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -469,16 +421,11 @@ describe('<AboutContent />', () => {
});
it('renders info', async () => {
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -506,16 +453,11 @@ describe('<AboutContent />', () => {
delete entity.metadata.tags;
delete entity.spec!.type;
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -567,16 +509,11 @@ describe('<AboutContent />', () => {
});
it('renders info', async () => {
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -605,16 +542,11 @@ describe('<AboutContent />', () => {
delete entity.spec!.system;
entity.relations = [];
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -668,16 +600,11 @@ describe('<AboutContent />', () => {
});
it('renders info', async () => {
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -704,16 +631,11 @@ describe('<AboutContent />', () => {
delete entity.spec!.domain;
entity.relations = [];
await renderInTestApp(
<ApiProvider apis={apis}>
<AboutContent entity={entity} />
</ApiProvider>,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
await renderInTestApp(<AboutContent entity={entity} />, {
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
);
});
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Description').nextSibling).toHaveTextContent(
@@ -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();
@@ -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<ErrorApi> = { post: jest.fn() };
const catalogApi: jest.Mocked<CatalogApi> = {
getEntityByRef: jest.fn(),
} as any;
const sampleEntities = [
{
kind: 'system',
@@ -94,7 +86,6 @@ describe('PlaylistEntitiesTable', () => {
[errorApiRef, errorApi],
[permissionApiRef, permissionApi],
[playlistApiRef, playlistApi],
[catalogApiRef, catalogApi],
]}
>
<PlaylistEntitiesTable playlistId="playlist-id" />
@@ -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<PermissionApi> = { authorize: mockAuthorize };
const catalogApi: jest.Mocked<CatalogApi> = {
getEntityByRef: jest.fn(),
} as any;
const mockOnUpdate = jest.fn();
@@ -98,7 +91,6 @@ describe('PlaylistHeader', () => {
[errorApiRef, errorApi],
[permissionApiRef, permissionApi],
[playlistApiRef, playlistApi],
[catalogApiRef, catalogApi],
]}
>
<PlaylistHeader playlist={testPlaylist} onUpdate={mockOnUpdate} />
@@ -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('<TemplateTitleColumn />', () => {
const scaffolderApiMock: jest.Mocked<ScaffolderApi> = {
@@ -32,10 +28,6 @@ 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',
@@ -46,12 +38,7 @@ describe('<TemplateTitleColumn />', () => {
});
const { getByText } = await renderInTestApp(
<TestApiProvider
apis={[
[scaffolderApiRef, scaffolderApiMock],
[catalogApiRef, catalogApi],
]}
>
<TestApiProvider apis={[[scaffolderApiRef, scaffolderApiMock]]}>
<TemplateTitleColumn {...props} />
</TestApiProvider>,
{ mountedRoutes: { '/test': entityRouteRef } },
@@ -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,
],
]}
>
<TemplateCard template={mockTemplate} />
@@ -87,12 +80,6 @@ describe('TemplateCard', () => {
storageApi: MockStorageApi.create(),
}),
],
[
catalogApiRef,
{
getEntityByRef: jest.fn(),
} as any,
],
]}
>
<TemplateCard template={mockTemplate} />
@@ -124,12 +111,6 @@ describe('TemplateCard', () => {
storageApi: MockStorageApi.create(),
}),
],
[
catalogApiRef,
{
getEntityByRef: jest.fn(),
} as any,
],
]}
>
<TemplateCard template={mockTemplate} />
@@ -160,12 +141,6 @@ describe('TemplateCard', () => {
storageApi: MockStorageApi.create(),
}),
],
[
catalogApiRef,
{
getEntityByRef: jest.fn(),
} as any,
],
]}
>
<TemplateCard template={mockTemplate} />
@@ -204,12 +179,6 @@ describe('TemplateCard', () => {
storageApi: MockStorageApi.create(),
}),
],
[
catalogApiRef,
{
getEntityByRef: jest.fn(),
} as any,
],
]}
>
<TemplateCard template={mockTemplate} />
@@ -249,12 +218,6 @@ describe('TemplateCard', () => {
storageApi: MockStorageApi.create(),
}),
],
[
catalogApiRef,
{
getEntityByRef: jest.fn(),
} as any,
],
]}
>
<TemplateCard template={mockTemplate} />
@@ -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<CatalogApi> = {
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(
<ApiProvider apis={apis}>
<DocsTable
entities={[
{
apiVersion: 'version',
kind: 'TestKind',
metadata: {
name: 'testName',
},
spec: {
owner: 'user:owned',
},
relations: [
{
targetRef: 'user:default/owned',
type: 'ownedBy',
},
],
<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',
},
]}
/>
</ApiProvider>,
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(
<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',
},
],
<DocsTable
entities={[
{
apiVersion: 'version',
kind: 'TestKind',
metadata: {
name: 'testName',
namespace: 'SomeNamespace',
},
]}
/>
</ApiProvider>,
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(
<ApiProvider apis={apis}>
<DocsTable entities={[]} />
</ApiProvider>,
{
mountedRoutes: {
'/docs/:namespace/:kind/:name/*': rootDocsRouteRef,
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
wrapInTestApp(<DocsTable entities={[]} />, {
mountedRoutes: {
'/docs/:namespace/:kind/:name/*': rootDocsRouteRef,
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
),
}),
);
expect(await findByText('No documents to show')).toBeInTheDocument();
@@ -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<CatalogApi> = {
getEntityByRef: jest.fn(),
} as any;
const Wrapper = ({
entityRef = {
kind: mockEntityMetadata.kind,
@@ -80,12 +72,7 @@ const Wrapper = ({
children: React.ReactNode;
}) => (
<ThemeProvider theme={lightTheme}>
<TestApiProvider
apis={[
[techdocsApiRef, techdocsApiMock],
[catalogApiRef, catalogApi],
]}
>
<TestApiProvider apis={[[techdocsApiRef, techdocsApiMock]]}>
<TechDocsReaderPageProvider entityRef={entityRef}>
{children}
</TechDocsReaderPageProvider>
-16
View File
@@ -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"