update tests to be more robust against catalog-client changes
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -24,7 +24,7 @@ import {
|
||||
import { CatalogIdentityClient } from './CatalogIdentityClient';
|
||||
|
||||
describe('CatalogIdentityClient', () => {
|
||||
const catalogApi: jest.Mocked<CatalogApi> = {
|
||||
const catalogApi = {
|
||||
getLocationById: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
getEntities: jest.fn(),
|
||||
@@ -48,7 +48,7 @@ describe('CatalogIdentityClient', () => {
|
||||
catalogApi.getEntities.mockResolvedValueOnce({ items: [{} as UserEntity] });
|
||||
tokenManager.getToken.mockResolvedValue({ token: 'my-token' });
|
||||
const client = new CatalogIdentityClient({
|
||||
catalogApi,
|
||||
catalogApi: catalogApi as Partial<CatalogApi> as CatalogApi,
|
||||
tokenManager,
|
||||
});
|
||||
|
||||
@@ -106,7 +106,7 @@ describe('CatalogIdentityClient', () => {
|
||||
tokenManager.getToken.mockResolvedValue({ token: 'my-token' });
|
||||
|
||||
const client = new CatalogIdentityClient({
|
||||
catalogApi,
|
||||
catalogApi: catalogApi as Partial<CatalogApi> as CatalogApi,
|
||||
tokenManager,
|
||||
});
|
||||
|
||||
|
||||
@@ -29,7 +29,19 @@ import { BadgeBuilder } from '../lib';
|
||||
describe('createRouter', () => {
|
||||
let app: express.Express;
|
||||
let badgeBuilder: jest.Mocked<BadgeBuilder>;
|
||||
let catalog: jest.Mocked<CatalogApi>;
|
||||
const catalog = {
|
||||
addLocation: jest.fn(),
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
removeEntityByUid: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
let config: Config;
|
||||
let discovery: PluginEndpointDiscovery;
|
||||
|
||||
@@ -57,20 +69,6 @@ describe('createRouter', () => {
|
||||
createBadgeJson: jest.fn(),
|
||||
createBadgeSvg: jest.fn(),
|
||||
};
|
||||
catalog = {
|
||||
addLocation: jest.fn(),
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
removeEntityByUid: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
|
||||
config = new ConfigReader({
|
||||
backend: {
|
||||
baseUrl: 'http://127.0.0.1',
|
||||
@@ -81,7 +79,7 @@ describe('createRouter', () => {
|
||||
|
||||
const router = await createRouter({
|
||||
badgeBuilder,
|
||||
catalog,
|
||||
catalog: catalog as Partial<CatalogApi> as CatalogApi,
|
||||
config,
|
||||
discovery,
|
||||
});
|
||||
@@ -95,7 +93,7 @@ describe('createRouter', () => {
|
||||
it('works', async () => {
|
||||
const router = await createRouter({
|
||||
badgeBuilder,
|
||||
catalog,
|
||||
catalog: catalog as Partial<CatalogApi> as CatalogApi,
|
||||
config,
|
||||
discovery,
|
||||
});
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { ApiProvider } from '@backstage/core-app-api';
|
||||
import { analyticsApiRef } from '@backstage/core-plugin-api';
|
||||
import {
|
||||
CatalogApi,
|
||||
catalogApiRef,
|
||||
EntityProvider,
|
||||
entityRouteRef,
|
||||
@@ -36,10 +36,24 @@ import { CatalogGraphCard } from './CatalogGraphCard';
|
||||
describe('<CatalogGraphCard/>', () => {
|
||||
let entity: Entity;
|
||||
let wrapper: JSX.Element;
|
||||
let catalog: jest.Mocked<CatalogApi>;
|
||||
const catalog = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
removeEntityByUid: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
let apis: TestApiRegistry;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
entity = {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
@@ -48,19 +62,6 @@ describe('<CatalogGraphCard/>', () => {
|
||||
namespace: 'd',
|
||||
},
|
||||
};
|
||||
catalog = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(async _ => ({ ...entity, relations: [] })),
|
||||
removeEntityByUid: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
apis = TestApiRegistry.from([catalogApiRef, catalog]);
|
||||
|
||||
wrapper = (
|
||||
@@ -73,6 +74,11 @@ describe('<CatalogGraphCard/>', () => {
|
||||
});
|
||||
|
||||
test('renders without exploding', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async _ => ({
|
||||
...entity,
|
||||
relations: [],
|
||||
}));
|
||||
|
||||
const { findByText, findAllByTestId } = await renderInTestApp(wrapper, {
|
||||
mountedRoutes: {
|
||||
'/entity/{kind}/{namespace}/{name}': entityRouteRef,
|
||||
@@ -86,6 +92,11 @@ describe('<CatalogGraphCard/>', () => {
|
||||
});
|
||||
|
||||
test('renders with custom title', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async _ => ({
|
||||
...entity,
|
||||
relations: [],
|
||||
}));
|
||||
|
||||
const { findByText } = await renderInTestApp(
|
||||
<ApiProvider apis={apis}>
|
||||
<EntityProvider entity={entity}>
|
||||
@@ -104,6 +115,11 @@ describe('<CatalogGraphCard/>', () => {
|
||||
});
|
||||
|
||||
test('renders link to standalone viewer', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async _ => ({
|
||||
...entity,
|
||||
relations: [],
|
||||
}));
|
||||
|
||||
const { findByText, getByText } = await renderInTestApp(wrapper, {
|
||||
mountedRoutes: {
|
||||
'/entity/{kind}/{namespace}/{name}': entityRouteRef,
|
||||
@@ -145,6 +161,11 @@ describe('<CatalogGraphCard/>', () => {
|
||||
});
|
||||
|
||||
test('captures analytics event on click', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async _ => ({
|
||||
...entity,
|
||||
relations: [],
|
||||
}));
|
||||
|
||||
const analyticsSpy = new MockAnalyticsApi();
|
||||
const { findByText } = await renderInTestApp(
|
||||
<TestApiProvider apis={[[analyticsApiRef, analyticsSpy]]}>
|
||||
|
||||
@@ -13,13 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { RELATION_HAS_PART, RELATION_PART_OF } from '@backstage/catalog-model';
|
||||
import { analyticsApiRef } from '@backstage/core-plugin-api';
|
||||
import {
|
||||
CatalogApi,
|
||||
catalogApiRef,
|
||||
entityRouteRef,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react';
|
||||
import {
|
||||
MockAnalyticsApi,
|
||||
renderInTestApp,
|
||||
@@ -38,63 +35,59 @@ jest.mock('react-router', () => ({
|
||||
|
||||
describe('<CatalogGraphPage/>', () => {
|
||||
let wrapper: JSX.Element;
|
||||
let catalog: jest.Mocked<CatalogApi>;
|
||||
const entityC = {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'c',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
type: RELATION_PART_OF,
|
||||
targetRef: 'b:d/e',
|
||||
target: {
|
||||
kind: 'b',
|
||||
namespace: 'd',
|
||||
name: 'e',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const entityE = {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'e',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
type: RELATION_HAS_PART,
|
||||
targetRef: 'b:d/c',
|
||||
target: {
|
||||
kind: 'b',
|
||||
namespace: 'd',
|
||||
name: 'c',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const catalog = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
removeEntityByUid: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
const entityC = {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'c',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
type: RELATION_PART_OF,
|
||||
targetRef: 'b:d/e',
|
||||
target: {
|
||||
kind: 'b',
|
||||
namespace: 'd',
|
||||
name: 'e',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const entityE = {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'e',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
type: RELATION_HAS_PART,
|
||||
targetRef: 'b:d/c',
|
||||
target: {
|
||||
kind: 'b',
|
||||
namespace: 'd',
|
||||
name: 'c',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
catalog = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(async (n: any) =>
|
||||
n === 'b:d/e' ? entityE : entityC,
|
||||
),
|
||||
removeEntityByUid: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
|
||||
wrapper = (
|
||||
<TestApiProvider apis={[[catalogApiRef, catalog]]}>
|
||||
<CatalogGraphPage
|
||||
@@ -111,6 +104,10 @@ describe('<CatalogGraphPage/>', () => {
|
||||
afterEach(() => jest.resetAllMocks());
|
||||
|
||||
test('should render without exploding', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async (n: any) =>
|
||||
n === 'b:d/e' ? entityE : entityC,
|
||||
);
|
||||
|
||||
const { getByText, findByText, findAllByTestId } = await renderInTestApp(
|
||||
wrapper,
|
||||
{
|
||||
@@ -128,6 +125,10 @@ describe('<CatalogGraphPage/>', () => {
|
||||
});
|
||||
|
||||
test('should toggle filters', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async (n: any) =>
|
||||
n === 'b:d/e' ? entityE : entityC,
|
||||
);
|
||||
|
||||
const { getByText, queryByText } = await renderInTestApp(wrapper, {
|
||||
mountedRoutes: {
|
||||
'/entity/{kind}/{namespace}/{name}': entityRouteRef,
|
||||
@@ -142,6 +143,10 @@ describe('<CatalogGraphPage/>', () => {
|
||||
});
|
||||
|
||||
test('should select other entity', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async (n: any) =>
|
||||
n === 'b:d/e' ? entityE : entityC,
|
||||
);
|
||||
|
||||
const { getByText, findByText, findAllByTestId } = await renderInTestApp(
|
||||
wrapper,
|
||||
{
|
||||
@@ -159,6 +164,10 @@ describe('<CatalogGraphPage/>', () => {
|
||||
});
|
||||
|
||||
test('should navigate to entity', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async (n: any) =>
|
||||
n === 'b:d/e' ? entityE : entityC,
|
||||
);
|
||||
|
||||
const { getByText, findAllByTestId } = await renderInTestApp(wrapper, {
|
||||
mountedRoutes: {
|
||||
'/entity/{kind}/{namespace}/{name}': entityRouteRef,
|
||||
@@ -174,6 +183,10 @@ describe('<CatalogGraphPage/>', () => {
|
||||
});
|
||||
|
||||
test('should capture analytics event when selecting other entity', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async (n: any) =>
|
||||
n === 'b:d/e' ? entityE : entityC,
|
||||
);
|
||||
|
||||
const analyticsSpy = new MockAnalyticsApi();
|
||||
const { getByText, findAllByTestId } = await renderInTestApp(
|
||||
<TestApiProvider apis={[[analyticsApiRef, analyticsSpy]]}>
|
||||
@@ -200,6 +213,10 @@ describe('<CatalogGraphPage/>', () => {
|
||||
});
|
||||
|
||||
test('should capture analytics event when navigating to entity', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async (n: any) =>
|
||||
n === 'b:d/e' ? entityE : entityC,
|
||||
);
|
||||
|
||||
const analyticsSpy = new MockAnalyticsApi();
|
||||
const { getByText, findAllByTestId } = await renderInTestApp(
|
||||
<TestApiProvider apis={[[analyticsApiRef, analyticsSpy]]}>
|
||||
|
||||
+108
-92
@@ -22,7 +22,7 @@ import {
|
||||
RELATION_PART_OF,
|
||||
} from '@backstage/catalog-model';
|
||||
import { DependencyGraphTypes } from '@backstage/core-components';
|
||||
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
import { catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import React, { FunctionComponent } from 'react';
|
||||
@@ -30,98 +30,96 @@ import { EntityRelationsGraph } from './EntityRelationsGraph';
|
||||
|
||||
describe('<EntityRelationsGraph/>', () => {
|
||||
let Wrapper: FunctionComponent;
|
||||
let catalog: jest.Mocked<CatalogApi>;
|
||||
const entities: { [ref: string]: Entity } = {
|
||||
'b:d/c': {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'c',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'k:d/a1',
|
||||
type: RELATION_OWNER_OF,
|
||||
},
|
||||
{
|
||||
targetRef: 'b:d/c1',
|
||||
type: RELATION_HAS_PART,
|
||||
},
|
||||
],
|
||||
},
|
||||
'k:d/a1': {
|
||||
apiVersion: 'a',
|
||||
kind: 'k',
|
||||
metadata: {
|
||||
name: 'a1',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'b:d/c',
|
||||
type: RELATION_OWNED_BY,
|
||||
},
|
||||
{
|
||||
targetRef: 'b:d/c1',
|
||||
type: RELATION_OWNED_BY,
|
||||
},
|
||||
],
|
||||
},
|
||||
'b:d/c1': {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'c1',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'b:d/c',
|
||||
type: RELATION_PART_OF,
|
||||
},
|
||||
{
|
||||
targetRef: 'k:d/a1',
|
||||
type: RELATION_OWNER_OF,
|
||||
},
|
||||
{
|
||||
targetRef: 'b:d/c2',
|
||||
type: RELATION_HAS_PART,
|
||||
},
|
||||
],
|
||||
},
|
||||
'b:d/c2': {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'c2',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'b:d/c1',
|
||||
type: RELATION_PART_OF,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const catalog = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
removeEntityByUid: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
const CUSTOM_TEST_ID = 'custom-test-id';
|
||||
|
||||
beforeEach(() => {
|
||||
const entities: { [ref: string]: Entity } = {
|
||||
'b:d/c': {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'c',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'k:d/a1',
|
||||
type: RELATION_OWNER_OF,
|
||||
},
|
||||
{
|
||||
targetRef: 'b:d/c1',
|
||||
type: RELATION_HAS_PART,
|
||||
},
|
||||
],
|
||||
},
|
||||
'k:d/a1': {
|
||||
apiVersion: 'a',
|
||||
kind: 'k',
|
||||
metadata: {
|
||||
name: 'a1',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'b:d/c',
|
||||
type: RELATION_OWNED_BY,
|
||||
},
|
||||
{
|
||||
targetRef: 'b:d/c1',
|
||||
type: RELATION_OWNED_BY,
|
||||
},
|
||||
],
|
||||
},
|
||||
'b:d/c1': {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'c1',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'b:d/c',
|
||||
type: RELATION_PART_OF,
|
||||
},
|
||||
{
|
||||
targetRef: 'k:d/a1',
|
||||
type: RELATION_OWNER_OF,
|
||||
},
|
||||
{
|
||||
targetRef: 'b:d/c2',
|
||||
type: RELATION_HAS_PART,
|
||||
},
|
||||
],
|
||||
},
|
||||
'b:d/c2': {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'c2',
|
||||
namespace: 'd',
|
||||
},
|
||||
relations: [
|
||||
{
|
||||
targetRef: 'b:d/c1',
|
||||
type: RELATION_PART_OF,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
catalog = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(async n => entities[n as string]),
|
||||
removeEntityByUid: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
|
||||
Wrapper = ({ children }) => (
|
||||
<TestApiProvider apis={[[catalogApiRef, catalog]]}>
|
||||
{children}
|
||||
@@ -129,7 +127,7 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
@@ -213,6 +211,8 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
});
|
||||
|
||||
test('renders at max depth of one', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async n => entities[n as string]);
|
||||
|
||||
const { findByText, findAllByTestId, findAllByText } =
|
||||
await renderInTestApp(
|
||||
<Wrapper>
|
||||
@@ -235,7 +235,9 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
expect(catalog.getEntityByRef).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
test('renders simplied graph at full depth', async () => {
|
||||
test('renders simplified graph at full depth', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async n => entities[n as string]);
|
||||
|
||||
const { findByText, findAllByText, findAllByTestId } =
|
||||
await renderInTestApp(
|
||||
<Wrapper>
|
||||
@@ -261,6 +263,8 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
});
|
||||
|
||||
test('renders full graph at full depth', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async n => entities[n as string]);
|
||||
|
||||
const { findAllByText, findByText, findAllByTestId } =
|
||||
await renderInTestApp(
|
||||
<Wrapper>
|
||||
@@ -288,6 +292,8 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
});
|
||||
|
||||
test('renders full graph at full depth with merged relations', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async n => entities[n as string]);
|
||||
|
||||
const { findAllByText, findByText, findAllByTestId } =
|
||||
await renderInTestApp(
|
||||
<Wrapper>
|
||||
@@ -313,6 +319,8 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
});
|
||||
|
||||
test('renders a graph with multiple root nodes', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async n => entities[n as string]);
|
||||
|
||||
const { findAllByText, findByText, findAllByTestId } =
|
||||
await renderInTestApp(
|
||||
<Wrapper>
|
||||
@@ -339,6 +347,8 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
});
|
||||
|
||||
test('renders a graph with filtered kinds and relations', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async n => entities[n as string]);
|
||||
|
||||
const { findAllByText, findByText, findAllByTestId } =
|
||||
await renderInTestApp(
|
||||
<Wrapper>
|
||||
@@ -361,6 +371,8 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
});
|
||||
|
||||
test('handle clicks on a node', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async n => entities[n as string]);
|
||||
|
||||
const onNodeClick = jest.fn();
|
||||
const { findByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
@@ -376,6 +388,8 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
});
|
||||
|
||||
test('render custom node', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async n => entities[n as string]);
|
||||
|
||||
const renderNode = (props: DependencyGraphTypes.RenderNodeProps) => (
|
||||
<g>
|
||||
<text>{props.node.id}</text>
|
||||
@@ -398,6 +412,8 @@ describe('<EntityRelationsGraph/>', () => {
|
||||
});
|
||||
|
||||
test('render custom label', async () => {
|
||||
catalog.getEntityByRef.mockImplementation(async n => entities[n as string]);
|
||||
|
||||
const renderLabel = (props: DependencyGraphTypes.RenderLabelProps) => (
|
||||
<g>
|
||||
<text>{`Test-Label${props.edge.label}`}</text>
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { useApi as useApiMocked } from '@backstage/core-plugin-api';
|
||||
import { CatalogApi } from '@backstage/plugin-catalog-react';
|
||||
import { act, renderHook } from '@testing-library/react-hooks';
|
||||
import { useEntityStore } from './useEntityStore';
|
||||
|
||||
@@ -24,23 +24,21 @@ jest.mock('@backstage/core-plugin-api');
|
||||
const useApi = useApiMocked as jest.Mocked<any>;
|
||||
|
||||
describe('useEntityStore', () => {
|
||||
let catalogApi: jest.Mocked<CatalogApi>;
|
||||
const catalogApi = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
removeEntityByUid: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
catalogApi = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
removeEntityByUid: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
refreshEntity: jest.fn(),
|
||||
getEntityAncestors: jest.fn(),
|
||||
getEntityFacets: jest.fn(),
|
||||
validateEntity: jest.fn(),
|
||||
};
|
||||
|
||||
useApi.mockReturnValue(catalogApi);
|
||||
});
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ jest.mock('@octokit/rest', () => {
|
||||
import { ConfigReader, UrlPatternDiscovery } from '@backstage/core-app-api';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ScmAuthApi } from '@backstage/integration-react';
|
||||
import { catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
import { CatalogApi } from '@backstage/plugin-catalog-react';
|
||||
import { setupRequestMockHandlers } from '@backstage/test-utils';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { rest } from 'msw';
|
||||
@@ -89,7 +89,7 @@ describe('CatalogImportClient', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const catalogApi: jest.Mocked<typeof catalogApiRef.T> = {
|
||||
const catalogApi = {
|
||||
getEntities: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
removeLocationById: jest.fn(),
|
||||
@@ -111,7 +111,7 @@ describe('CatalogImportClient', () => {
|
||||
scmAuthApi,
|
||||
scmIntegrationsApi,
|
||||
identityApi,
|
||||
catalogApi,
|
||||
catalogApi: catalogApi as Partial<CatalogApi> as CatalogApi,
|
||||
configApi: new ConfigReader({
|
||||
app: {
|
||||
baseUrl: 'https://demo.backstage.io/',
|
||||
@@ -458,7 +458,7 @@ describe('CatalogImportClient', () => {
|
||||
scmAuthApi,
|
||||
scmIntegrationsApi,
|
||||
identityApi,
|
||||
catalogApi,
|
||||
catalogApi: catalogApi as Partial<CatalogApi> as CatalogApi,
|
||||
configApi: new ConfigReader({
|
||||
catalog: {
|
||||
import: {
|
||||
@@ -610,7 +610,7 @@ describe('CatalogImportClient', () => {
|
||||
scmAuthApi,
|
||||
scmIntegrationsApi,
|
||||
identityApi,
|
||||
catalogApi,
|
||||
catalogApi: catalogApi as Partial<CatalogApi> as CatalogApi,
|
||||
configApi: new ConfigReader({
|
||||
catalog: {
|
||||
import: {
|
||||
@@ -680,7 +680,7 @@ describe('CatalogImportClient', () => {
|
||||
scmAuthApi,
|
||||
scmIntegrationsApi,
|
||||
identityApi,
|
||||
catalogApi,
|
||||
catalogApi: catalogApi as Partial<CatalogApi> as CatalogApi,
|
||||
configApi: new ConfigReader({
|
||||
catalog: {
|
||||
import: {
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ describe('<StepPrepareCreatePullRequest />', () => {
|
||||
preparePullRequest: jest.fn(),
|
||||
};
|
||||
|
||||
const catalogApi: jest.Mocked<typeof catalogApiRef.T> = {
|
||||
const catalogApi = {
|
||||
getEntities: jest.fn(),
|
||||
addLocation: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
|
||||
@@ -21,8 +21,8 @@ import React from 'react';
|
||||
import { DefaultExplorePage } from './DefaultExplorePage';
|
||||
|
||||
describe('<DefaultExplorePage />', () => {
|
||||
const catalogApi: jest.Mocked<typeof catalogApiRef.T> = {
|
||||
addLocation: jest.fn(_a => new Promise(() => {})),
|
||||
const catalogApi = {
|
||||
addLocation: jest.fn(),
|
||||
getEntities: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
|
||||
@@ -22,8 +22,8 @@ import React from 'react';
|
||||
import { DomainExplorerContent } from './DomainExplorerContent';
|
||||
|
||||
describe('<DomainExplorerContent />', () => {
|
||||
const catalogApi: jest.Mocked<typeof catalogApiRef.T> = {
|
||||
addLocation: jest.fn(_a => new Promise(() => {})),
|
||||
const catalogApi = {
|
||||
addLocation: jest.fn(),
|
||||
getEntities: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
|
||||
@@ -22,8 +22,8 @@ import React from 'react';
|
||||
import { GroupsExplorerContent } from '../GroupsExplorerContent';
|
||||
|
||||
describe('<GroupsExplorerContent />', () => {
|
||||
const catalogApi: jest.Mocked<typeof catalogApiRef.T> = {
|
||||
addLocation: jest.fn(_a => new Promise(() => {})),
|
||||
const catalogApi = {
|
||||
addLocation: jest.fn(),
|
||||
getEntities: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
|
||||
@@ -15,21 +15,16 @@
|
||||
*/
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import {
|
||||
CatalogApi,
|
||||
catalogApiRef,
|
||||
entityRouteRef,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react';
|
||||
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
|
||||
import React from 'react';
|
||||
import { FossaApi, fossaApiRef } from '../../api';
|
||||
import { FossaPage } from './FossaPage';
|
||||
|
||||
describe('<FossaPage />', () => {
|
||||
const catalogApi: jest.Mocked<CatalogApi> = {
|
||||
const catalogApi = {
|
||||
addLocation: jest.fn(),
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
getLocationByRef: jest.fn(),
|
||||
getLocationById: jest.fn(),
|
||||
removeEntityByUid: jest.fn(),
|
||||
|
||||
@@ -58,7 +58,7 @@ function mockCatalogClient(entity?: Entity): jest.Mocked<CatalogApi> {
|
||||
if (entity) {
|
||||
mock.getEntityByRef.mockReturnValue(entity);
|
||||
}
|
||||
return mock;
|
||||
return mock as Partial<jest.Mocked<CatalogApi>> as jest.Mocked<CatalogApi>;
|
||||
}
|
||||
|
||||
function mockTodoReader(items?: TodoItem[]): jest.Mocked<TodoReader> {
|
||||
|
||||
Reference in New Issue
Block a user