packages,plugins: migrate to using TestApiProvider and Registry

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-11-17 18:56:22 +01:00
parent 7ff56c2330
commit 29ef695410
118 changed files with 991 additions and 1112 deletions
@@ -16,15 +16,15 @@
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { ChangeEvent } from '../types';
import { wrapInTestApp } from '@backstage/test-utils';
import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils';
import { pagerDutyApiRef } from '../../api';
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { ApiProvider } from '@backstage/core-app-api';
import { ChangeEvents } from './ChangeEvents';
const mockPagerDutyApi = {
getChangeEventsByServiceId: () => [],
getChangeEventsByServiceId: jest.fn(),
};
const apis = ApiRegistry.from([[pagerDutyApiRef, mockPagerDutyApi]]);
const apis = TestApiRegistry.from([pagerDutyApiRef, mockPagerDutyApi]);
describe('Incidents', () => {
it('Renders an empty state when there are no change events', async () => {
@@ -16,15 +16,15 @@
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { EscalationPolicy } from './EscalationPolicy';
import { wrapInTestApp } from '@backstage/test-utils';
import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils';
import { User } from '../types';
import { pagerDutyApiRef } from '../../api';
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { ApiProvider } from '@backstage/core-app-api';
const mockPagerDutyApi = {
getOnCallByPolicyId: () => [],
getOnCallByPolicyId: jest.fn(),
};
const apis = ApiRegistry.from([[pagerDutyApiRef, mockPagerDutyApi]]);
const apis = TestApiRegistry.from([pagerDutyApiRef, mockPagerDutyApi]);
describe('Escalation', () => {
it('Handles an empty response', async () => {
@@ -16,15 +16,15 @@
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { Incidents } from './Incidents';
import { wrapInTestApp } from '@backstage/test-utils';
import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils';
import { pagerDutyApiRef } from '../../api';
import { Incident } from '../types';
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { ApiProvider } from '@backstage/core-app-api';
const mockPagerDutyApi = {
getIncidentsByServiceId: () => [],
getIncidentsByServiceId: jest.fn(),
};
const apis = ApiRegistry.from([[pagerDutyApiRef, mockPagerDutyApi]]);
const apis = TestApiRegistry.from([pagerDutyApiRef, mockPagerDutyApi]);
describe('Incidents', () => {
it('Renders an empty state when there are no incidents', async () => {
@@ -18,12 +18,12 @@ import { render, waitFor, fireEvent, act } from '@testing-library/react';
import { PagerDutyCard } from '../PagerDutyCard';
import { Entity } from '@backstage/catalog-model';
import { EntityProvider } from '@backstage/plugin-catalog-react';
import { wrapInTestApp } from '@backstage/test-utils';
import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils';
import { pagerDutyApiRef, UnauthorizedError, PagerDutyClient } from '../../api';
import { Service, User } from '../types';
import { alertApiRef, createApiRef } from '@backstage/core-plugin-api';
import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { alertApiRef } from '@backstage/core-plugin-api';
import { ApiProvider } from '@backstage/core-app-api';
const mockPagerDutyApi: Partial<PagerDutyClient> = {
getServiceByIntegrationKey: async () => [],
@@ -31,16 +31,10 @@ const mockPagerDutyApi: Partial<PagerDutyClient> = {
getIncidentsByServiceId: async () => [],
};
const apis = ApiRegistry.from([
const apis = TestApiRegistry.from(
[pagerDutyApiRef, mockPagerDutyApi],
[
alertApiRef,
createApiRef({
id: 'core.alert',
description: 'Used to report alerts and forward them to the app',
}),
],
]);
[alertApiRef, {}],
);
const entity: Entity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
@@ -15,16 +15,15 @@
*/
import React from 'react';
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import { pagerDutyApiRef } from '../../api';
import { Entity } from '@backstage/catalog-model';
import { EntityProvider } from '@backstage/plugin-catalog-react';
import { TriggerButton } from './';
import { ApiRegistry, ApiProvider } from '@backstage/core-app-api';
import { ApiProvider } from '@backstage/core-app-api';
import {
alertApiRef,
createApiRef,
IdentityApi,
identityApiRef,
} from '@backstage/core-plugin-api';
@@ -39,17 +38,11 @@ describe('TriggerButton', () => {
triggerAlarm: mockTriggerAlarmFn,
};
const apis = ApiRegistry.from([
[
alertApiRef,
createApiRef({
id: 'core.alert',
description: 'Used to report alerts and forward them to the app',
}),
],
const apis = TestApiRegistry.from(
[alertApiRef, {}],
[identityApiRef, mockIdentityApi],
[pagerDutyApiRef, mockPagerDutyApi],
]);
);
it('renders the trigger button, opens and closes dialog', async () => {
const entity: Entity = {
@@ -15,16 +15,15 @@
*/
import React from 'react';
import { fireEvent, act } from '@testing-library/react';
import { renderInTestApp } from '@backstage/test-utils';
import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import { pagerDutyApiRef } from '../../api';
import { Entity } from '@backstage/catalog-model';
import { EntityProvider } from '@backstage/plugin-catalog-react';
import { TriggerDialog } from './TriggerDialog';
import { ApiRegistry, ApiProvider } from '@backstage/core-app-api';
import { ApiProvider } from '@backstage/core-app-api';
import {
alertApiRef,
createApiRef,
IdentityApi,
identityApiRef,
} from '@backstage/core-plugin-api';
@@ -39,17 +38,11 @@ describe('TriggerDialog', () => {
triggerAlarm: mockTriggerAlarmFn,
};
const apis = ApiRegistry.from([
[
alertApiRef,
createApiRef({
id: 'core.alert',
description: 'Used to report alerts and forward them to the app',
}),
],
const apis = TestApiRegistry.from(
[alertApiRef, {}],
[identityApiRef, mockIdentityApi],
[pagerDutyApiRef, mockPagerDutyApi],
]);
);
it('open the dialog and trigger an alarm', async () => {
const entity: Entity = {