Skip to content

Commit

Permalink
Add catalog api mock for tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Lazarev <[email protected]>
  • Loading branch information
wKich committed Aug 1, 2024
1 parent ca6ac80 commit 39a4007
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
type ScaffolderApi,
} from '@backstage/plugin-scaffolder-react';
import { analyticsApiRef } from '@backstage/core-plugin-api';
import { catalogApiRef, CatalogApi } from '@backstage/plugin-catalog-react';
import { scaffolderPlugin } from '@backstage/plugin-scaffolder';

const scaffolderApiMock: jest.Mocked<ScaffolderApi> = {
Expand All @@ -27,8 +28,24 @@ const scaffolderApiMock: jest.Mocked<ScaffolderApi> = {
cancelTask: jest.fn()
};

const analyticsMock = new MockAnalyticsApi();
const catalogMock: jest.Mocked<CatalogApi> = {
getEntities: jest.fn(),
getEntitiesByRefs: jest.fn(),
queryEntities: jest.fn(),
getEntityAncestors: jest.fn(),
getEntityByRef: jest.fn(),
removeEntityByUid: jest.fn(),
refreshEntity: jest.fn(),
getEntityFacets: jest.fn(),
getLocationById: jest.fn(),
getLocationByRef: jest.fn(),
addLocation: jest.fn(),
removeLocationById: jest.fn(),
getLocationByEntity: jest.fn(),
validateEntity: jest.fn(),
}

const analyticsMock = new MockAnalyticsApi();

describe('<EmbeddedScaffolderWorkflow />', () => {
it('should embed workflow inside another component', async () => {
Expand All @@ -55,7 +72,8 @@ describe('<EmbeddedScaffolderWorkflow />', () => {
const { getByRole, getByText } = await renderInTestApp(
<TestApiProvider apis={[
[scaffolderApiRef, scaffolderApiMock],
[analyticsApiRef, analyticsMock]
[analyticsApiRef, analyticsMock],
[catalogApiRef, catalogMock]
]}>
<SecretsContextProvider>
<EmbeddedScaffolderWorkflow
Expand Down Expand Up @@ -179,7 +197,8 @@ describe('<EmbeddedScaffolderWorkflow />', () => {
const {getByRole} = await renderInTestApp(
<TestApiProvider apis={[
[scaffolderApiRef, scaffolderApiMock],
[analyticsApiRef, analyticsMock]
[analyticsApiRef, analyticsMock],
[catalogApiRef, catalogMock]
]}>
<SecretsContextProvider>
<EmbeddedScaffolderWorkflow
Expand Down Expand Up @@ -207,5 +226,3 @@ describe('<EmbeddedScaffolderWorkflow />', () => {
);
});
});


0 comments on commit 39a4007

Please sign in to comment.