packages,plugins: migrate to using TestApiProvider and Registry
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -30,8 +30,9 @@ import { useWebsiteForEntity } from '../../hooks/useWebsiteForEntity';
|
||||
import * as data from '../../__fixtures__/website-list-response.json';
|
||||
import { AuditListForEntity } from './AuditListForEntity';
|
||||
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
|
||||
import { ApiProvider } from '@backstage/core-app-api';
|
||||
import { errorApiRef } from '@backstage/core-plugin-api';
|
||||
import { TestApiRegistry } from '@backstage/test-utils';
|
||||
|
||||
jest.mock('../../hooks/useWebsiteForEntity', () => ({
|
||||
useWebsiteForEntity: jest.fn(),
|
||||
@@ -41,7 +42,7 @@ const websiteListResponse = data as WebsiteListResponse;
|
||||
const entityWebsite = websiteListResponse.items[0];
|
||||
|
||||
describe('<AuditListTableForEntity />', () => {
|
||||
let apis: ApiRegistry;
|
||||
let apis: TestApiRegistry;
|
||||
|
||||
const mockErrorApi: jest.Mocked<typeof errorApiRef.T> = {
|
||||
post: jest.fn(),
|
||||
@@ -49,10 +50,10 @@ describe('<AuditListTableForEntity />', () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
apis = ApiRegistry.from([
|
||||
apis = TestApiRegistry.from(
|
||||
[lighthouseApiRef, new LighthouseRestApi('http://lighthouse')],
|
||||
[errorApiRef, mockErrorApi],
|
||||
]);
|
||||
);
|
||||
|
||||
(useWebsiteForEntity as jest.Mock).mockReturnValue({
|
||||
value: entityWebsite,
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import { wrapInTestApp, setupRequestMockHandlers } from '@backstage/test-utils';
|
||||
import {
|
||||
wrapInTestApp,
|
||||
setupRequestMockHandlers,
|
||||
TestApiRegistry,
|
||||
} from '@backstage/test-utils';
|
||||
import AuditListTable from './AuditListTable';
|
||||
|
||||
import {
|
||||
@@ -28,19 +32,20 @@ import { formatTime } from '../../utils';
|
||||
import { setupServer } from 'msw/node';
|
||||
import * as data from '../../__fixtures__/website-list-response.json';
|
||||
|
||||
import { ApiRegistry, ApiProvider } from '@backstage/core-app-api';
|
||||
import { ApiProvider } from '@backstage/core-app-api';
|
||||
|
||||
const websiteListResponse = data as WebsiteListResponse;
|
||||
|
||||
describe('AuditListTable', () => {
|
||||
let apis: ApiRegistry;
|
||||
let apis: TestApiRegistry;
|
||||
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
beforeEach(() => {
|
||||
apis = ApiRegistry.from([
|
||||
[lighthouseApiRef, new LighthouseRestApi('http://lighthouse')],
|
||||
apis = TestApiRegistry.from([
|
||||
lighthouseApiRef,
|
||||
new LighthouseRestApi('http://lighthouse'),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -23,7 +23,11 @@ jest.mock('react-router-dom', () => {
|
||||
};
|
||||
});
|
||||
|
||||
import { setupRequestMockHandlers, wrapInTestApp } from '@backstage/test-utils';
|
||||
import {
|
||||
setupRequestMockHandlers,
|
||||
TestApiRegistry,
|
||||
wrapInTestApp,
|
||||
} from '@backstage/test-utils';
|
||||
import { fireEvent, render } from '@testing-library/react';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
@@ -35,20 +39,21 @@ import {
|
||||
} from '../../api';
|
||||
import * as data from '../../__fixtures__/website-list-response.json';
|
||||
import AuditList from './index';
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
|
||||
import { ApiProvider } from '@backstage/core-app-api';
|
||||
|
||||
const { useNavigate } = jest.requireMock('react-router-dom');
|
||||
const websiteListResponse = data as WebsiteListResponse;
|
||||
|
||||
describe('AuditList', () => {
|
||||
let apis: ApiRegistry;
|
||||
let apis: TestApiRegistry;
|
||||
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
beforeEach(() => {
|
||||
apis = ApiRegistry.from([
|
||||
[lighthouseApiRef, new LighthouseRestApi('http://lighthouse')],
|
||||
apis = TestApiRegistry.from([
|
||||
lighthouseApiRef,
|
||||
new LighthouseRestApi('http://lighthouse'),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -26,7 +26,11 @@ jest.mock('react-router-dom', () => {
|
||||
};
|
||||
});
|
||||
|
||||
import { setupRequestMockHandlers, wrapInTestApp } from '@backstage/test-utils';
|
||||
import {
|
||||
setupRequestMockHandlers,
|
||||
TestApiRegistry,
|
||||
wrapInTestApp,
|
||||
} from '@backstage/test-utils';
|
||||
import { render } from '@testing-library/react';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
@@ -35,14 +39,14 @@ import { Audit, lighthouseApiRef, LighthouseRestApi, Website } from '../../api';
|
||||
import { formatTime } from '../../utils';
|
||||
import * as data from '../../__fixtures__/website-response.json';
|
||||
import AuditView from './index';
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
|
||||
import { ApiProvider } from '@backstage/core-app-api';
|
||||
|
||||
const { useParams }: { useParams: jest.Mock } =
|
||||
jest.requireMock('react-router-dom');
|
||||
const websiteResponse = data as Website;
|
||||
|
||||
describe('AuditView', () => {
|
||||
let apis: ApiRegistry;
|
||||
let apis: TestApiRegistry;
|
||||
let id: string;
|
||||
|
||||
const server = setupServer();
|
||||
@@ -55,8 +59,9 @@ describe('AuditView', () => {
|
||||
),
|
||||
);
|
||||
|
||||
apis = ApiRegistry.from([
|
||||
[lighthouseApiRef, new LighthouseRestApi('https://lighthouse')],
|
||||
apis = TestApiRegistry.from([
|
||||
lighthouseApiRef,
|
||||
new LighthouseRestApi('https://lighthouse'),
|
||||
]);
|
||||
id = websiteResponse.audits.find(a => a.status === 'COMPLETED')
|
||||
?.id as string;
|
||||
|
||||
@@ -23,7 +23,11 @@ jest.mock('react-router-dom', () => {
|
||||
};
|
||||
});
|
||||
|
||||
import { setupRequestMockHandlers, wrapInTestApp } from '@backstage/test-utils';
|
||||
import {
|
||||
setupRequestMockHandlers,
|
||||
TestApiRegistry,
|
||||
wrapInTestApp,
|
||||
} from '@backstage/test-utils';
|
||||
import { fireEvent, render, waitFor } from '@testing-library/react';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
@@ -32,7 +36,7 @@ import { Audit, lighthouseApiRef, LighthouseRestApi } from '../../api';
|
||||
import * as data from '../../__fixtures__/create-audit-response.json';
|
||||
import CreateAudit from './index';
|
||||
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
|
||||
import { ApiProvider } from '@backstage/core-app-api';
|
||||
import { ErrorApi, errorApiRef } from '@backstage/core-plugin-api';
|
||||
|
||||
const { useNavigate }: { useNavigate: jest.Mock } =
|
||||
@@ -41,17 +45,17 @@ const createAuditResponse = data as Audit;
|
||||
|
||||
// TODO add act() to these tests without breaking them!
|
||||
describe('CreateAudit', () => {
|
||||
let apis: ApiRegistry;
|
||||
let apis: TestApiRegistry;
|
||||
let errorApi: ErrorApi;
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
beforeEach(() => {
|
||||
errorApi = { post: jest.fn(), error$: jest.fn() };
|
||||
apis = ApiRegistry.from([
|
||||
apis = TestApiRegistry.from(
|
||||
[lighthouseApiRef, new LighthouseRestApi('http://lighthouse')],
|
||||
[errorApiRef, errorApi],
|
||||
]);
|
||||
);
|
||||
});
|
||||
|
||||
it('renders the form', () => {
|
||||
|
||||
@@ -21,8 +21,8 @@ import { lighthouseApiRef, WebsiteListResponse } from '../api';
|
||||
import * as data from '../__fixtures__/website-list-response.json';
|
||||
import { useWebsiteForEntity } from './useWebsiteForEntity';
|
||||
|
||||
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
|
||||
import { errorApiRef } from '@backstage/core-plugin-api';
|
||||
import { TestApiProvider } from '@backstage/test-utils';
|
||||
|
||||
const websiteListResponse = data as WebsiteListResponse;
|
||||
const website = websiteListResponse.items[0];
|
||||
@@ -55,14 +55,14 @@ describe('useWebsiteForEntity', () => {
|
||||
|
||||
const wrapper = ({ children }: PropsWithChildren<{}>) => {
|
||||
return (
|
||||
<ApiProvider
|
||||
apis={ApiRegistry.with(errorApiRef, mockErrorApi).with(
|
||||
lighthouseApiRef,
|
||||
mockLighthouseApi,
|
||||
)}
|
||||
<TestApiProvider
|
||||
apis={[
|
||||
[errorApiRef, mockErrorApi],
|
||||
[lighthouseApiRef, mockLighthouseApi],
|
||||
]}
|
||||
>
|
||||
<EntityProvider entity={entity}>{children}</EntityProvider>
|
||||
</ApiProvider>
|
||||
</TestApiProvider>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user