@@ -22,6 +22,7 @@ import {
|
||||
EntityProvider,
|
||||
entityRouteRef,
|
||||
} from '@backstage/plugin-catalog-react';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
import {
|
||||
MockAnalyticsApi,
|
||||
renderInTestApp,
|
||||
@@ -38,20 +39,7 @@ import Button from '@material-ui/core/Button';
|
||||
describe('<CatalogGraphCard/>', () => {
|
||||
let entity: Entity;
|
||||
let wrapper: JSX.Element;
|
||||
const catalog = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
getEntitiesByRefs: 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 catalog = catalogApiMock.mock();
|
||||
let apis: TestApiRegistry;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -14,9 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { RELATION_HAS_PART, RELATION_PART_OF } from '@backstage/catalog-model';
|
||||
import {
|
||||
Entity,
|
||||
RELATION_HAS_PART,
|
||||
RELATION_PART_OF,
|
||||
} from '@backstage/catalog-model';
|
||||
import { analyticsApiRef } from '@backstage/core-plugin-api';
|
||||
import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
import {
|
||||
MockAnalyticsApi,
|
||||
renderInTestApp,
|
||||
@@ -112,24 +117,11 @@ describe.skip('<CatalogGraphPage/>', () => {
|
||||
},
|
||||
],
|
||||
};
|
||||
const allEntities: Record<string, object> = {
|
||||
const allEntities: Record<string, Entity> = {
|
||||
'b:d/c': entityC,
|
||||
'b:d/e': entityE,
|
||||
};
|
||||
const catalog = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
getEntitiesByRefs: 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 catalog = catalogApiMock.mock();
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = (
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { GetEntityFacetsResponse } from '@backstage/catalog-client';
|
||||
import { ApiProvider } from '@backstage/core-app-api';
|
||||
import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
|
||||
import { catalogApiRef } from '@backstage/plugin-catalog-react';
|
||||
@@ -23,8 +22,9 @@ import { waitFor, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import React from 'react';
|
||||
import { SelectedKindsFilter } from './SelectedKindsFilter';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
|
||||
const catalogApi = {
|
||||
const catalogApi = catalogApiMock.mock({
|
||||
getEntityFacets: jest.fn().mockResolvedValue({
|
||||
facets: {
|
||||
kind: [
|
||||
@@ -34,8 +34,8 @@ const catalogApi = {
|
||||
{ value: 'Resource', count: 1 },
|
||||
],
|
||||
},
|
||||
} as GetEntityFacetsResponse),
|
||||
};
|
||||
}),
|
||||
});
|
||||
const apis = TestApiRegistry.from(
|
||||
[catalogApiRef, catalogApi],
|
||||
[alertApiRef, {} as AlertApi],
|
||||
|
||||
+2
-13
@@ -28,6 +28,7 @@ import { screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import React, { FunctionComponent } from 'react';
|
||||
import { EntityRelationsGraph } from './EntityRelationsGraph';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
|
||||
/*
|
||||
The tests in this file have been disabled for the following error:
|
||||
@@ -142,19 +143,7 @@ describe.skip('<EntityRelationsGraph/>', () => {
|
||||
],
|
||||
},
|
||||
};
|
||||
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 catalog = catalogApiMock.mock();
|
||||
const CUSTOM_TEST_ID = 'custom-test-id';
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -18,26 +18,14 @@ import { Entity } from '@backstage/catalog-model';
|
||||
import { useApi as useApiMocked } from '@backstage/core-plugin-api';
|
||||
import { act, renderHook, waitFor } from '@testing-library/react';
|
||||
import { useEntityStore } from './useEntityStore';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
|
||||
jest.mock('@backstage/core-plugin-api');
|
||||
|
||||
const useApi = useApiMocked as jest.Mocked<any>;
|
||||
|
||||
describe('useEntityStore', () => {
|
||||
const catalogApi = {
|
||||
getEntities: jest.fn(),
|
||||
getEntityByRef: jest.fn(),
|
||||
getEntitiesByRefs: 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 catalogApi = catalogApiMock.mock();
|
||||
|
||||
beforeEach(() => {
|
||||
useApi.mockReturnValue(catalogApi);
|
||||
|
||||
+2
-13
@@ -27,6 +27,7 @@ import {
|
||||
generateEntities,
|
||||
StepPrepareCreatePullRequest,
|
||||
} from './StepPrepareCreatePullRequest';
|
||||
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
|
||||
|
||||
describe('<StepPrepareCreatePullRequest />', () => {
|
||||
const catalogImportApi: jest.Mocked<typeof catalogImportApiRef.T> = {
|
||||
@@ -35,19 +36,7 @@ describe('<StepPrepareCreatePullRequest />', () => {
|
||||
preparePullRequest: jest.fn(),
|
||||
};
|
||||
|
||||
const catalogApi = {
|
||||
getEntities: jest.fn(),
|
||||
addLocation: 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(),
|
||||
};
|
||||
const catalogApi = catalogApiMock.mock();
|
||||
|
||||
const errorApi: jest.Mocked<typeof errorApiRef.T> = {
|
||||
error$: jest.fn(),
|
||||
|
||||
@@ -20,6 +20,7 @@ import { renderHook, waitFor } from '@testing-library/react';
|
||||
import React, { ComponentType, PropsWithChildren } from 'react';
|
||||
import { catalogApiRef } from '../api';
|
||||
import { useRelatedEntities } from './useRelatedEntities';
|
||||
import { catalogApiMock } from '../testUtils';
|
||||
|
||||
describe('useRelatedEntities', () => {
|
||||
afterEach(() => {
|
||||
@@ -46,9 +47,7 @@ describe('useRelatedEntities', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const catalogApi = {
|
||||
getEntitiesByRefs: jest.fn(),
|
||||
};
|
||||
const catalogApi = catalogApiMock.mock();
|
||||
|
||||
const wrapper: ComponentType<PropsWithChildren<{}>> = ({ children }) => {
|
||||
return (
|
||||
@@ -60,7 +59,7 @@ describe('useRelatedEntities', () => {
|
||||
|
||||
it('filters and requests entities', async () => {
|
||||
catalogApi.getEntitiesByRefs.mockResolvedValueOnce({
|
||||
items: [entity, null], // one of them doesn't exist
|
||||
items: [entity, undefined], // one of them doesn't exist
|
||||
});
|
||||
|
||||
const rendered = renderHook(
|
||||
|
||||
@@ -84,11 +84,11 @@ describe('StarredEntitiesContent', () => {
|
||||
it('should display call to action message if no entities are starred', async () => {
|
||||
const mockedApi = new MockStarredEntitiesApi();
|
||||
|
||||
const mockCatalogApi = {
|
||||
const mockCatalogApi = catalogApiMock.mock({
|
||||
getEntitiesByRefs: jest
|
||||
.fn()
|
||||
.mockImplementation(async () => ({ items: entities })),
|
||||
};
|
||||
});
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<TestApiProvider
|
||||
@@ -114,11 +114,11 @@ describe('StarredEntitiesContent', () => {
|
||||
it('should display user provided message if no entities are starred', async () => {
|
||||
const mockedApi = new MockStarredEntitiesApi();
|
||||
|
||||
const mockCatalogApi = {
|
||||
const mockCatalogApi = catalogApiMock.mock({
|
||||
getEntitiesByRefs: jest
|
||||
.fn()
|
||||
.mockImplementation(async () => ({ items: entities })),
|
||||
};
|
||||
});
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<TestApiProvider
|
||||
|
||||
Reference in New Issue
Block a user