diff --git a/docs/plugins/analytics.md b/docs/plugins/analytics.md
index 7adf2650df..ace9a89968 100644
--- a/docs/plugins/analytics.md
+++ b/docs/plugins/analytics.md
@@ -261,10 +261,13 @@ analytics events captured.
Use it like this:
```tsx
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
-import { analyticsApiRef } from '@backstage/core-plugin-api';
-import { MockAnalyticsApi, wrapInTestApp } from '@backstage/test-utils';
import { render, fireEvent, waitFor } from '@testing-library/react';
+import { analyticsApiRef } from '@backstage/core-plugin-api';
+import {
+ MockAnalyticsApi,
+ TestApiProvider,
+ wrapInTestApp,
+} from '@backstage/test-utils';
describe('SomeComponent', () => {
it('should capture event on click', () => {
@@ -274,9 +277,9 @@ describe('SomeComponent', () => {
// Render the component being tested
const { getByText } = render(
wrapInTestApp(
-
+
- ,
+ ,
),
);
diff --git a/packages/app/src/components/catalog/EntityPage.test.tsx b/packages/app/src/components/catalog/EntityPage.test.tsx
index 089cb9c7cf..a6878cd28b 100644
--- a/packages/app/src/components/catalog/EntityPage.test.tsx
+++ b/packages/app/src/components/catalog/EntityPage.test.tsx
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { EntityLayout } from '@backstage/plugin-catalog';
import {
DefaultStarredEntitiesApi,
@@ -22,7 +21,11 @@ import {
starredEntitiesApiRef,
} from '@backstage/plugin-catalog-react';
import { githubActionsApiRef } from '@backstage/plugin-github-actions';
-import { MockStorageApi, renderInTestApp } from '@backstage/test-utils';
+import {
+ MockStorageApi,
+ renderInTestApp,
+ TestApiProvider,
+} from '@backstage/test-utils';
import React from 'react';
import { cicdContent } from './EntityPage';
@@ -45,22 +48,22 @@ describe('EntityPage Test', () => {
const mockedApi = {
listWorkflowRuns: jest.fn().mockResolvedValue([]),
- getWorkflow: jest.fn(),
- getWorkflowRun: jest.fn(),
- reRunWorkflow: jest.fn(),
- listJobsForWorkflowRun: jest.fn(),
- downloadJobLogsForWorkflowRun: jest.fn(),
- } as jest.Mocked;
-
- const apis = ApiRegistry.with(githubActionsApiRef, mockedApi).with(
- starredEntitiesApiRef,
- new DefaultStarredEntitiesApi({ storageApi: MockStorageApi.create() }),
- );
+ };
describe('cicdContent', () => {
it('Should render GitHub Actions View', async () => {
const rendered = await renderInTestApp(
-
+
@@ -68,7 +71,7 @@ describe('EntityPage Test', () => {
- ,
+ ,
);
expect(rendered.getByText('ExampleComponent')).toBeInTheDocument();
diff --git a/packages/dev-utils/src/devApp/SidebarThemeSwitcher.test.tsx b/packages/dev-utils/src/devApp/SidebarThemeSwitcher.test.tsx
index 3907dc1007..43eaa6218c 100644
--- a/packages/dev-utils/src/devApp/SidebarThemeSwitcher.test.tsx
+++ b/packages/dev-utils/src/devApp/SidebarThemeSwitcher.test.tsx
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+
import { AppThemeApi, appThemeApiRef } from '@backstage/core-plugin-api';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { BackstageTheme } from '@backstage/theme';
import userEvent from '@testing-library/user-event';
import React from 'react';
@@ -24,7 +24,6 @@ import { SidebarThemeSwitcher } from './SidebarThemeSwitcher';
describe('SidebarThemeSwitcher', () => {
let appThemeApi: jest.Mocked;
- let apiRegistry: ApiRegistry;
beforeEach(() => {
appThemeApi = {
@@ -51,15 +50,13 @@ describe('SidebarThemeSwitcher', () => {
theme: {} as unknown as BackstageTheme,
},
]);
-
- apiRegistry = ApiRegistry.with(appThemeApiRef, appThemeApi);
});
it('should display current theme', async () => {
const { getByLabelText, getByRole, getByText } = await renderInTestApp(
-
+
- ,
+ ,
);
const button = getByLabelText('Switch Theme');
@@ -76,9 +73,9 @@ describe('SidebarThemeSwitcher', () => {
it('should select different theme', async () => {
const { getByLabelText, getByRole, getByText } = await renderInTestApp(
-
+
- ,
+ ,
);
const button = getByLabelText('Switch Theme');
diff --git a/packages/storybook/.storybook/apis.js b/packages/storybook/.storybook/apis.js
index 41b8433594..ca3914dd0c 100644
--- a/packages/storybook/.storybook/apis.js
+++ b/packages/storybook/.storybook/apis.js
@@ -1,6 +1,5 @@
import {
AlertApiForwarder,
- ApiRegistry,
ErrorAlerter,
ErrorApiForwarder,
GithubAuth,
@@ -27,78 +26,57 @@ import {
configApiRef,
} from '@backstage/core-plugin-api';
-const builder = ApiRegistry.builder();
-
-builder.add(configApiRef, new ConfigReader({}));
-
-const alertApi = builder.add(alertApiRef, new AlertApiForwarder());
-
-builder.add(errorApiRef, new ErrorAlerter(alertApi, new ErrorApiForwarder()));
-
-builder.add(identityApiRef, {
+const configApi = new ConfigReader({});
+const alertApi = new AlertApiForwarder();
+const errorApi = new ErrorAlerter(alertApi, new ErrorApiForwarder());
+const identityApi = {
getUserId: () => 'guest',
getProfile: () => ({ email: 'guest@example.com' }),
getIdToken: () => undefined,
signOut: async () => {},
+};
+const oauthRequestApi = new OAuthRequestManager();
+const googleAuthApi = GoogleAuth.create({
+ apiOrigin: 'http://localhost:7000',
+ basePath: '/auth/',
+ oauthRequestApi,
+});
+const githubAuthApi = GithubAuth.create({
+ apiOrigin: 'http://localhost:7000',
+ basePath: '/auth/',
+ oauthRequestApi,
+});
+const gitlabAuthApi = GitlabAuth.create({
+ apiOrigin: 'http://localhost:7000',
+ basePath: '/auth/',
+ oauthRequestApi,
+});
+const oktaAuthApi = OktaAuth.create({
+ apiOrigin: 'http://localhost:7000',
+ basePath: '/auth/',
+ oauthRequestApi,
+});
+const auth0AuthApi = Auth0Auth.create({
+ apiOrigin: 'http://localhost:7000',
+ basePath: '/auth/',
+ oauthRequestApi,
+});
+const oauth2Api = OAuth2.create({
+ apiOrigin: 'http://localhost:7000',
+ basePath: '/auth/',
+ oauthRequestApi,
});
-const oauthRequestApi = builder.add(
- oauthRequestApiRef,
- new OAuthRequestManager(),
-);
-
-builder.add(
- googleAuthApiRef,
- GoogleAuth.create({
- apiOrigin: 'http://localhost:7000',
- basePath: '/auth/',
- oauthRequestApi,
- }),
-);
-
-builder.add(
- githubAuthApiRef,
- GithubAuth.create({
- apiOrigin: 'http://localhost:7000',
- basePath: '/auth/',
- oauthRequestApi,
- }),
-);
-
-builder.add(
- gitlabAuthApiRef,
- GitlabAuth.create({
- apiOrigin: 'http://localhost:7000',
- basePath: '/auth/',
- oauthRequestApi,
- }),
-);
-
-builder.add(
- oktaAuthApiRef,
- OktaAuth.create({
- apiOrigin: 'http://localhost:7000',
- basePath: '/auth/',
- oauthRequestApi,
- }),
-);
-
-builder.add(
- auth0AuthApiRef,
- Auth0Auth.create({
- apiOrigin: 'http://localhost:7000',
- basePath: '/auth/',
- oauthRequestApi,
- }),
-);
-
-builder.add(
- oauth2ApiRef,
- OAuth2.create({
- apiOrigin: 'http://localhost:7000',
- basePath: '/auth/',
- oauthRequestApi,
- }),
-);
-
-export const apis = builder.build();
+export const apis = [
+ [configApiRef, configApi],
+ [alertApiRef, alertApi],
+ [errorApiRef, errorApi],
+ [identityApiRef, identityApi],
+ [oauthRequestApiRef, oauthRequestApi],
+ [googleAuthApiRef, googleAuthApi],
+ [githubAuthApiRef, githubAuthApi],
+ [gitlabAuthApiRef, gitlabAuthApi],
+ [oktaAuthApiRef, oktaAuthApi],
+ [auth0AuthApiRef, auth0AuthApi],
+ [oauth2ApiRef, oauth2Api],
+];
diff --git a/packages/storybook/.storybook/preview.js b/packages/storybook/.storybook/preview.js
index 6186b82ca5..2b1a4af329 100644
--- a/packages/storybook/.storybook/preview.js
+++ b/packages/storybook/.storybook/preview.js
@@ -6,17 +6,17 @@ import { useDarkMode } from 'storybook-dark-mode';
import { apis } from './apis';
import { Content, AlertDisplay } from '@backstage/core-components';
-import { ApiProvider } from '@backstage/core-app-api';
+import { TestApiProvider } from '@backstage/test-utils';
addDecorator(story => (
-
+
{story()}
-
+
));
addParameters({
diff --git a/packages/test-utils/src/testUtils/TestApiProvider.tsx b/packages/test-utils/src/testUtils/TestApiProvider.tsx
index 4408fc5b36..b1499b0cde 100644
--- a/packages/test-utils/src/testUtils/TestApiProvider.tsx
+++ b/packages/test-utils/src/testUtils/TestApiProvider.tsx
@@ -54,7 +54,7 @@ export class TestApiRegistry implements ApiHolder {
*
* @example
* ```ts
- * const apis = TestApiRegistry.with(
+ * const apis = TestApiRegistry.from(
* [configApiRef, new ConfigReader({})],
* [identityApiRef, { getUserId: () => 'tester' }],
* );
diff --git a/packages/test-utils/src/testUtils/appWrappers.test.tsx b/packages/test-utils/src/testUtils/appWrappers.test.tsx
index 25809912ec..39e5da3df2 100644
--- a/packages/test-utils/src/testUtils/appWrappers.test.tsx
+++ b/packages/test-utils/src/testUtils/appWrappers.test.tsx
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import {
createExternalRouteRef,
createRouteRef,
@@ -29,6 +28,7 @@ import React, { useEffect } from 'react';
import { Route, Routes } from 'react-router';
import { MockErrorApi } from './apis';
import { renderInTestApp, wrapInTestApp } from './appWrappers';
+import { TestApiProvider } from './TestApiProvider';
describe('wrapInTestApp', () => {
it('should provide routing and warn about missing act()', async () => {
@@ -111,9 +111,9 @@ describe('wrapInTestApp', () => {
};
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText('foo')).toBeInTheDocument();
diff --git a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx
index 7b0ffac58e..32a6ec0f77 100644
--- a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx
+++ b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionCard.test.tsx
@@ -16,13 +16,12 @@
import { ApiEntity } from '@backstage/catalog-model';
import { EntityProvider } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { ApiDocsConfig, apiDocsConfigRef } from '../../config';
import { OpenApiDefinitionWidget } from '../OpenApiDefinitionWidget';
import { ApiDefinitionCard } from './ApiDefinitionCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const apiDocsConfig: jest.Mocked = {
@@ -31,10 +30,10 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(apiDocsConfigRef, apiDocsConfig);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/api-docs/src/components/ApiDefinitionCard/ApiTypeTitle.test.tsx b/plugins/api-docs/src/components/ApiDefinitionCard/ApiTypeTitle.test.tsx
index 450e9e57ac..5476857a06 100644
--- a/plugins/api-docs/src/components/ApiDefinitionCard/ApiTypeTitle.test.tsx
+++ b/plugins/api-docs/src/components/ApiDefinitionCard/ApiTypeTitle.test.tsx
@@ -15,11 +15,10 @@
*/
import { ApiEntity } from '@backstage/catalog-model';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import React from 'react';
import { ApiDocsConfig, apiDocsConfigRef } from '../../config';
import { ApiTypeTitle } from './ApiTypeTitle';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const apiDocsConfig: jest.Mocked = {
@@ -28,10 +27,10 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(apiDocsConfigRef, apiDocsConfig);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerPage.test.tsx b/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerPage.test.tsx
index cf40e5160c..3629110d47 100644
--- a/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerPage.test.tsx
+++ b/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerPage.test.tsx
@@ -15,11 +15,7 @@
*/
import { Entity, RELATION_MEMBER_OF } from '@backstage/catalog-model';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ConfigReader } from '@backstage/core-app-api';
import { TableColumn, TableProps } from '@backstage/core-components';
import {
ConfigApi,
@@ -34,7 +30,11 @@ import {
entityRouteRef,
starredEntitiesApiRef,
} from '@backstage/plugin-catalog-react';
-import { MockStorageApi, wrapInTestApp } from '@backstage/test-utils';
+import {
+ MockStorageApi,
+ TestApiProvider,
+ wrapInTestApp,
+} from '@backstage/test-utils';
import DashboardIcon from '@material-ui/icons/Dashboard';
import { render } from '@testing-library/react';
import React from 'react';
@@ -88,8 +88,8 @@ describe('ApiCatalogPage', () => {
const renderWrapped = (children: React.ReactNode) =>
render(
wrapInTestApp(
- {
new DefaultStarredEntitiesApi({ storageApi }),
],
[apiDocsConfigRef, apiDocsConfig],
- ])}
+ ]}
>
{children}
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
diff --git a/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx b/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx
index ac09b717f7..5e7b22524a 100644
--- a/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx
+++ b/plugins/api-docs/src/components/ApisCards/ConsumedApisCard.test.tsx
@@ -21,12 +21,11 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { ApiDocsConfig, apiDocsConfigRef } from '../../config';
import { ConsumedApisCard } from './ConsumedApisCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const apiDocsConfig: jest.Mocked = {
@@ -43,13 +42,15 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi).with(
- apiDocsConfigRef,
- apiDocsConfig,
- );
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/api-docs/src/components/ApisCards/HasApisCard.test.tsx b/plugins/api-docs/src/components/ApisCards/HasApisCard.test.tsx
index ac833251e3..4102bebf0e 100644
--- a/plugins/api-docs/src/components/ApisCards/HasApisCard.test.tsx
+++ b/plugins/api-docs/src/components/ApisCards/HasApisCard.test.tsx
@@ -21,12 +21,11 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { ApiDocsConfig, apiDocsConfigRef } from '../../config';
import { HasApisCard } from './HasApisCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const apiDocsConfig: jest.Mocked = {
@@ -43,13 +42,15 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi).with(
- apiDocsConfigRef,
- apiDocsConfig,
- );
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx b/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx
index f2719d0f4b..b29075aee9 100644
--- a/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx
+++ b/plugins/api-docs/src/components/ApisCards/ProvidedApisCard.test.tsx
@@ -21,12 +21,11 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { ApiDocsConfig, apiDocsConfigRef } from '../../config';
import { ProvidedApisCard } from './ProvidedApisCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const apiDocsConfig: jest.Mocked = {
@@ -43,13 +42,15 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi).with(
- apiDocsConfigRef,
- apiDocsConfig,
- );
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx b/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx
index 274962c346..06022eec69 100644
--- a/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx
+++ b/plugins/api-docs/src/components/ComponentsCards/ConsumingComponentsCard.test.tsx
@@ -21,11 +21,10 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { ConsumingComponentsCard } from './ConsumingComponentsCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const catalogApi: jest.Mocked = {
@@ -39,10 +38,10 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx b/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx
index 879944749a..275338d2f9 100644
--- a/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx
+++ b/plugins/api-docs/src/components/ComponentsCards/ProvidingComponentsCard.test.tsx
@@ -21,11 +21,10 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { ProvidingComponentsCard } from './ProvidingComponentsCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const catalogApi: jest.Mocked = {
@@ -39,10 +38,10 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/badges/src/components/EntityBadgesDialog.test.tsx b/plugins/badges/src/components/EntityBadgesDialog.test.tsx
index 1f5ee94e04..ea44eb20fc 100644
--- a/plugins/badges/src/components/EntityBadgesDialog.test.tsx
+++ b/plugins/badges/src/components/EntityBadgesDialog.test.tsx
@@ -16,12 +16,11 @@
import React from 'react';
import { Entity } from '@backstage/catalog-model';
-import { renderWithEffects } from '@backstage/test-utils';
+import { renderWithEffects, TestApiProvider } from '@backstage/test-utils';
import { BadgesApi, badgesApiRef } from '../api';
import { EntityBadgesDialog } from './EntityBadgesDialog';
import { EntityProvider } from '@backstage/plugin-catalog-react';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { ErrorApi, errorApiRef } from '@backstage/core-plugin-api';
describe('EntityBadgesDialog', () => {
@@ -42,16 +41,16 @@ describe('EntityBadgesDialog', () => {
const mockEntity = { metadata: { name: 'mock' } } as Entity;
const rendered = await renderWithEffects(
-
- ,
+ ,
);
await expect(
diff --git a/plugins/bitrise/src/components/BitriseBuildsTableComponent/BitriseBuildsTableComponent.test.tsx b/plugins/bitrise/src/components/BitriseBuildsTableComponent/BitriseBuildsTableComponent.test.tsx
index a206e28de6..82faa3e39c 100644
--- a/plugins/bitrise/src/components/BitriseBuildsTableComponent/BitriseBuildsTableComponent.test.tsx
+++ b/plugins/bitrise/src/components/BitriseBuildsTableComponent/BitriseBuildsTableComponent.test.tsx
@@ -21,14 +21,11 @@ import { setupServer } from 'msw/node';
import {
setupRequestMockHandlers,
renderInTestApp,
+ TestApiRegistry,
} from '@backstage/test-utils';
import { useBitriseBuilds } from '../../hooks/useBitriseBuilds';
import { BitriseBuildsTable } from './BitriseBuildsTableComponent';
-import {
- ApiProvider,
- ApiRegistry,
- UrlPatternDiscovery,
-} from '@backstage/core-app-api';
+import { ApiProvider, UrlPatternDiscovery } from '@backstage/core-app-api';
jest.mock('../../hooks/useBitriseBuilds', () => ({
useBitriseBuilds: jest.fn(),
@@ -40,10 +37,13 @@ describe('BitriseBuildsFetchComponent', () => {
setupRequestMockHandlers(server);
const mockBaseUrl = 'http://backstage:9191';
const discoveryApi = UrlPatternDiscovery.compile(mockBaseUrl);
- let apis: ApiRegistry;
+ let apis: TestApiRegistry;
beforeEach(() => {
- apis = ApiRegistry.with(bitriseApiRef, new BitriseClientApi(discoveryApi));
+ apis = TestApiRegistry.from([
+ bitriseApiRef,
+ new BitriseClientApi(discoveryApi),
+ ]);
});
it('should display `no records` message if there are no builds', async () => {
diff --git a/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx
index 9fe482a30b..3c167946d4 100644
--- a/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx
+++ b/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx
@@ -14,14 +14,19 @@
* limitations under the License.
*/
import { Entity } from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import { analyticsApiRef } from '@backstage/core-plugin-api';
import {
CatalogApi,
catalogApiRef,
EntityProvider,
} from '@backstage/plugin-catalog-react';
-import { MockAnalyticsApi, renderInTestApp } from '@backstage/test-utils';
+import {
+ MockAnalyticsApi,
+ renderInTestApp,
+ TestApiProvider,
+ TestApiRegistry,
+} from '@backstage/test-utils';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { catalogEntityRouteRef, catalogGraphRouteRef } from '../../routes';
@@ -31,7 +36,7 @@ describe('', () => {
let entity: Entity;
let wrapper: JSX.Element;
let catalog: jest.Mocked;
- let apis: ApiRegistry;
+ let apis: TestApiRegistry;
beforeAll(() => {
Object.defineProperty(window.SVGElement.prototype, 'getBBox', {
@@ -61,7 +66,7 @@ describe('', () => {
refreshEntity: jest.fn(),
getEntityAncestors: jest.fn(),
};
- apis = ApiRegistry.with(catalogApiRef, catalog);
+ apis = TestApiRegistry.from([catalogApiRef, catalog]);
wrapper = (
@@ -123,9 +128,9 @@ describe('', () => {
test('captures analytics event on click', async () => {
const analyticsSpy = new MockAnalyticsApi();
const { findByText } = await renderInTestApp(
-
+
{wrapper}
- ,
+ ,
{
mountedRoutes: {
'/entity/{kind}/{namespace}/{name}': catalogEntityRouteRef,
diff --git a/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx
index b992d0c976..7bd1045fff 100644
--- a/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx
+++ b/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx
@@ -14,10 +14,13 @@
* limitations under the License.
*/
import { RELATION_HAS_PART, RELATION_PART_OF } from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { analyticsApiRef } from '@backstage/core-plugin-api';
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
-import { MockAnalyticsApi, renderInTestApp } from '@backstage/test-utils';
+import {
+ MockAnalyticsApi,
+ renderInTestApp,
+ TestApiProvider,
+} from '@backstage/test-utils';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { catalogEntityRouteRef } from '../../routes';
@@ -90,10 +93,9 @@ describe('', () => {
refreshEntity: jest.fn(),
getEntityAncestors: jest.fn(),
};
- const apis = ApiRegistry.with(catalogApiRef, catalog);
wrapper = (
-
+
', () => {
selectedKinds: ['b'],
}}
/>
-
+
);
});
@@ -172,9 +174,9 @@ describe('', () => {
test('should capture analytics event when selecting other entity', async () => {
const analyticsSpy = new MockAnalyticsApi();
const { getByText, findAllByTestId } = await renderInTestApp(
-
+
{wrapper}
- ,
+ ,
{
mountedRoutes: {
'/entity/{kind}/{namespace}/{name}': catalogEntityRouteRef,
@@ -195,9 +197,9 @@ describe('', () => {
test('should capture analytics event when navigating to entity', async () => {
const analyticsSpy = new MockAnalyticsApi();
const { getByText, findAllByTestId } = await renderInTestApp(
-
+
{wrapper}
- ,
+ ,
{
mountedRoutes: {
'/entity/{kind}/{namespace}/{name}': catalogEntityRouteRef,
diff --git a/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx b/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx
index 2d6c5cc93d..be0c4dc5e5 100644
--- a/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx
+++ b/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx
@@ -21,9 +21,8 @@ import {
RELATION_PART_OF,
stringifyEntityRef,
} from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import userEvent from '@testing-library/user-event';
import React, { FunctionComponent } from 'react';
import { EntityRelationsGraph } from './EntityRelationsGraph';
@@ -158,10 +157,11 @@ describe('', () => {
refreshEntity: jest.fn(),
getEntityAncestors: jest.fn(),
};
- const apis = ApiRegistry.with(catalogApiRef, catalog);
Wrapper = ({ children }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/catalog-import/src/components/DefaultImportPage/DefaultImportPage.test.tsx b/plugins/catalog-import/src/components/DefaultImportPage/DefaultImportPage.test.tsx
index 69ae38207d..784cbfbe9e 100644
--- a/plugins/catalog-import/src/components/DefaultImportPage/DefaultImportPage.test.tsx
+++ b/plugins/catalog-import/src/components/DefaultImportPage/DefaultImportPage.test.tsx
@@ -15,14 +15,10 @@
*/
import { CatalogClient } from '@backstage/catalog-client';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import { configApiRef } from '@backstage/core-plugin-api';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import React from 'react';
import { catalogImportApiRef, CatalogImportClient } from '../../api';
import { DefaultImportPage } from './DefaultImportPage';
@@ -43,15 +39,13 @@ describe('', () => {
},
};
- let apis: ApiRegistry;
+ let apis: TestApiRegistry;
beforeEach(() => {
- apis = ApiRegistry.with(
- configApiRef,
- new ConfigReader({ integrations: {} }),
- )
- .with(catalogApiRef, new CatalogClient({ discoveryApi: {} as any }))
- .with(
+ apis = TestApiRegistry.from(
+ [configApiRef, new ConfigReader({ integrations: {} })],
+ [catalogApiRef, new CatalogClient({ discoveryApi: {} as any })],
+ [
catalogImportApiRef,
new CatalogImportClient({
discoveryApi: {} as any,
@@ -63,7 +57,8 @@ describe('', () => {
catalogApi: {} as any,
configApi: {} as any,
}),
- );
+ ],
+ );
});
it('renders without exploding', async () => {
diff --git a/plugins/catalog-import/src/components/ImportInfoCard/ImportInfoCard.test.tsx b/plugins/catalog-import/src/components/ImportInfoCard/ImportInfoCard.test.tsx
index 4e0c3694cd..9a27532c57 100644
--- a/plugins/catalog-import/src/components/ImportInfoCard/ImportInfoCard.test.tsx
+++ b/plugins/catalog-import/src/components/ImportInfoCard/ImportInfoCard.test.tsx
@@ -14,19 +14,19 @@
* limitations under the License.
*/
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import { configApiRef } from '@backstage/core-plugin-api';
-import { renderInTestApp } from '@backstage/test-utils';
+import {
+ renderInTestApp,
+ TestApiProvider,
+ TestApiRegistry,
+} from '@backstage/test-utils';
import React from 'react';
import { CatalogImportApi, catalogImportApiRef } from '../../api';
import { ImportInfoCard } from './ImportInfoCard';
describe('', () => {
- let apis: ApiRegistry;
+ let apis: TestApiRegistry;
let catalogImportApi: jest.Mocked;
beforeEach(() => {
@@ -35,26 +35,29 @@ describe('', () => {
submitPullRequest: jest.fn(),
};
- apis = ApiRegistry.with(
- configApiRef,
- new ConfigReader({
- integrations: {
- github: [{ token: 'my-token' }],
- },
- }),
- ).with(catalogImportApiRef, catalogImportApi);
+ apis = TestApiRegistry.from(
+ [
+ configApiRef,
+ new ConfigReader({
+ integrations: {
+ github: [{ token: 'my-token' }],
+ },
+ }),
+ ],
+ [catalogImportApiRef, catalogImportApi],
+ );
});
it('renders without exploding', async () => {
- apis = ApiRegistry.with(
- configApiRef,
- new ConfigReader({ integrations: {} }),
- ).with(catalogImportApiRef, catalogImportApi);
-
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
);
expect(getByText('Register an existing component')).toBeInTheDocument();
diff --git a/plugins/catalog-import/src/components/ImportPage/ImportPage.test.tsx b/plugins/catalog-import/src/components/ImportPage/ImportPage.test.tsx
index 92a6077792..1778af73dc 100644
--- a/plugins/catalog-import/src/components/ImportPage/ImportPage.test.tsx
+++ b/plugins/catalog-import/src/components/ImportPage/ImportPage.test.tsx
@@ -15,14 +15,10 @@
*/
import { CatalogClient } from '@backstage/catalog-client';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import { configApiRef } from '@backstage/core-plugin-api';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import React from 'react';
import { useOutlet } from 'react-router';
import { catalogImportApiRef, CatalogImportClient } from '../../api';
@@ -49,15 +45,13 @@ describe('', () => {
},
};
- let apis: ApiRegistry;
+ let apis: TestApiRegistry;
beforeEach(() => {
- apis = ApiRegistry.with(
- configApiRef,
- new ConfigReader({ integrations: {} }),
- )
- .with(catalogApiRef, new CatalogClient({ discoveryApi: {} as any }))
- .with(
+ apis = TestApiRegistry.from(
+ [configApiRef, new ConfigReader({ integrations: {} })],
+ [catalogApiRef, new CatalogClient({ discoveryApi: {} as any })],
+ [
catalogImportApiRef,
new CatalogImportClient({
discoveryApi: {} as any,
@@ -67,7 +61,8 @@ describe('', () => {
catalogApi: {} as any,
configApi: new ConfigReader({}),
}),
- );
+ ],
+ );
});
afterEach(() => jest.resetAllMocks());
diff --git a/plugins/catalog-import/src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.test.tsx b/plugins/catalog-import/src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.test.tsx
index 4a72a653ea..8d28fb8604 100644
--- a/plugins/catalog-import/src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.test.tsx
+++ b/plugins/catalog-import/src/components/StepInitAnalyzeUrl/StepInitAnalyzeUrl.test.tsx
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { errorApiRef } from '@backstage/core-plugin-api';
+import { TestApiProvider } from '@backstage/test-utils';
import { act, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
@@ -34,14 +34,14 @@ describe('', () => {
};
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
-
{children}
-
+
);
const location = {
diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx
index 0a55d6337b..3b6f353155 100644
--- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx
+++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { errorApiRef } from '@backstage/core-plugin-api';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
+import { TestApiProvider } from '@backstage/test-utils';
import { TextField } from '@material-ui/core';
import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
@@ -54,13 +54,15 @@ describe('', () => {
};
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
-
{children}
-
+
);
const onPrepareFn = jest.fn();
diff --git a/plugins/catalog-react/src/components/EntityTypePicker/EntityTypePicker.test.tsx b/plugins/catalog-react/src/components/EntityTypePicker/EntityTypePicker.test.tsx
index 8eba11aeca..f6e9d296df 100644
--- a/plugins/catalog-react/src/components/EntityTypePicker/EntityTypePicker.test.tsx
+++ b/plugins/catalog-react/src/components/EntityTypePicker/EntityTypePicker.test.tsx
@@ -17,16 +17,15 @@
import React from 'react';
import { fireEvent, waitFor } from '@testing-library/react';
import { capitalize } from 'lodash';
-import { CatalogApi } from '@backstage/catalog-client';
import { Entity } from '@backstage/catalog-model';
import { EntityTypePicker } from './EntityTypePicker';
import { MockEntityListContextProvider } from '../../testUtils/providers';
import { catalogApiRef } from '../../api';
import { EntityKindFilter, EntityTypeFilter } from '../../filters';
-import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
-import { renderWithEffects } from '@backstage/test-utils';
+import { alertApiRef } from '@backstage/core-plugin-api';
+import { ApiProvider } from '@backstage/core-app-api';
+import { renderWithEffects, TestApiRegistry } from '@backstage/test-utils';
const entities: Entity[] = [
{
@@ -61,11 +60,20 @@ const entities: Entity[] = [
},
];
-const apis = ApiRegistry.with(catalogApiRef, {
- getEntities: jest.fn().mockResolvedValue({ items: entities }),
-} as unknown as CatalogApi).with(alertApiRef, {
- post: jest.fn(),
-} as unknown as AlertApi);
+const apis = TestApiRegistry.from(
+ [
+ catalogApiRef,
+ {
+ getEntities: jest.fn().mockResolvedValue({ items: entities }),
+ },
+ ],
+ [
+ alertApiRef,
+ {
+ post: jest.fn(),
+ },
+ ],
+);
describe('', () => {
it('renders available entity types', async () => {
diff --git a/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx b/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx
index eccf824c2e..2b29bba4fd 100644
--- a/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx
+++ b/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx
@@ -24,7 +24,7 @@ import { CatalogClient } from '@backstage/catalog-client';
import { catalogApiRef } from '../../api';
import { entityRouteRef } from '../../routes';
import { screen, waitFor } from '@testing-library/react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import * as state from './useUnregisterEntityDialogState';
import {
@@ -32,7 +32,6 @@ import {
alertApiRef,
DiscoveryApi,
} from '@backstage/core-plugin-api';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('UnregisterEntityDialog', () => {
const discoveryApi: DiscoveryApi = {
@@ -49,11 +48,6 @@ describe('UnregisterEntityDialog', () => {
},
};
- const apis = ApiRegistry.with(
- catalogApiRef,
- new CatalogClient({ discoveryApi }),
- ).with(alertApiRef, alertApi);
-
const entity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
@@ -68,7 +62,14 @@ describe('UnregisterEntityDialog', () => {
};
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
const stateSpy = jest.spyOn(state, 'useUnregisterEntityDialogState');
diff --git a/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.test.tsx b/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.test.tsx
index 8b4f436aed..8d6083f111 100644
--- a/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.test.tsx
+++ b/plugins/catalog-react/src/components/UnregisterEntityDialog/useUnregisterEntityDialogState.test.tsx
@@ -31,7 +31,7 @@ import {
UseUnregisterEntityDialogState,
useUnregisterEntityDialogState,
} from './useUnregisterEntityDialogState';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { TestApiProvider } from '@backstage/test-utils';
function defer(): { promise: Promise; resolve: (value: T) => void } {
let resolve: (value: T) => void = () => {};
@@ -51,9 +51,9 @@ describe('useUnregisterEntityDialogState', () => {
const catalogApi = catalogApiMock as Partial as CatalogApi;
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
-
+
{children}
-
+
);
let entity: Entity;
diff --git a/plugins/catalog-react/src/components/UserListPicker/UserListPicker.test.tsx b/plugins/catalog-react/src/components/UserListPicker/UserListPicker.test.tsx
index 4662e58dd2..f6a4c59374 100644
--- a/plugins/catalog-react/src/components/UserListPicker/UserListPicker.test.tsx
+++ b/plugins/catalog-react/src/components/UserListPicker/UserListPicker.test.tsx
@@ -26,9 +26,9 @@ import { MockEntityListContextProvider } from '../../testUtils/providers';
import { EntityTagFilter, UserListFilter } from '../../filters';
import { CatalogApi } from '@backstage/catalog-client';
import { catalogApiRef } from '../../api';
-import { MockStorageApi } from '@backstage/test-utils';
+import { MockStorageApi, TestApiRegistry } from '@backstage/test-utils';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import {
ConfigApi,
configApiRef,
@@ -62,12 +62,12 @@ const mockIdentityApi = {
getIdToken: async () => undefined,
} as Partial;
-const apis = ApiRegistry.from([
+const apis = TestApiRegistry.from(
[configApiRef, mockConfigApi],
[catalogApiRef, mockCatalogApi],
[identityApiRef, mockIdentityApi],
[storageApiRef, MockStorageApi.create()],
-]);
+);
const mockIsOwnedEntity = (entity: Entity) =>
entity.metadata.name === 'component-1';
diff --git a/plugins/catalog-react/src/hooks/useEntityKinds.test.tsx b/plugins/catalog-react/src/hooks/useEntityKinds.test.tsx
index d801e508a6..cdcac8c194 100644
--- a/plugins/catalog-react/src/hooks/useEntityKinds.test.tsx
+++ b/plugins/catalog-react/src/hooks/useEntityKinds.test.tsx
@@ -15,12 +15,12 @@
*/
import React, { PropsWithChildren } from 'react';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { CatalogApi } from '@backstage/catalog-client';
import { Entity } from '@backstage/catalog-model';
import { catalogApiRef } from '../api';
import { renderHook } from '@testing-library/react-hooks';
import { useEntityKinds } from './useEntityKinds';
+import { TestApiProvider } from '@backstage/test-utils';
const entities: Entity[] = [
{
@@ -59,9 +59,9 @@ const mockCatalogApi: Partial = {
const wrapper = ({ children }: PropsWithChildren<{}>) => {
return (
-
+
{children}
-
+
);
};
diff --git a/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx b/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx
index e448ee73f1..b96f63304a 100644
--- a/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx
+++ b/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx
@@ -16,7 +16,6 @@
import { CatalogApi } from '@backstage/catalog-client';
import { Entity } from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import {
ConfigApi,
configApiRef,
@@ -24,7 +23,7 @@ import {
identityApiRef,
storageApiRef,
} from '@backstage/core-plugin-api';
-import { MockStorageApi } from '@backstage/test-utils';
+import { MockStorageApi, TestApiProvider } from '@backstage/test-utils';
import { act, renderHook } from '@testing-library/react-hooks';
import qs from 'qs';
import React, { PropsWithChildren } from 'react';
@@ -76,16 +75,6 @@ const mockCatalogApi: Partial = {
getEntities: jest.fn().mockImplementation(async () => ({ items: entities })),
getEntityByName: async () => undefined,
};
-const apis = ApiRegistry.from([
- [configApiRef, mockConfigApi],
- [catalogApiRef, mockCatalogApi],
- [identityApiRef, mockIdentityApi],
- [storageApiRef, MockStorageApi.create()],
- [
- starredEntitiesApiRef,
- new DefaultStarredEntitiesApi({ storageApi: MockStorageApi.create() }),
- ],
-]);
const wrapper = ({
userFilter,
@@ -94,13 +83,26 @@ const wrapper = ({
userFilter?: UserListFilterKind;
}>) => {
return (
-
+
{children}
-
+
);
};
diff --git a/plugins/catalog-react/src/hooks/useEntityOwnership.test.tsx b/plugins/catalog-react/src/hooks/useEntityOwnership.test.tsx
index 4edad98c12..f01c13839d 100644
--- a/plugins/catalog-react/src/hooks/useEntityOwnership.test.tsx
+++ b/plugins/catalog-react/src/hooks/useEntityOwnership.test.tsx
@@ -21,8 +21,8 @@ import {
RELATION_OWNED_BY,
UserEntity,
} from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { IdentityApi, identityApiRef } from '@backstage/core-plugin-api';
+import { TestApiProvider } from '@backstage/test-utils';
import { renderHook } from '@testing-library/react-hooks';
import React from 'react';
import { catalogApiRef } from '../api';
@@ -50,14 +50,14 @@ describe('useEntityOwnership', () => {
const catalogApi = mockCatalogApi as unknown as CatalogApi;
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
-
{children}
-
+
);
const ownedEntity: ComponentEntity = {
diff --git a/plugins/catalog-react/src/hooks/useStarredEntities.test.tsx b/plugins/catalog-react/src/hooks/useStarredEntities.test.tsx
index 4f41ef090f..aef876a1b2 100644
--- a/plugins/catalog-react/src/hooks/useStarredEntities.test.tsx
+++ b/plugins/catalog-react/src/hooks/useStarredEntities.test.tsx
@@ -15,9 +15,8 @@
*/
import { Entity } from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { StorageApi } from '@backstage/core-plugin-api';
-import { MockStorageApi } from '@backstage/test-utils';
+import { MockStorageApi, TestApiProvider } from '@backstage/test-utils';
import { act, renderHook } from '@testing-library/react-hooks';
import React, { PropsWithChildren } from 'react';
import { DefaultStarredEntitiesApi, starredEntitiesApiRef } from '../apis';
@@ -47,14 +46,16 @@ describe('useStarredEntities', () => {
beforeEach(() => {
mockStorage = MockStorageApi.create();
wrapper = ({ children }: PropsWithChildren<{}>) => (
-
{children}
-
+
);
});
diff --git a/plugins/catalog-react/src/hooks/useStarredEntity.test.tsx b/plugins/catalog-react/src/hooks/useStarredEntity.test.tsx
index b8577aec0c..8ffc891092 100644
--- a/plugins/catalog-react/src/hooks/useStarredEntity.test.tsx
+++ b/plugins/catalog-react/src/hooks/useStarredEntity.test.tsx
@@ -15,7 +15,7 @@
*/
import { Entity, EntityName } from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { TestApiProvider } from '@backstage/test-utils';
import { renderHook } from '@testing-library/react-hooks';
import React, { PropsWithChildren } from 'react';
import Observable from 'zen-observable';
@@ -31,11 +31,9 @@ describe('useStarredEntity', () => {
beforeEach(() => {
wrapper = ({ children }: PropsWithChildren<{}>) => (
-
+
{children}
-
+
);
});
diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx
index d6f13ed22d..afbed3bdc7 100644
--- a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx
+++ b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx
@@ -15,11 +15,7 @@
*/
import { RELATION_OWNED_BY } from '@backstage/catalog-model';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ConfigReader } from '@backstage/core-app-api';
import {
ScmIntegrationsApi,
scmIntegrationsApiRef,
@@ -30,7 +26,7 @@ import {
CatalogApi,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { viewTechDocRouteRef } from '../../routes';
@@ -71,21 +67,25 @@ describe('', () => {
},
],
};
- const apis = ApiRegistry.with(
- scmIntegrationsApiRef,
- ScmIntegrationsApi.fromConfig(
- new ConfigReader({
- integrations: {},
- }),
- ),
- ).with(catalogApiRef, catalogApi);
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
@@ -116,28 +116,32 @@ describe('', () => {
lifecycle: 'production',
},
};
- const apis = ApiRegistry.with(
- scmIntegrationsApiRef,
- ScmIntegrationsApi.fromConfig(
- new ConfigReader({
- integrations: {
- github: [
- {
- host: 'github.com',
- token: '...',
- },
- ],
- },
- }),
- ),
- ).with(catalogApiRef, catalogApi);
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
@@ -167,28 +171,32 @@ describe('', () => {
lifecycle: 'production',
},
};
- const apis = ApiRegistry.with(
- scmIntegrationsApiRef,
- ScmIntegrationsApi.fromConfig(
- new ConfigReader({
- integrations: {
- github: [
- {
- host: 'github.com',
- token: '...',
- },
- ],
- },
- }),
- ),
- ).with(catalogApiRef, catalogApi);
const { getByTitle } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
@@ -216,17 +224,21 @@ describe('', () => {
lifecycle: 'production',
},
};
- const apis = ApiRegistry.with(
- scmIntegrationsApiRef,
- ScmIntegrationsApi.fromConfig(new ConfigReader({})),
- ).with(catalogApiRef, catalogApi);
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
@@ -253,17 +265,21 @@ describe('', () => {
lifecycle: 'production',
},
};
- const apis = ApiRegistry.with(
- scmIntegrationsApiRef,
- ScmIntegrationsApi.fromConfig(new ConfigReader({})),
- ).with(catalogApiRef, catalogApi);
const { getByTitle } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
@@ -295,17 +311,21 @@ describe('', () => {
lifecycle: 'production',
},
};
- const apis = ApiRegistry.with(
- scmIntegrationsApiRef,
- ScmIntegrationsApi.fromConfig(new ConfigReader({})),
- ).with(catalogApiRef, catalogApi);
const { queryByTitle } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
@@ -332,28 +352,32 @@ describe('', () => {
lifecycle: 'production',
},
};
- const apis = ApiRegistry.with(
- scmIntegrationsApiRef,
- ScmIntegrationsApi.fromConfig(
- new ConfigReader({
- integrations: {
- github: [
- {
- host: 'github.com',
- token: '...',
- },
- ],
- },
- }),
- ),
- ).with(catalogApiRef, catalogApi);
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/docs/:namespace/:kind/:name': viewTechDocRouteRef,
@@ -381,28 +405,32 @@ describe('', () => {
lifecycle: 'production',
},
};
- const apis = ApiRegistry.with(
- scmIntegrationsApiRef,
- ScmIntegrationsApi.fromConfig(
- new ConfigReader({
- integrations: {
- github: [
- {
- host: 'github.com',
- token: '...',
- },
- ],
- },
- }),
- ),
- ).with(catalogApiRef, catalogApi);
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
@@ -429,28 +457,32 @@ describe('', () => {
lifecycle: 'production',
},
};
- const apis = ApiRegistry.with(
- scmIntegrationsApiRef,
- ScmIntegrationsApi.fromConfig(
- new ConfigReader({
- integrations: {
- github: [
- {
- host: 'github.com',
- token: '...',
- },
- ],
- },
- }),
- ),
- ).with(catalogApiRef, catalogApi);
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
diff --git a/plugins/catalog/src/components/CatalogKindHeader/CatalogKindHeader.test.tsx b/plugins/catalog/src/components/CatalogKindHeader/CatalogKindHeader.test.tsx
index 2730665fb6..b320d6d220 100644
--- a/plugins/catalog/src/components/CatalogKindHeader/CatalogKindHeader.test.tsx
+++ b/plugins/catalog/src/components/CatalogKindHeader/CatalogKindHeader.test.tsx
@@ -18,13 +18,12 @@ import React from 'react';
import { fireEvent } from '@testing-library/react';
import { Entity } from '@backstage/catalog-model';
import {
- CatalogApi,
catalogApiRef,
EntityKindFilter,
MockEntityListContextProvider,
} from '@backstage/plugin-catalog-react';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
-import { renderWithEffects } from '@backstage/test-utils';
+import { ApiProvider } from '@backstage/core-app-api';
+import { renderWithEffects, TestApiRegistry } from '@backstage/test-utils';
import { CatalogKindHeader } from './CatalogKindHeader';
const entities: Entity[] = [
@@ -58,9 +57,12 @@ const entities: Entity[] = [
},
];
-const apis = ApiRegistry.with(catalogApiRef, {
- getEntities: jest.fn().mockResolvedValue({ items: entities }),
-} as Partial);
+const apis = TestApiRegistry.from([
+ catalogApiRef,
+ {
+ getEntities: jest.fn().mockResolvedValue({ items: entities }),
+ },
+]);
describe('', () => {
it('renders available kinds', async () => {
diff --git a/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx b/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx
index 6b33b33b08..0a46580c12 100644
--- a/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx
+++ b/plugins/catalog/src/components/CatalogPage/CatalogPage.test.tsx
@@ -20,7 +20,6 @@ import {
RELATION_MEMBER_OF,
RELATION_OWNED_BY,
} from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { TableColumn, TableProps } from '@backstage/core-components';
import {
IdentityApi,
@@ -38,6 +37,7 @@ import {
mockBreakpoint,
MockStorageApi,
renderWithEffects,
+ TestApiProvider,
wrapInTestApp,
} from '@backstage/test-utils';
import DashboardIcon from '@material-ui/icons/Dashboard';
@@ -129,8 +129,8 @@ describe('CatalogPage', () => {
const renderWrapped = (children: React.ReactNode) =>
renderWithEffects(
wrapInTestApp(
- {
starredEntitiesApiRef,
new DefaultStarredEntitiesApi({ storageApi }),
],
- ])}
+ ]}
>
{children}
- ,
+ ,
{
mountedRoutes: {
'/create': createComponentRouteRef,
diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx
index 822913a385..4c6adcf400 100644
--- a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx
+++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx
@@ -19,7 +19,7 @@ import {
Entity,
VIEW_URL_ANNOTATION,
} from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import {
entityRouteRef,
DefaultStarredEntitiesApi,
@@ -27,7 +27,11 @@ import {
starredEntitiesApiRef,
UserListFilter,
} from '@backstage/plugin-catalog-react';
-import { MockStorageApi, renderInTestApp } from '@backstage/test-utils';
+import {
+ MockStorageApi,
+ renderInTestApp,
+ TestApiRegistry,
+} from '@backstage/test-utils';
import { act, fireEvent } from '@testing-library/react';
import * as React from 'react';
import { CatalogTable } from './CatalogTable';
@@ -51,10 +55,10 @@ const entities: Entity[] = [
];
describe('CatalogTable component', () => {
- const mockApis = ApiRegistry.with(
+ const mockApis = TestApiRegistry.from([
starredEntitiesApiRef,
new DefaultStarredEntitiesApi({ storageApi: MockStorageApi.create() }),
- );
+ ]);
beforeEach(() => {
window.open = jest.fn();
diff --git a/plugins/catalog/src/components/DependencyOfComponentsCard/DependencyOfComponentsCard.test.tsx b/plugins/catalog/src/components/DependencyOfComponentsCard/DependencyOfComponentsCard.test.tsx
index 7dd823a8f0..e43104b67d 100644
--- a/plugins/catalog/src/components/DependencyOfComponentsCard/DependencyOfComponentsCard.test.tsx
+++ b/plugins/catalog/src/components/DependencyOfComponentsCard/DependencyOfComponentsCard.test.tsx
@@ -21,28 +21,20 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { DependencyOfComponentsCard } from './DependencyOfComponentsCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
- const catalogApi: jest.Mocked = {
- getLocationById: jest.fn(),
- getEntityByName: jest.fn(),
- getEntities: jest.fn(),
- addLocation: jest.fn(),
- getLocationByEntity: jest.fn(),
- removeEntityByUid: jest.fn(),
- } as any;
+ const getEntities: jest.MockedFunction = jest.fn();
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
@@ -97,7 +89,7 @@ describe('', () => {
},
],
};
- catalogApi.getEntities.mockResolvedValue({
+ getEntities.mockResolvedValue({
items: [
{
apiVersion: 'v1',
diff --git a/plugins/catalog/src/components/DependsOnComponentsCard/DependsOnComponentsCard.test.tsx b/plugins/catalog/src/components/DependsOnComponentsCard/DependsOnComponentsCard.test.tsx
index b9fd75def9..b654136d18 100644
--- a/plugins/catalog/src/components/DependsOnComponentsCard/DependsOnComponentsCard.test.tsx
+++ b/plugins/catalog/src/components/DependsOnComponentsCard/DependsOnComponentsCard.test.tsx
@@ -21,28 +21,20 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { DependsOnComponentsCard } from './DependsOnComponentsCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
- const catalogApi: jest.Mocked = {
- getLocationById: jest.fn(),
- getEntityByName: jest.fn(),
- getEntities: jest.fn(),
- addLocation: jest.fn(),
- getLocationByEntity: jest.fn(),
- removeEntityByUid: jest.fn(),
- } as any;
+ const getEntities: jest.MockedFunction = jest.fn();
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
@@ -97,7 +89,7 @@ describe('', () => {
},
],
};
- catalogApi.getEntities.mockResolvedValue({
+ getEntities.mockResolvedValue({
items: [
{
apiVersion: 'v1',
diff --git a/plugins/catalog/src/components/DependsOnResourcesCard/DependsOnResourcesCard.test.tsx b/plugins/catalog/src/components/DependsOnResourcesCard/DependsOnResourcesCard.test.tsx
index bee759254c..40685705aa 100644
--- a/plugins/catalog/src/components/DependsOnResourcesCard/DependsOnResourcesCard.test.tsx
+++ b/plugins/catalog/src/components/DependsOnResourcesCard/DependsOnResourcesCard.test.tsx
@@ -21,28 +21,20 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { DependsOnResourcesCard } from './DependsOnResourcesCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
- const catalogApi: jest.Mocked = {
- getLocationById: jest.fn(),
- getEntityByName: jest.fn(),
- getEntities: jest.fn(),
- addLocation: jest.fn(),
- getLocationByEntity: jest.fn(),
- removeEntityByUid: jest.fn(),
- } as any;
+ const getEntities: jest.MockedFunction = jest.fn();
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
@@ -97,7 +89,7 @@ describe('', () => {
},
],
};
- catalogApi.getEntities.mockResolvedValue({
+ getEntities.mockResolvedValue({
items: [
{
apiVersion: 'v1',
diff --git a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx
index 2216070984..3f3fc804e1 100644
--- a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx
+++ b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx
@@ -16,7 +16,7 @@
import { CatalogApi } from '@backstage/catalog-client';
import { Entity } from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
import {
AsyncEntityProvider,
@@ -26,7 +26,11 @@ import {
entityRouteRef,
starredEntitiesApiRef,
} from '@backstage/plugin-catalog-react';
-import { MockStorageApi, renderInTestApp } from '@backstage/test-utils';
+import {
+ MockStorageApi,
+ renderInTestApp,
+ TestApiRegistry,
+} from '@backstage/test-utils';
import { fireEvent } from '@testing-library/react';
import React from 'react';
import { act } from 'react-dom/test-utils';
@@ -40,12 +44,14 @@ const mockEntity = {
},
} as Entity;
-const mockApis = ApiRegistry.with(catalogApiRef, {} as CatalogApi)
- .with(alertApiRef, {} as AlertApi)
- .with(
+const mockApis = TestApiRegistry.from(
+ [catalogApiRef, {} as CatalogApi],
+ [alertApiRef, {} as AlertApi],
+ [
starredEntitiesApiRef,
new DefaultStarredEntitiesApi({ storageApi: MockStorageApi.create() }),
- );
+ ],
+);
describe('EntityLayout', () => {
it('renders simplest case', async () => {
diff --git a/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx b/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx
index 862ef9504b..f58e6b9b66 100644
--- a/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx
+++ b/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx
@@ -20,10 +20,9 @@ import { ORIGIN_LOCATION_ANNOTATION } from '@backstage/catalog-model';
import { CatalogApi } from '@backstage/catalog-client';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
import { screen, waitFor } from '@testing-library/react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('DeleteEntityDialog', () => {
const alertApi: jest.Mocked = {
@@ -34,10 +33,6 @@ describe('DeleteEntityDialog', () => {
const catalogClient: jest.Mocked = {
removeEntityByUid: jest.fn(),
} as any;
- const apis = ApiRegistry.with(catalogApiRef, catalogClient).with(
- alertApiRef,
- alertApi,
- );
const entity = {
apiVersion: 'backstage.io/v1alpha1',
@@ -54,7 +49,14 @@ describe('DeleteEntityDialog', () => {
};
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
afterEach(() => {
diff --git a/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.test.tsx b/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.test.tsx
index 9e26184a8d..a8aac405fe 100644
--- a/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.test.tsx
+++ b/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.test.tsx
@@ -15,23 +15,16 @@
*/
import {
- CatalogApi,
catalogApiRef,
catalogRouteRef,
EntityProvider,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import React from 'react';
import { EntityOrphanWarning } from './EntityOrphanWarning';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
- const catalogClient: jest.Mocked = {
- removeEntityByUid: jest.fn(),
- } as any;
- const apis = ApiRegistry.with(catalogApiRef, catalogClient);
-
it('renders EntityOrphanWarning if the entity is orphan', async () => {
const entity = {
apiVersion: 'v1',
@@ -50,11 +43,20 @@ describe('', () => {
};
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/create': catalogRouteRef,
diff --git a/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx b/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx
index c406d0ed3c..fcc4475f6a 100644
--- a/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx
+++ b/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx
@@ -21,17 +21,17 @@ import {
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import React from 'react';
import { EntityProcessingErrorsPanel } from './EntityProcessingErrorsPanel';
import { Entity, getEntityName } from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
describe('', () => {
- const catalogClient: jest.Mocked = {
- getEntityAncestors: jest.fn(),
- } as any;
- const apis = ApiRegistry.with(catalogApiRef, catalogClient);
+ const getEntityAncestors: jest.MockedFunction<
+ CatalogApi['getEntityAncestors']
+ > = jest.fn();
+ const apis = TestApiRegistry.from([catalogApiRef, { getEntityAncestors }]);
it('renders EntityProcessErrors if the entity has errors', async () => {
const entity: Entity = {
@@ -97,7 +97,7 @@ describe('', () => {
},
};
- catalogClient.getEntityAncestors.mockResolvedValue({
+ getEntityAncestors.mockResolvedValue({
root: getEntityName(entity),
items: [{ entity, parents: [] }],
});
@@ -198,7 +198,7 @@ describe('', () => {
],
},
};
- catalogClient.getEntityAncestors.mockResolvedValue({
+ getEntityAncestors.mockResolvedValue({
root: getEntityName(entity),
items: [
{ entity, parents: [getEntityName(parent)] },
diff --git a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx
index 7f8bf35b74..8768e9728e 100644
--- a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx
+++ b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx
@@ -21,17 +21,14 @@ import React from 'react';
import { isKind } from './conditions';
import { EntitySwitch } from './EntitySwitch';
import { featureFlagsApiRef } from '@backstage/core-plugin-api';
-import {
- LocalStorageFeatureFlags,
- ApiProvider,
- ApiRegistry,
-} from '@backstage/core-app-api';
+import { LocalStorageFeatureFlags } from '@backstage/core-app-api';
+import { TestApiProvider } from '@backstage/test-utils';
const mockFeatureFlagsApi = new LocalStorageFeatureFlags();
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
-
+
{children}
-
+
);
describe('EntitySwitch', () => {
diff --git a/plugins/catalog/src/components/HasComponentsCard/HasComponentsCard.test.tsx b/plugins/catalog/src/components/HasComponentsCard/HasComponentsCard.test.tsx
index d484ab026a..45f7561d6e 100644
--- a/plugins/catalog/src/components/HasComponentsCard/HasComponentsCard.test.tsx
+++ b/plugins/catalog/src/components/HasComponentsCard/HasComponentsCard.test.tsx
@@ -21,28 +21,20 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { HasComponentsCard } from './HasComponentsCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
- const catalogApi: jest.Mocked = {
- getLocationById: jest.fn(),
- getEntityByName: jest.fn(),
- getEntities: jest.fn(),
- addLocation: jest.fn(),
- getLocationByEntity: jest.fn(),
- removeEntityByUid: jest.fn(),
- } as any;
+ const getEntities: jest.MockedFunction = jest.fn();
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
@@ -97,7 +89,7 @@ describe('', () => {
},
],
};
- catalogApi.getEntities.mockResolvedValue({
+ getEntities.mockResolvedValue({
items: [
{
apiVersion: 'v1',
diff --git a/plugins/catalog/src/components/HasResourcesCard/HasResourcesCard.test.tsx b/plugins/catalog/src/components/HasResourcesCard/HasResourcesCard.test.tsx
index 45604ceb56..a01922d988 100644
--- a/plugins/catalog/src/components/HasResourcesCard/HasResourcesCard.test.tsx
+++ b/plugins/catalog/src/components/HasResourcesCard/HasResourcesCard.test.tsx
@@ -21,28 +21,20 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { HasResourcesCard } from './HasResourcesCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
- const catalogApi: jest.Mocked = {
- getLocationById: jest.fn(),
- getEntityByName: jest.fn(),
- getEntities: jest.fn(),
- addLocation: jest.fn(),
- getLocationByEntity: jest.fn(),
- removeEntityByUid: jest.fn(),
- } as any;
+ const getEntities: jest.MockedFunction = jest.fn();
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
@@ -92,7 +84,7 @@ describe('', () => {
},
],
};
- catalogApi.getEntities.mockResolvedValue({
+ getEntities.mockResolvedValue({
items: [
{
apiVersion: 'v1',
diff --git a/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx b/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx
index 431e757656..e517bd38ae 100644
--- a/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx
+++ b/plugins/catalog/src/components/HasSubcomponentsCard/HasSubcomponentsCard.test.tsx
@@ -21,28 +21,20 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { HasSubcomponentsCard } from './HasSubcomponentsCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
- const catalogApi: jest.Mocked = {
- getLocationById: jest.fn(),
- getEntityByName: jest.fn(),
- getEntities: jest.fn(),
- addLocation: jest.fn(),
- getLocationByEntity: jest.fn(),
- removeEntityByUid: jest.fn(),
- } as any;
+ const getEntities: jest.MockedFunction = jest.fn();
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
@@ -97,7 +89,7 @@ describe('', () => {
},
],
};
- catalogApi.getEntities.mockResolvedValue({
+ getEntities.mockResolvedValue({
items: [
{
apiVersion: 'v1',
diff --git a/plugins/catalog/src/components/HasSystemsCard/HasSystemsCard.test.tsx b/plugins/catalog/src/components/HasSystemsCard/HasSystemsCard.test.tsx
index 3fcfed6099..050550101f 100644
--- a/plugins/catalog/src/components/HasSystemsCard/HasSystemsCard.test.tsx
+++ b/plugins/catalog/src/components/HasSystemsCard/HasSystemsCard.test.tsx
@@ -21,28 +21,20 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { HasSystemsCard } from './HasSystemsCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
- const catalogApi: jest.Mocked = {
- getLocationById: jest.fn(),
- getEntityByName: jest.fn(),
- getEntities: jest.fn(),
- addLocation: jest.fn(),
- getLocationByEntity: jest.fn(),
- removeEntityByUid: jest.fn(),
- } as any;
+ const getEntities: jest.MockedFunction = jest.fn();
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
@@ -95,7 +87,7 @@ describe('', () => {
},
],
};
- catalogApi.getEntities.mockResolvedValue({
+ getEntities.mockResolvedValue({
items: [
{
apiVersion: 'v1',
diff --git a/plugins/catalog/src/components/SystemDiagramCard/SystemDiagramCard.test.tsx b/plugins/catalog/src/components/SystemDiagramCard/SystemDiagramCard.test.tsx
index 2b35d0f3b6..e0ec48fbed 100644
--- a/plugins/catalog/src/components/SystemDiagramCard/SystemDiagramCard.test.tsx
+++ b/plugins/catalog/src/components/SystemDiagramCard/SystemDiagramCard.test.tsx
@@ -21,10 +21,9 @@ import {
entityRouteRef,
} from '@backstage/plugin-catalog-react';
import { Entity, RELATION_PART_OF } from '@backstage/catalog-model';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import React from 'react';
import { SystemDiagramCard } from './SystemDiagramCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
beforeAll(() => {
@@ -55,11 +54,11 @@ describe('', () => {
};
const { queryByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
@@ -114,11 +113,11 @@ describe('', () => {
};
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
@@ -173,11 +172,11 @@ describe('', () => {
};
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
diff --git a/plugins/cost-insights/src/components/CostInsightsHeader/CostInsightsHeader.test.tsx b/plugins/cost-insights/src/components/CostInsightsHeader/CostInsightsHeader.test.tsx
index 4a38af3dbc..e29bb78f2f 100644
--- a/plugins/cost-insights/src/components/CostInsightsHeader/CostInsightsHeader.test.tsx
+++ b/plugins/cost-insights/src/components/CostInsightsHeader/CostInsightsHeader.test.tsx
@@ -15,10 +15,10 @@
*/
import { CostInsightsHeader } from './CostInsightsHeader';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import React from 'react';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import { IdentityApi, identityApiRef } from '@backstage/core-plugin-api';
describe('', () => {
@@ -29,7 +29,7 @@ describe('', () => {
}),
};
- const apis = ApiRegistry.from([[identityApiRef, identityApi]]);
+ const apis = TestApiRegistry.from([identityApiRef, identityApi]);
it('Shows nothing to do when no alerts exist', async () => {
const rendered = await renderInTestApp(
diff --git a/plugins/cost-insights/src/testUtils/providers.tsx b/plugins/cost-insights/src/testUtils/providers.tsx
index 75450c0bb7..09d2feb71b 100644
--- a/plugins/cost-insights/src/testUtils/providers.tsx
+++ b/plugins/cost-insights/src/testUtils/providers.tsx
@@ -30,8 +30,9 @@ import { Group, Duration } from '../types';
// TODO(Rugvip): Could be good to have a clear place to put test utils that is linted accordingly
// eslint-disable-next-line import/no-extraneous-dependencies
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { IdentityApi, identityApiRef } from '@backstage/core-plugin-api';
+// eslint-disable-next-line import/no-extraneous-dependencies
+import { TestApiProvider } from '@backstage/test-utils';
type PartialPropsWithChildren = PropsWithChildren>;
@@ -199,16 +200,17 @@ export const MockCostInsightsApiProvider = ({
getUserGroups: jest.fn(),
};
- // TODO: defaultConfigApiRef: ConfigApiRef
-
- const defaultContext = ApiRegistry.from([
- [identityApiRef, { ...defaultIdentityApi, ...context.identityApi }],
- [
- costInsightsApiRef,
- { ...defaultCostInsightsApi, ...context.costInsightsApi },
- ],
- // [configApiRef, { ...defaultConfigApiRef, ...context.configApiRef }]
- ]);
-
- return {children};
+ return (
+
+ {children}
+
+ );
};
diff --git a/plugins/explore/src/components/DefaultExplorePage/DefaultExplorePage.test.tsx b/plugins/explore/src/components/DefaultExplorePage/DefaultExplorePage.test.tsx
index 8927cf088b..d10c262357 100644
--- a/plugins/explore/src/components/DefaultExplorePage/DefaultExplorePage.test.tsx
+++ b/plugins/explore/src/components/DefaultExplorePage/DefaultExplorePage.test.tsx
@@ -15,11 +15,10 @@
*/
import { catalogApiRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor, getByText } from '@testing-library/react';
import React from 'react';
import { DefaultExplorePage } from './DefaultExplorePage';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const catalogApi: jest.Mocked = {
@@ -36,9 +35,9 @@ describe('', () => {
};
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
-
+
{children}
-
+
);
beforeEach(() => {
diff --git a/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx b/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx
index d78fc0428d..46a8f1adf2 100644
--- a/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx
+++ b/plugins/explore/src/components/DomainExplorerContent/DomainExplorerContent.test.tsx
@@ -16,12 +16,11 @@
import { DomainEntity } from '@backstage/catalog-model';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { catalogEntityRouteRef } from '../../routes';
import { DomainExplorerContent } from './DomainExplorerContent';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const catalogApi: jest.Mocked = {
@@ -38,9 +37,9 @@ describe('', () => {
};
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
-
+
{children}
-
+
);
const mountedRoutes = {
diff --git a/plugins/explore/src/components/ExploreLayout/ExploreLayout.test.tsx b/plugins/explore/src/components/ExploreLayout/ExploreLayout.test.tsx
index 80944628da..7574c685a4 100644
--- a/plugins/explore/src/components/ExploreLayout/ExploreLayout.test.tsx
+++ b/plugins/explore/src/components/ExploreLayout/ExploreLayout.test.tsx
@@ -14,16 +14,12 @@
* limitations under the License.
*/
-import {
- ApiProvider,
- ApiRegistry,
- FeatureFlagged,
-} from '@backstage/core-app-api';
+import { FeatureFlagged } from '@backstage/core-app-api';
import {
FeatureFlagsApi,
featureFlagsApiRef,
} from '@backstage/core-plugin-api';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { ExploreLayout } from './ExploreLayout';
@@ -35,11 +31,11 @@ const featureFlagsApi: jest.Mocked = {
registerFlag: jest.fn(),
};
-const mockApis = ApiRegistry.with(featureFlagsApiRef, featureFlagsApi);
-
describe('', () => {
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
afterEach(() => {
diff --git a/plugins/explore/src/components/GroupsExplorerContent/GroupsDiagram.test.tsx b/plugins/explore/src/components/GroupsExplorerContent/GroupsDiagram.test.tsx
index 66f54900c9..7c57de84bc 100644
--- a/plugins/explore/src/components/GroupsExplorerContent/GroupsDiagram.test.tsx
+++ b/plugins/explore/src/components/GroupsExplorerContent/GroupsDiagram.test.tsx
@@ -20,10 +20,9 @@ import {
entityRouteRef,
} from '@backstage/plugin-catalog-react';
import { Entity } from '@backstage/catalog-model';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import React from 'react';
import { GroupsDiagram } from './GroupsDiagram';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
beforeAll(() => {
@@ -57,9 +56,9 @@ describe('', () => {
};
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
diff --git a/plugins/explore/src/components/GroupsExplorerContent/GroupsExplorerContent.test.tsx b/plugins/explore/src/components/GroupsExplorerContent/GroupsExplorerContent.test.tsx
index f0815e0116..5d3f7c358b 100644
--- a/plugins/explore/src/components/GroupsExplorerContent/GroupsExplorerContent.test.tsx
+++ b/plugins/explore/src/components/GroupsExplorerContent/GroupsExplorerContent.test.tsx
@@ -16,11 +16,10 @@
import { Entity } from '@backstage/catalog-model';
import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { GroupsExplorerContent } from '../GroupsExplorerContent';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const catalogApi: jest.Mocked = {
@@ -37,9 +36,9 @@ describe('', () => {
};
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
-
+
{children}
-
+
);
const mountedRoutes = {
diff --git a/plugins/explore/src/components/ToolExplorerContent/ToolExplorerContent.test.tsx b/plugins/explore/src/components/ToolExplorerContent/ToolExplorerContent.test.tsx
index 8accf8fd30..da35c9fa39 100644
--- a/plugins/explore/src/components/ToolExplorerContent/ToolExplorerContent.test.tsx
+++ b/plugins/explore/src/components/ToolExplorerContent/ToolExplorerContent.test.tsx
@@ -18,13 +18,12 @@ import {
ExploreTool,
exploreToolsConfigRef,
} from '@backstage/plugin-explore-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { lightTheme } from '@backstage/theme';
import { ThemeProvider } from '@material-ui/core';
import { waitFor } from '@testing-library/react';
import React from 'react';
import { ToolExplorerContent } from './ToolExplorerContent';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const exploreToolsConfigApi: jest.Mocked = {
@@ -33,11 +32,9 @@ describe('', () => {
const Wrapper = ({ children }: { children?: React.ReactNode }) => (
-
+
{children}
-
+
);
diff --git a/plugins/firehydrant/src/components/ServiceDetailsCard/ServiceDetailsCard.test.tsx b/plugins/firehydrant/src/components/ServiceDetailsCard/ServiceDetailsCard.test.tsx
index 1123f014da..20dbb77e86 100644
--- a/plugins/firehydrant/src/components/ServiceDetailsCard/ServiceDetailsCard.test.tsx
+++ b/plugins/firehydrant/src/components/ServiceDetailsCard/ServiceDetailsCard.test.tsx
@@ -14,19 +14,19 @@
* limitations under the License.
*/
import React from 'react';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import { fireHydrantApiRef } from '../../api';
import { screen } from '@testing-library/react';
import { ServiceDetailsCard } from './ServiceDetailsCard';
import { Service, Incident } from '../types';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
const mockFireHydrantApi = {
- getServiceDetails: () => {},
- getServiceAnalytics: () => {},
+ getServiceDetails: jest.fn(),
+ getServiceAnalytics: jest.fn(),
};
-const apis = ApiRegistry.from([[fireHydrantApiRef, mockFireHydrantApi]]);
+const apis = TestApiRegistry.from([fireHydrantApiRef, mockFireHydrantApi]);
jest.mock('@backstage/plugin-catalog-react', () => ({
useEntity: () => {
diff --git a/plugins/fossa/src/components/FossaCard/FossaCard.test.tsx b/plugins/fossa/src/components/FossaCard/FossaCard.test.tsx
index 79b401e4a8..046e3e9860 100644
--- a/plugins/fossa/src/components/FossaCard/FossaCard.test.tsx
+++ b/plugins/fossa/src/components/FossaCard/FossaCard.test.tsx
@@ -16,11 +16,10 @@
import { Entity } from '@backstage/catalog-model';
import { EntityProvider } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import React from 'react';
import { FossaApi, fossaApiRef } from '../../api';
import { FossaCard } from './FossaCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const fossaApi: jest.Mocked = {
@@ -30,10 +29,10 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(fossaApiRef, fossaApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx b/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx
index 778f5ee9c6..421ff4431f 100644
--- a/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx
+++ b/plugins/fossa/src/components/FossaPage/FossaPage.test.tsx
@@ -20,11 +20,10 @@ import {
catalogApiRef,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import React from 'react';
import { FossaApi, fossaApiRef } from '../../api';
import { FossaPage } from './FossaPage';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('', () => {
const catalogApi: jest.Mocked = {
@@ -46,13 +45,15 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(fossaApiRef, fossaApi).with(
- catalogApiRef,
- catalogApi,
- );
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx
index 4a4452be5c..0f9573e051 100644
--- a/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx
+++ b/plugins/github-actions/src/components/Cards/RecentWorkflowRunsCard.test.tsx
@@ -24,16 +24,13 @@ import { useWorkflowRuns } from '../useWorkflowRuns';
import type { Props as RecentWorkflowRunsCardProps } from './RecentWorkflowRunsCard';
import { RecentWorkflowRunsCard } from './RecentWorkflowRunsCard';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ConfigReader } from '@backstage/core-app-api';
import {
errorApiRef,
configApiRef,
ConfigApi,
} from '@backstage/core-plugin-api';
+import { TestApiProvider } from '@backstage/test-utils';
jest.mock('../useWorkflowRuns', () => ({
useWorkflowRuns: jest.fn(),
@@ -82,16 +79,16 @@ describe('', () => {
render(
-
-
+
,
);
diff --git a/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx b/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx
index 08eeb4a3ce..dba5bbfe1c 100644
--- a/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx
+++ b/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx
@@ -19,6 +19,7 @@ import { fireEvent } from '@testing-library/react';
import {
setupRequestMockHandlers,
renderInTestApp,
+ TestApiRegistry,
} from '@backstage/test-utils';
import {
GithubDeployment,
@@ -42,11 +43,7 @@ import { Entity } from '@backstage/catalog-model';
import { GithubDeploymentsTable } from './GithubDeploymentsTable';
import { Box } from '@material-ui/core';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import {
errorApiRef,
configApiRef,
@@ -95,14 +92,14 @@ const githubAuthApi: OAuthApi = {
getAccessToken: async _ => 'access_token',
};
-const apis = ApiRegistry.from([
+const apis = TestApiRegistry.from(
[configApiRef, configApi],
[errorApiRef, errorApiMock],
[
githubDeploymentsApiRef,
new GithubDeploymentsApiClient({ scmIntegrationsApi, githubAuthApi }),
],
-]);
+);
const assertFetchedData = async () => {
const rendered = await renderInTestApp(
diff --git a/plugins/gitops-profiles/src/components/ProfileCatalog/ProfileCatalog.test.tsx b/plugins/gitops-profiles/src/components/ProfileCatalog/ProfileCatalog.test.tsx
index 8dba498507..e158bcf6ad 100644
--- a/plugins/gitops-profiles/src/components/ProfileCatalog/ProfileCatalog.test.tsx
+++ b/plugins/gitops-profiles/src/components/ProfileCatalog/ProfileCatalog.test.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import { lightTheme } from '@backstage/theme';
import { ThemeProvider } from '@material-ui/core';
import React from 'react';
@@ -23,7 +23,6 @@ import ProfileCatalog from './ProfileCatalog';
import {
ApiProvider,
- ApiRegistry,
GithubAuth,
OAuthRequestManager,
UrlPatternDiscovery,
@@ -34,7 +33,7 @@ import { githubAuthApiRef } from '@backstage/core-plugin-api';
describe('ProfileCatalog', () => {
it('should render', async () => {
const oauthRequestApi = new OAuthRequestManager();
- const apis = ApiRegistry.from([
+ const apis = TestApiRegistry.from(
[gitOpsApiRef, new GitOpsRestApi('http://localhost:3008')],
[
githubAuthApiRef,
@@ -45,7 +44,7 @@ describe('ProfileCatalog', () => {
oauthRequestApi,
}),
],
- ]);
+ );
const { getByText } = await renderInTestApp(
diff --git a/plugins/graphiql/src/components/GraphiQLPage/GraphiQLPage.test.tsx b/plugins/graphiql/src/components/GraphiQLPage/GraphiQLPage.test.tsx
index 4e426d4364..ae84b549ec 100644
--- a/plugins/graphiql/src/components/GraphiQLPage/GraphiQLPage.test.tsx
+++ b/plugins/graphiql/src/components/GraphiQLPage/GraphiQLPage.test.tsx
@@ -19,14 +19,10 @@ import { GraphiQLPage } from './GraphiQLPage';
import { ThemeProvider } from '@material-ui/core';
import { lightTheme } from '@backstage/theme';
import { act } from 'react-dom/test-utils';
-import { renderWithEffects } from '@backstage/test-utils';
+import { renderWithEffects, TestApiProvider } from '@backstage/test-utils';
import { GraphQLBrowseApi, graphQlBrowseApiRef } from '../../lib/api';
import { configApiRef } from '@backstage/core-plugin-api';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ConfigReader } from '@backstage/core-app-api';
jest.mock('../GraphiQLBrowser', () => ({
GraphiQLBrowser: () => '',
@@ -43,17 +39,17 @@ describe('GraphiQLPage', () => {
};
const rendered = await renderWithEffects(
-
,
- ,
+ ,
);
act(() => {
jest.advanceTimersByTime(250);
@@ -71,16 +67,16 @@ describe('GraphiQLPage', () => {
};
const rendered = await renderWithEffects(
-
- ,
+ ,
);
rendered.getByText('GraphiQL');
@@ -95,16 +91,16 @@ describe('GraphiQLPage', () => {
};
const rendered = await renderWithEffects(
-
- ,
+ ,
);
rendered.getByText('GraphiQL');
diff --git a/plugins/jenkins/src/components/Cards/Cards.test.tsx b/plugins/jenkins/src/components/Cards/Cards.test.tsx
index 2508461710..0af91da179 100644
--- a/plugins/jenkins/src/components/Cards/Cards.test.tsx
+++ b/plugins/jenkins/src/components/Cards/Cards.test.tsx
@@ -15,11 +15,10 @@
*/
import React from 'react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { LatestRunCard } from './Cards';
import { EntityProvider } from '@backstage/plugin-catalog-react';
import { JenkinsApi, jenkinsApiRef } from '../../api';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { Project } from '../../api/JenkinsApi';
describe('', () => {
@@ -41,14 +40,12 @@ describe('', () => {
};
it('should show success status of latest build', async () => {
- const apis = ApiRegistry.from([[jenkinsApiRef, jenkinsApi]]);
-
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
);
expect(getByText('Completed')).toBeInTheDocument();
@@ -59,14 +56,12 @@ describe('', () => {
getProjects: () => Promise.reject(new Error('Unauthorized')),
};
- const apis = ApiRegistry.from([[jenkinsApiRef, jenkinsApiWithError]]);
-
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
);
expect(getByText("Error: Can't connect to Jenkins")).toBeInTheDocument();
@@ -82,14 +77,12 @@ describe('', () => {
}),
};
- const apis = ApiRegistry.from([[jenkinsApiRef, jenkinsApiWithError]]);
-
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
);
expect(getByText("Error: Can't find Jenkins project")).toBeInTheDocument();
diff --git a/plugins/kafka/src/components/ConsumerGroupOffsets/useConsumerGroupsOffsetsForEntity.test.tsx b/plugins/kafka/src/components/ConsumerGroupOffsets/useConsumerGroupsOffsetsForEntity.test.tsx
index a90d3d608e..0be9cabacd 100644
--- a/plugins/kafka/src/components/ConsumerGroupOffsets/useConsumerGroupsOffsetsForEntity.test.tsx
+++ b/plugins/kafka/src/components/ConsumerGroupOffsets/useConsumerGroupsOffsetsForEntity.test.tsx
@@ -26,8 +26,8 @@ import {
import { useConsumerGroupsOffsetsForEntity } from './useConsumerGroupsOffsetsForEntity';
import * as data from './__fixtures__/consumer-group-offsets.json';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { errorApiRef } from '@backstage/core-plugin-api';
+import { TestApiProvider } from '@backstage/test-utils';
const consumerGroupOffsets = data as ConsumerGroupOffsetsResponse;
@@ -59,14 +59,14 @@ describe('useConsumerGroupOffsets', () => {
const wrapper = ({ children }: PropsWithChildren<{}>) => {
return (
-
{children}
-
+
);
};
diff --git a/plugins/kubernetes/dev/index.tsx b/plugins/kubernetes/dev/index.tsx
index a2c1114c2d..12de5f098f 100644
--- a/plugins/kubernetes/dev/index.tsx
+++ b/plugins/kubernetes/dev/index.tsx
@@ -29,7 +29,7 @@ import {
} from '@backstage/plugin-kubernetes-common';
import fixture1 from '../src/__fixtures__/1-deployments.json';
import fixture2 from '../src/__fixtures__/2-deployments.json';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { TestApiProvider } from '@backstage/test-utils';
const mockEntity: Entity = {
apiVersion: 'backstage.io/v1alpha1',
@@ -80,32 +80,26 @@ createDevApp()
path: '/fixture-1',
title: 'Fixture 1',
element: (
-
-
+
),
})
.addPage({
path: '/fixture-2',
title: 'Fixture 2',
element: (
-
-
+
),
})
.registerPlugin(kubernetesPlugin)
diff --git a/plugins/lighthouse/src/components/AuditList/AuditListForEntity.test.tsx b/plugins/lighthouse/src/components/AuditList/AuditListForEntity.test.tsx
index 1433a186fb..53de33d21b 100644
--- a/plugins/lighthouse/src/components/AuditList/AuditListForEntity.test.tsx
+++ b/plugins/lighthouse/src/components/AuditList/AuditListForEntity.test.tsx
@@ -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('', () => {
- let apis: ApiRegistry;
+ let apis: TestApiRegistry;
const mockErrorApi: jest.Mocked = {
post: jest.fn(),
@@ -49,10 +50,10 @@ describe('', () => {
};
beforeEach(() => {
- apis = ApiRegistry.from([
+ apis = TestApiRegistry.from(
[lighthouseApiRef, new LighthouseRestApi('http://lighthouse')],
[errorApiRef, mockErrorApi],
- ]);
+ );
(useWebsiteForEntity as jest.Mock).mockReturnValue({
value: entityWebsite,
diff --git a/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx b/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx
index 4c92997755..d8a54928b2 100644
--- a/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx
+++ b/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx
@@ -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'),
]);
});
diff --git a/plugins/lighthouse/src/components/AuditList/index.test.tsx b/plugins/lighthouse/src/components/AuditList/index.test.tsx
index ea3587fea9..2b422cce7a 100644
--- a/plugins/lighthouse/src/components/AuditList/index.test.tsx
+++ b/plugins/lighthouse/src/components/AuditList/index.test.tsx
@@ -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'),
]);
});
diff --git a/plugins/lighthouse/src/components/AuditView/index.test.tsx b/plugins/lighthouse/src/components/AuditView/index.test.tsx
index ed1bbbcaf9..00b2843a50 100644
--- a/plugins/lighthouse/src/components/AuditView/index.test.tsx
+++ b/plugins/lighthouse/src/components/AuditView/index.test.tsx
@@ -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;
diff --git a/plugins/lighthouse/src/components/CreateAudit/index.test.tsx b/plugins/lighthouse/src/components/CreateAudit/index.test.tsx
index 84493e243f..59847b516e 100644
--- a/plugins/lighthouse/src/components/CreateAudit/index.test.tsx
+++ b/plugins/lighthouse/src/components/CreateAudit/index.test.tsx
@@ -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', () => {
diff --git a/plugins/lighthouse/src/hooks/useWebsiteForEntity.test.tsx b/plugins/lighthouse/src/hooks/useWebsiteForEntity.test.tsx
index 64f7483081..13da0f6f4f 100644
--- a/plugins/lighthouse/src/hooks/useWebsiteForEntity.test.tsx
+++ b/plugins/lighthouse/src/hooks/useWebsiteForEntity.test.tsx
@@ -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 (
-
{children}
-
+
);
};
diff --git a/plugins/org/src/components/Cards/Group/MembersList/MembersListCard.stories.tsx b/plugins/org/src/components/Cards/Group/MembersList/MembersListCard.stories.tsx
index 0a5a0cfef1..b6b549d934 100644
--- a/plugins/org/src/components/Cards/Group/MembersList/MembersListCard.stories.tsx
+++ b/plugins/org/src/components/Cards/Group/MembersList/MembersListCard.stories.tsx
@@ -15,8 +15,8 @@
*/
import { Entity, GroupEntity } from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { catalogApiRef, EntityProvider } from '@backstage/plugin-catalog-react';
+import { TestApiProvider } from '@backstage/test-utils';
import { Grid } from '@material-ui/core';
import React from 'react';
import { MemoryRouter } from 'react-router';
@@ -99,12 +99,9 @@ const catalogApi = (items: Entity[]) => ({
getEntities: () => Promise.resolve({ items }),
});
-const apiRegistry = (items: Entity[]) =>
- ApiRegistry.from([[catalogApiRef, catalogApi(items)]]);
-
export const Default = () => (
-
+
@@ -112,13 +109,13 @@ export const Default = () => (
-
+
);
export const Empty = () => (
-
+
@@ -126,6 +123,6 @@ export const Empty = () => (
-
+
);
diff --git a/plugins/org/src/components/Cards/Group/MembersList/MembersListCard.test.tsx b/plugins/org/src/components/Cards/Group/MembersList/MembersListCard.test.tsx
index 75cb9efd7f..b0c68d9a83 100644
--- a/plugins/org/src/components/Cards/Group/MembersList/MembersListCard.test.tsx
+++ b/plugins/org/src/components/Cards/Group/MembersList/MembersListCard.test.tsx
@@ -20,10 +20,13 @@ import {
catalogApiRef,
EntityProvider,
} from '@backstage/plugin-catalog-react';
-import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils';
+import {
+ renderWithEffects,
+ TestApiProvider,
+ wrapInTestApp,
+} from '@backstage/test-utils';
import React from 'react';
import { MembersListCard } from './MembersListCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('MemberTab Test', () => {
const groupEntity: GroupEntity = {
@@ -103,17 +106,15 @@ describe('MemberTab Test', () => {
}),
};
- const apis = ApiRegistry.from([[catalogApiRef, catalogApi]]);
-
it('Display Profile Card', async () => {
const rendered = await renderWithEffects(
wrapInTestApp(
-
+
,
- ,
+ ,
),
);
diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.stories.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.stories.tsx
index 14fed985b6..6a20035dfa 100644
--- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.stories.tsx
+++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.stories.tsx
@@ -15,14 +15,14 @@
*/
import { GroupEntity } from '@backstage/catalog-model';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import {
CatalogApi,
catalogApiRef,
catalogRouteRef,
EntityProvider,
} from '@backstage/plugin-catalog-react';
-import { wrapInTestApp } from '@backstage/test-utils';
+import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils';
import {
BackstageTheme,
createTheme,
@@ -86,11 +86,11 @@ const catalogApi: Partial = {
getEntities: () => Promise.resolve({ items: [serviceA, serviceB, websiteA] }),
};
-const apiRegistry = ApiRegistry.from([[catalogApiRef, catalogApi]]);
+const apis = TestApiRegistry.from([catalogApiRef, catalogApi]);
export const Default = () =>
wrapInTestApp(
-
+
@@ -123,7 +123,7 @@ const monochromeTheme = (outer: BackstageTheme) =>
export const Themed = () =>
wrapInTestApp(
-
+
diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx
index b5ffd37083..8d6fc1a002 100644
--- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx
+++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx
@@ -21,11 +21,10 @@ import {
EntityProvider,
catalogRouteRef,
} from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { queryByText } from '@testing-library/react';
import React from 'react';
import { OwnershipCard } from './OwnershipCard';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('OwnershipCard', () => {
const groupEntity: GroupEntity = {
@@ -121,11 +120,11 @@ describe('OwnershipCard', () => {
});
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/create': catalogRouteRef,
@@ -157,11 +156,11 @@ describe('OwnershipCard', () => {
});
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/create': catalogRouteRef,
@@ -205,11 +204,11 @@ describe('OwnershipCard', () => {
});
const { getByText } = await renderInTestApp(
-
+
- ,
+ ,
{
mountedRoutes: {
'/create': catalogRouteRef,
diff --git a/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx b/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx
index 446c867f35..723e7b7b19 100644
--- a/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx
+++ b/plugins/pagerduty/src/components/ChangeEvents/ChangeEvents.test.tsx
@@ -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 () => {
diff --git a/plugins/pagerduty/src/components/Escalation/Escalation.test.tsx b/plugins/pagerduty/src/components/Escalation/Escalation.test.tsx
index 52aa9a860f..47f18002fe 100644
--- a/plugins/pagerduty/src/components/Escalation/Escalation.test.tsx
+++ b/plugins/pagerduty/src/components/Escalation/Escalation.test.tsx
@@ -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 () => {
diff --git a/plugins/pagerduty/src/components/Incident/Incidents.test.tsx b/plugins/pagerduty/src/components/Incident/Incidents.test.tsx
index d66acc0879..74e7d82e8b 100644
--- a/plugins/pagerduty/src/components/Incident/Incidents.test.tsx
+++ b/plugins/pagerduty/src/components/Incident/Incidents.test.tsx
@@ -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 () => {
diff --git a/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx b/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx
index d644aa019a..e0a857ccc7 100644
--- a/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx
+++ b/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx
@@ -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 = {
getServiceByIntegrationKey: async () => [],
@@ -31,16 +31,10 @@ const mockPagerDutyApi: Partial = {
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',
diff --git a/plugins/pagerduty/src/components/TriggerButton/index.test.tsx b/plugins/pagerduty/src/components/TriggerButton/index.test.tsx
index 21f0dd5f1d..3776bcaf1c 100644
--- a/plugins/pagerduty/src/components/TriggerButton/index.test.tsx
+++ b/plugins/pagerduty/src/components/TriggerButton/index.test.tsx
@@ -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 = {
diff --git a/plugins/pagerduty/src/components/TriggerDialog/TriggerDialog.test.tsx b/plugins/pagerduty/src/components/TriggerDialog/TriggerDialog.test.tsx
index 444e820b98..d6f378b4bf 100644
--- a/plugins/pagerduty/src/components/TriggerDialog/TriggerDialog.test.tsx
+++ b/plugins/pagerduty/src/components/TriggerDialog/TriggerDialog.test.tsx
@@ -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 = {
diff --git a/plugins/scaffolder/src/components/ActionsPage/ActionsPage.test.tsx b/plugins/scaffolder/src/components/ActionsPage/ActionsPage.test.tsx
index 77c8240974..ce0354b817 100644
--- a/plugins/scaffolder/src/components/ActionsPage/ActionsPage.test.tsx
+++ b/plugins/scaffolder/src/components/ActionsPage/ActionsPage.test.tsx
@@ -17,8 +17,8 @@ import React from 'react';
import { ScaffolderApi, scaffolderApiRef } from '../../api';
import { ActionsPage } from './ActionsPage';
import { rootRouteRef } from '../../routes';
-import { renderInTestApp } from '@backstage/test-utils';
-import { ApiRegistry, ApiProvider } from '@backstage/core-app-api';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
+import { ApiProvider } from '@backstage/core-app-api';
const scaffolderApiMock: jest.Mocked = {
scaffold: jest.fn(),
@@ -29,7 +29,7 @@ const scaffolderApiMock: jest.Mocked = {
listActions: jest.fn(),
};
-const apis = ApiRegistry.from([[scaffolderApiRef, scaffolderApiMock]]);
+const apis = TestApiRegistry.from([scaffolderApiRef, scaffolderApiMock]);
describe('TemplatePage', () => {
beforeEach(() => jest.resetAllMocks());
diff --git a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx
index e42bcbdbdc..60e9ee8840 100644
--- a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx
+++ b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx
@@ -13,7 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { renderInTestApp, renderWithEffects } from '@backstage/test-utils';
+import {
+ renderInTestApp,
+ renderWithEffects,
+ TestApiRegistry,
+} from '@backstage/test-utils';
import { lightTheme } from '@backstage/theme';
import { ThemeProvider } from '@material-ui/core';
import { fireEvent, within } from '@testing-library/react';
@@ -24,7 +28,7 @@ import { ScaffolderApi, scaffolderApiRef } from '../../api';
import { rootRouteRef } from '../../routes';
import { TemplatePage } from './TemplatePage';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import { errorApiRef } from '@backstage/core-plugin-api';
jest.mock('react-router-dom', () => {
@@ -47,10 +51,10 @@ const scaffolderApiMock: jest.Mocked = {
const errorApiMock = { post: jest.fn(), error$: jest.fn() };
-const apis = ApiRegistry.from([
+const apis = TestApiRegistry.from(
[scaffolderApiRef, scaffolderApiMock],
[errorApiRef, errorApiMock],
-]);
+);
describe('TemplatePage', () => {
beforeEach(() => jest.resetAllMocks());
diff --git a/plugins/scaffolder/src/components/TemplateTypePicker/TemplateTypePicker.test.tsx b/plugins/scaffolder/src/components/TemplateTypePicker/TemplateTypePicker.test.tsx
index 3d0267ff1f..c70f251eac 100644
--- a/plugins/scaffolder/src/components/TemplateTypePicker/TemplateTypePicker.test.tsx
+++ b/plugins/scaffolder/src/components/TemplateTypePicker/TemplateTypePicker.test.tsx
@@ -26,8 +26,8 @@ import {
MockEntityListContextProvider,
} from '@backstage/plugin-catalog-react';
import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
-import { renderWithEffects } from '@backstage/test-utils';
+import { ApiProvider } from '@backstage/core-app-api';
+import { renderWithEffects, TestApiRegistry } from '@backstage/test-utils';
const entities: Entity[] = [
{
@@ -62,7 +62,7 @@ const entities: Entity[] = [
},
];
-const apis = ApiRegistry.from([
+const apis = TestApiRegistry.from(
[
catalogApiRef,
{
@@ -77,7 +77,7 @@ const apis = ApiRegistry.from([
post: jest.fn(),
} as unknown as AlertApi,
],
-]);
+);
describe('', () => {
it('renders available entity types', async () => {
diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx
index f293969dff..b7e72e3583 100644
--- a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx
+++ b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.test.tsx
@@ -16,12 +16,11 @@
import { Entity } from '@backstage/catalog-model';
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { FieldProps } from '@rjsf/core';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { EntityPicker } from './EntityPicker';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
const makeEntity = (kind: string, namespace: string, name: string): Entity => ({
apiVersion: 'backstage.io/v1beta1',
@@ -53,14 +52,15 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
entities = [
makeEntity('Group', 'default', 'team-a'),
makeEntity('Group', 'default', 'squad-b'),
];
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.test.tsx b/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.test.tsx
index 18d6fd7e5c..31992fbc8a 100644
--- a/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.test.tsx
+++ b/plugins/scaffolder/src/components/fields/OwnerPicker/OwnerPicker.test.tsx
@@ -16,11 +16,10 @@
import { Entity } from '@backstage/catalog-model';
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { FieldProps } from '@rjsf/core';
import React from 'react';
import { OwnerPicker } from './OwnerPicker';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
const makeEntity = (kind: string, namespace: string, name: string): Entity => ({
apiVersion: 'backstage.io/v1beta1',
@@ -50,14 +49,15 @@ describe('', () => {
let Wrapper: React.ComponentType;
beforeEach(() => {
- const apis = ApiRegistry.with(catalogApiRef, catalogApi);
entities = [
makeEntity('Group', 'default', 'team-a'),
makeEntity('Group', 'default', 'squad-b'),
];
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/search/src/components/SearchBar/SearchBar.test.tsx b/plugins/search/src/components/SearchBar/SearchBar.test.tsx
index 3a11daa9fa..81f90640c1 100644
--- a/plugins/search/src/components/SearchBar/SearchBar.test.tsx
+++ b/plugins/search/src/components/SearchBar/SearchBar.test.tsx
@@ -21,12 +21,9 @@ import { SearchContextProvider } from '../SearchContext';
import { SearchBar } from './SearchBar';
import { configApiRef } from '@backstage/core-plugin-api';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import { searchApiRef } from '../../apis';
+import { TestApiRegistry } from '@backstage/test-utils';
jest.mock('@backstage/core-plugin-api', () => ({
...jest.requireActual('@backstage/core-plugin-api'),
@@ -42,10 +39,10 @@ describe('SearchBar', () => {
const query = jest.fn().mockResolvedValue({});
- const apiRegistry = ApiRegistry.from([
+ const apiRegistry = TestApiRegistry.from(
[configApiRef, new ConfigReader({ app: { title: 'Mock title' } })],
[searchApiRef, { query }],
- ]);
+ );
const name = 'Search';
const term = 'term';
diff --git a/plugins/search/src/components/SearchModal/SearchModal.test.tsx b/plugins/search/src/components/SearchModal/SearchModal.test.tsx
index d7f873abf3..ff9622dfb9 100644
--- a/plugins/search/src/components/SearchModal/SearchModal.test.tsx
+++ b/plugins/search/src/components/SearchModal/SearchModal.test.tsx
@@ -15,14 +15,10 @@
*/
import React from 'react';
import { screen } from '@testing-library/react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import userEvent from '@testing-library/user-event';
import { configApiRef } from '@backstage/core-plugin-api';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import { rootRouteRef } from '../../plugin';
import { searchApiRef } from '../../apis';
@@ -38,10 +34,10 @@ jest.mock('../SearchContext', () => ({
describe('SearchModal', () => {
const query = jest.fn().mockResolvedValue({});
- const apiRegistry = ApiRegistry.from([
+ const apiRegistry = TestApiRegistry.from(
[configApiRef, new ConfigReader({ app: { title: 'Mock app' } })],
[searchApiRef, { query }],
- ]);
+ );
const toggleModal = jest.fn();
diff --git a/plugins/shortcuts/src/Shortcuts.test.tsx b/plugins/shortcuts/src/Shortcuts.test.tsx
index 9182bcb47d..e0a70d6069 100644
--- a/plugins/shortcuts/src/Shortcuts.test.tsx
+++ b/plugins/shortcuts/src/Shortcuts.test.tsx
@@ -15,25 +15,31 @@
*/
import React from 'react';
-import { MockStorageApi, renderInTestApp } from '@backstage/test-utils';
+import {
+ MockStorageApi,
+ renderInTestApp,
+ TestApiProvider,
+} from '@backstage/test-utils';
import { screen, waitFor } from '@testing-library/react';
import { Shortcuts } from './Shortcuts';
import { LocalStoredShortcuts, shortcutsApiRef } from './api';
import { SidebarContext } from '@backstage/core-components';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
-
-const apis = ApiRegistry.from([
- [shortcutsApiRef, new LocalStoredShortcuts(MockStorageApi.create())],
-]);
describe('Shortcuts', () => {
it('displays an add button', async () => {
await renderInTestApp(
-
+
-
+
,
);
await waitFor(() => !screen.queryByTestId('progress'));
diff --git a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx
index 63d617aff2..eb5c99d4e7 100644
--- a/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx
+++ b/plugins/splunk-on-call/src/components/EntitySplunkOnCallCard.test.tsx
@@ -17,7 +17,7 @@ import React from 'react';
import { act, fireEvent, render, waitFor } from '@testing-library/react';
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 {
splunkOnCallApiRef,
SplunkOnCallClient,
@@ -37,13 +37,8 @@ import {
alertApiRef,
ConfigApi,
configApiRef,
- createApiRef,
} from '@backstage/core-plugin-api';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
const mockSplunkOnCallApi: Partial = {
getUsers: async () => [],
@@ -59,17 +54,11 @@ const configApi: ConfigApi = new ConfigReader({
},
});
-const apis = ApiRegistry.from([
+const apis = TestApiRegistry.from(
[splunkOnCallApiRef, mockSplunkOnCallApi],
[configApiRef, configApi],
- [
- alertApiRef,
- createApiRef({
- id: 'core.alert',
- description: 'Used to report alerts and forward them to the app',
- }),
- ],
-]);
+ [alertApiRef, {}],
+);
const mockEntity = {
apiVersion: 'backstage.io/v1alpha1',
diff --git a/plugins/splunk-on-call/src/components/Escalation/Escalation.test.tsx b/plugins/splunk-on-call/src/components/Escalation/Escalation.test.tsx
index 1319493742..046c6a37f9 100644
--- a/plugins/splunk-on-call/src/components/Escalation/Escalation.test.tsx
+++ b/plugins/splunk-on-call/src/components/Escalation/Escalation.test.tsx
@@ -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 { splunkOnCallApiRef } from '../../api';
import { MOCKED_ON_CALL, MOCKED_USER } from '../../api/mocks';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
const mockSplunkOnCallApi = {
- getOnCallUsers: () => [],
+ getOnCallUsers: jest.fn(),
};
-const apis = ApiRegistry.from([[splunkOnCallApiRef, mockSplunkOnCallApi]]);
+const apis = TestApiRegistry.from([splunkOnCallApiRef, mockSplunkOnCallApi]);
describe('Escalation', () => {
it('Handles an empty response', async () => {
diff --git a/plugins/splunk-on-call/src/components/Incident/Incidents.test.tsx b/plugins/splunk-on-call/src/components/Incident/Incidents.test.tsx
index df4254d3ad..181c2fda77 100644
--- a/plugins/splunk-on-call/src/components/Incident/Incidents.test.tsx
+++ b/plugins/splunk-on-call/src/components/Incident/Incidents.test.tsx
@@ -16,43 +16,39 @@
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 { splunkOnCallApiRef } from '../../api';
import { MOCK_TEAM, MOCK_INCIDENT } from '../../api/mocks';
import {
alertApiRef,
- createApiRef,
IdentityApi,
identityApiRef,
} from '@backstage/core-plugin-api';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
const mockIdentityApi: Partial = {
getUserId: () => 'test',
};
const mockSplunkOnCallApi = {
- getIncidents: () => [],
- getTeams: () => [],
+ getIncidents: jest.fn(),
+ getTeams: jest.fn(),
};
-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],
[splunkOnCallApiRef, mockSplunkOnCallApi],
-]);
+);
describe('Incidents', () => {
+ afterEach(() => {
+ jest.resetAllMocks();
+ });
+
it('Renders an empty state when there are no incidents', async () => {
- mockSplunkOnCallApi.getTeams = jest
- .fn()
- .mockImplementationOnce(async () => [MOCK_TEAM]);
+ mockSplunkOnCallApi.getIncidents.mockResolvedValue([]);
+ mockSplunkOnCallApi.getTeams.mockResolvedValue([MOCK_TEAM]);
const { getByText, queryByTestId } = render(
wrapInTestApp(
@@ -69,13 +65,9 @@ describe('Incidents', () => {
});
it('Renders all incidents', async () => {
- mockSplunkOnCallApi.getIncidents = jest
- .fn()
- .mockImplementationOnce(async () => [MOCK_INCIDENT]);
+ mockSplunkOnCallApi.getIncidents.mockResolvedValue([MOCK_INCIDENT]);
+ mockSplunkOnCallApi.getTeams.mockResolvedValue([MOCK_TEAM]);
- mockSplunkOnCallApi.getTeams = jest
- .fn()
- .mockImplementationOnce(async () => [MOCK_TEAM]);
const {
getByText,
getByTitle,
@@ -108,9 +100,10 @@ describe('Incidents', () => {
});
it('Handle errors', async () => {
- mockSplunkOnCallApi.getIncidents = jest
- .fn()
- .mockRejectedValueOnce(new Error('Error occurred'));
+ mockSplunkOnCallApi.getIncidents.mockRejectedValueOnce(
+ new Error('Error occurred'),
+ );
+ mockSplunkOnCallApi.getTeams.mockResolvedValue([]);
const { getByText, queryByTestId } = render(
wrapInTestApp(
diff --git a/plugins/splunk-on-call/src/components/TriggerDialog/TriggerDialog.test.tsx b/plugins/splunk-on-call/src/components/TriggerDialog/TriggerDialog.test.tsx
index 94fd40bfe5..0b64a137af 100644
--- a/plugins/splunk-on-call/src/components/TriggerDialog/TriggerDialog.test.tsx
+++ b/plugins/splunk-on-call/src/components/TriggerDialog/TriggerDialog.test.tsx
@@ -15,12 +15,12 @@
*/
import React from 'react';
import { render, fireEvent, act } from '@testing-library/react';
-import { wrapInTestApp } from '@backstage/test-utils';
+import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils';
import { splunkOnCallApiRef } from '../../api';
import { TriggerDialog } from './TriggerDialog';
-import { ApiRegistry, ApiProvider } from '@backstage/core-app-api';
-import { alertApiRef, createApiRef } from '@backstage/core-plugin-api';
+import { ApiProvider } from '@backstage/core-app-api';
+import { alertApiRef } from '@backstage/core-plugin-api';
describe('TriggerDialog', () => {
const mockTriggerAlarmFn = jest.fn();
@@ -28,16 +28,10 @@ describe('TriggerDialog', () => {
incidentAction: 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, {}],
[splunkOnCallApiRef, mockSplunkOnCallApi],
- ]);
+ );
it('open the dialog and trigger an alarm', async () => {
const { getByText, getByRole, getByTestId } = render(
diff --git a/plugins/tech-radar/src/components/RadarComponent.test.tsx b/plugins/tech-radar/src/components/RadarComponent.test.tsx
index cce411e897..2b237c8d83 100644
--- a/plugins/tech-radar/src/components/RadarComponent.test.tsx
+++ b/plugins/tech-radar/src/components/RadarComponent.test.tsx
@@ -19,13 +19,12 @@ import { render, waitForElement } from '@testing-library/react';
import { ThemeProvider } from '@material-ui/core';
import { lightTheme } from '@backstage/theme';
import { act } from 'react-dom/test-utils';
-import { withLogCollector } from '@backstage/test-utils';
+import { TestApiProvider, withLogCollector } from '@backstage/test-utils';
import GetBBoxPolyfill from '../utils/polyfills/getBBox';
import { RadarComponent } from './RadarComponent';
import { TechRadarLoaderResponse, techRadarApiRef, TechRadarApi } from '../api';
-import { ApiRegistry, ApiProvider } from '@backstage/core-app-api';
import { errorApiRef } from '@backstage/core-plugin-api';
describe('RadarComponent', () => {
@@ -55,18 +54,18 @@ describe('RadarComponent', () => {
const errorApi = { post: () => {} };
const { getByTestId, queryByTestId } = render(
-
-
+
,
);
@@ -87,18 +86,18 @@ describe('RadarComponent', () => {
const { queryByTestId } = render(
-
-
+
,
);
@@ -115,13 +114,13 @@ describe('RadarComponent', () => {
expect(() => {
render(
-
+
-
+
,
);
}).toThrow();
diff --git a/plugins/tech-radar/src/components/RadarPage.test.tsx b/plugins/tech-radar/src/components/RadarPage.test.tsx
index 7215fc40df..7f4e69e388 100644
--- a/plugins/tech-radar/src/components/RadarPage.test.tsx
+++ b/plugins/tech-radar/src/components/RadarPage.test.tsx
@@ -17,6 +17,7 @@
import {
MockErrorApi,
renderInTestApp,
+ TestApiProvider,
wrapInTestApp,
} from '@backstage/test-utils';
import { lightTheme } from '@backstage/theme';
@@ -28,7 +29,6 @@ import GetBBoxPolyfill from '../utils/polyfills/getBBox';
import { RadarPage } from './RadarPage';
import { TechRadarLoaderResponse, techRadarApiRef, TechRadarApi } from '../api';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { errorApiRef } from '@backstage/core-plugin-api';
describe('RadarPage', () => {
@@ -63,9 +63,9 @@ describe('RadarPage', () => {
const { getByTestId, queryByTestId } = render(
wrapInTestApp(
-
+
-
+
,
),
);
@@ -89,9 +89,9 @@ describe('RadarPage', () => {
const { getByText, getByTestId } = await renderInTestApp(
-
+
-
+
,
);
@@ -115,9 +115,9 @@ describe('RadarPage', () => {
const { getByTestId } = await renderInTestApp(
-
+
-
+
,
);
@@ -142,14 +142,14 @@ describe('RadarPage', () => {
const { queryByTestId } = await renderInTestApp(
-
-
+
,
);
diff --git a/plugins/techdocs/src/home/components/DefaultTechDocsHome.test.tsx b/plugins/techdocs/src/home/components/DefaultTechDocsHome.test.tsx
index 1d8d7d2b04..8618c4432f 100644
--- a/plugins/techdocs/src/home/components/DefaultTechDocsHome.test.tsx
+++ b/plugins/techdocs/src/home/components/DefaultTechDocsHome.test.tsx
@@ -14,11 +14,7 @@
* limitations under the License.
*/
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import {
ConfigApi,
configApiRef,
@@ -30,7 +26,11 @@ import {
DefaultStarredEntitiesApi,
starredEntitiesApiRef,
} from '@backstage/plugin-catalog-react';
-import { MockStorageApi, renderInTestApp } from '@backstage/test-utils';
+import {
+ MockStorageApi,
+ renderInTestApp,
+ TestApiRegistry,
+} from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import React from 'react';
import { rootDocsRouteRef } from '../../routes';
@@ -69,12 +69,12 @@ describe('TechDocs Home', () => {
const storageApi = MockStorageApi.create();
- const apiRegistry = ApiRegistry.from([
+ const apiRegistry = TestApiRegistry.from(
[catalogApiRef, mockCatalogApi],
[configApiRef, configApi],
[storageApiRef, storageApi],
[starredEntitiesApiRef, new DefaultStarredEntitiesApi({ storageApi })],
- ]);
+ );
it('should render a TechDocs home page', async () => {
await renderInTestApp(
diff --git a/plugins/techdocs/src/home/components/LegacyTechDocsHome.test.tsx b/plugins/techdocs/src/home/components/LegacyTechDocsHome.test.tsx
index d9d2c6a345..a8fd472f7c 100644
--- a/plugins/techdocs/src/home/components/LegacyTechDocsHome.test.tsx
+++ b/plugins/techdocs/src/home/components/LegacyTechDocsHome.test.tsx
@@ -15,16 +15,12 @@
*/
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import React from 'react';
import { LegacyTechDocsHome } from './LegacyTechDocsHome';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import { ConfigApi, configApiRef } from '@backstage/core-plugin-api';
import { rootDocsRouteRef } from '../../routes';
@@ -59,10 +55,10 @@ describe('Legacy TechDocs Home', () => {
},
});
- const apiRegistry = ApiRegistry.from([
+ const apiRegistry = TestApiRegistry.from(
[catalogApiRef, mockCatalogApi],
[configApiRef, configApi],
- ]);
+ );
it('should render a TechDocs home page', async () => {
await renderInTestApp(
diff --git a/plugins/techdocs/src/home/components/TechDocsCustomHome.test.tsx b/plugins/techdocs/src/home/components/TechDocsCustomHome.test.tsx
index bcbfdeed86..e9c3a55b15 100644
--- a/plugins/techdocs/src/home/components/TechDocsCustomHome.test.tsx
+++ b/plugins/techdocs/src/home/components/TechDocsCustomHome.test.tsx
@@ -15,11 +15,11 @@
*/
import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
import { screen } from '@testing-library/react';
import React from 'react';
import { TechDocsCustomHome, PanelType } from './TechDocsCustomHome';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import { rootDocsRouteRef } from '../../routes';
jest.mock('@backstage/plugin-catalog-react', () => {
@@ -47,7 +47,7 @@ const mockCatalogApi = {
} as Partial;
describe('TechDocsCustomHome', () => {
- const apiRegistry = ApiRegistry.with(catalogApiRef, mockCatalogApi);
+ const apiRegistry = TestApiRegistry.from([catalogApiRef, mockCatalogApi]);
it('should render a TechDocs home page', async () => {
const tabsConfig = [
diff --git a/plugins/techdocs/src/reader/components/Reader.test.tsx b/plugins/techdocs/src/reader/components/Reader.test.tsx
index 8b5dbced3f..6e8609694d 100644
--- a/plugins/techdocs/src/reader/components/Reader.test.tsx
+++ b/plugins/techdocs/src/reader/components/Reader.test.tsx
@@ -19,12 +19,12 @@ import {
ScmIntegrationsApi,
scmIntegrationsApiRef,
} from '@backstage/integration-react';
-import { wrapInTestApp } from '@backstage/test-utils';
+import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils';
import { act, render } from '@testing-library/react';
import React from 'react';
import { TechDocsStorageApi, techdocsStorageApiRef } from '../../api';
import { Reader } from './Reader';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import { searchApiRef } from '@backstage/plugin-search';
jest.mock('react-router-dom', () => {
@@ -57,11 +57,11 @@ describe('', () => {
results: [],
}),
};
- const apiRegistry = ApiRegistry.from([
+ const apiRegistry = TestApiRegistry.from(
[scmIntegrationsApiRef, scmIntegrationsApi],
[techdocsStorageApiRef, techdocsStorageApi],
[searchApiRef, searchApi],
- ]);
+ );
await act(async () => {
const rendered = render(
diff --git a/plugins/techdocs/src/reader/components/TechDocsPage.test.tsx b/plugins/techdocs/src/reader/components/TechDocsPage.test.tsx
index 6a5af982fd..b297466a62 100644
--- a/plugins/techdocs/src/reader/components/TechDocsPage.test.tsx
+++ b/plugins/techdocs/src/reader/components/TechDocsPage.test.tsx
@@ -21,7 +21,7 @@ import {
ScmIntegrationsApi,
scmIntegrationsApiRef,
} from '@backstage/integration-react';
-import { wrapInTestApp } from '@backstage/test-utils';
+import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils';
import { Header } from '@backstage/core-components';
import {
techdocsApiRef,
@@ -29,7 +29,7 @@ import {
techdocsStorageApiRef,
TechDocsStorageApi,
} from '../../api';
-import { ApiRegistry, ApiProvider } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import { searchApiRef } from '@backstage/plugin-search';
jest.mock('react-router-dom', () => {
@@ -90,12 +90,12 @@ describe('', () => {
results: [],
}),
};
- const apiRegistry = ApiRegistry.from([
+ const apiRegistry = TestApiRegistry.from(
[scmIntegrationsApiRef, scmIntegrationsApi],
[techdocsApiRef, techdocsApi],
[techdocsStorageApiRef, techdocsStorageApi],
[searchApiRef, searchApi],
- ]);
+ );
await act(async () => {
const rendered = render(
@@ -147,12 +147,12 @@ describe('', () => {
results: [],
}),
};
- const apiRegistry = ApiRegistry.from([
+ const apiRegistry = TestApiRegistry.from(
[scmIntegrationsApiRef, scmIntegrationsApi],
[techdocsApiRef, techdocsApi],
[techdocsStorageApiRef, techdocsStorageApi],
[searchApiRef, searchApi],
- ]);
+ );
await act(async () => {
const rendered = render(
diff --git a/plugins/techdocs/src/reader/components/TechDocsSearch.test.tsx b/plugins/techdocs/src/reader/components/TechDocsSearch.test.tsx
index 602a94e758..5b3d714a04 100644
--- a/plugins/techdocs/src/reader/components/TechDocsSearch.test.tsx
+++ b/plugins/techdocs/src/reader/components/TechDocsSearch.test.tsx
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { ApiProvider } from '@backstage/core-app-api';
import { searchApiRef } from '@backstage/plugin-search';
-import { wrapInTestApp } from '@backstage/test-utils';
+import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils';
import {
act,
fireEvent,
@@ -54,7 +54,7 @@ describe('', () => {
const querySpy = jest.fn(query);
const searchApi = { query: querySpy };
- const apiRegistry = ApiRegistry.from([[searchApiRef, searchApi]]);
+ const apiRegistry = TestApiRegistry.from([searchApiRef, searchApi]);
await act(async () => {
const rendered = render(
@@ -75,7 +75,7 @@ describe('', () => {
const querySpy = jest.fn(query);
const searchApi = { query: querySpy };
- const apiRegistry = ApiRegistry.from([[searchApiRef, searchApi]]);
+ const apiRegistry = TestApiRegistry.from([searchApiRef, searchApi]);
await act(async () => {
const rendered = render(
diff --git a/plugins/techdocs/src/reader/components/useReaderState.test.tsx b/plugins/techdocs/src/reader/components/useReaderState.test.tsx
index cce8282b3d..e41a114dbe 100644
--- a/plugins/techdocs/src/reader/components/useReaderState.test.tsx
+++ b/plugins/techdocs/src/reader/components/useReaderState.test.tsx
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { NotFoundError } from '@backstage/errors';
+import { TestApiProvider } from '@backstage/test-utils';
import { act, renderHook } from '@testing-library/react-hooks';
import React from 'react';
import { techdocsStorageApiRef } from '../../api';
@@ -38,10 +38,10 @@ describe('useReaderState', () => {
};
beforeEach(() => {
- const apis = ApiRegistry.with(techdocsStorageApiRef, techdocsStorageApi);
-
Wrapper = ({ children }: { children?: React.ReactNode }) => (
- {children}
+
+ {children}
+
);
});
diff --git a/plugins/todo/dev/index.tsx b/plugins/todo/dev/index.tsx
index a4221dc710..fe547812ec 100644
--- a/plugins/todo/dev/index.tsx
+++ b/plugins/todo/dev/index.tsx
@@ -22,8 +22,8 @@ import OfflineIcon from '@material-ui/icons/Storage';
import React from 'react';
import { EntityTodoContent, todoApiRef, todoPlugin } from '../src';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { Content, Header, HeaderLabel, Page } from '@backstage/core-components';
+import { TestApiProvider } from '@backstage/test-utils';
const entity: Entity = {
apiVersion: 'backstage.io/v1alpha1',
@@ -60,7 +60,7 @@ createDevApp()
.registerPlugin(todoPlugin)
.addPage({
element: (
-
+
@@ -71,7 +71,7 @@ createDevApp()
-
+
),
title: 'Entity Todo Content',
icon: OfflineIcon,
diff --git a/plugins/todo/src/components/TodoList/TodoList.test.tsx b/plugins/todo/src/components/TodoList/TodoList.test.tsx
index 0e4d64172d..2759fe40f8 100644
--- a/plugins/todo/src/components/TodoList/TodoList.test.tsx
+++ b/plugins/todo/src/components/TodoList/TodoList.test.tsx
@@ -16,11 +16,10 @@
import { Entity } from '@backstage/catalog-model';
import { EntityProvider } from '@backstage/plugin-catalog-react';
-import { renderWithEffects } from '@backstage/test-utils';
+import { renderWithEffects, TestApiProvider } from '@backstage/test-utils';
import React from 'react';
import { TodoApi, todoApiRef } from '../../api';
import { TodoList } from './TodoList';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
describe('TodoList', () => {
it('should render', async () => {
@@ -42,11 +41,11 @@ describe('TodoList', () => {
const mockEntity = { metadata: { name: 'mock' } } as Entity;
const rendered = await renderWithEffects(
-
+
- ,
+ ,
);
await expect(rendered.findByText('FIXME')).resolves.toBeInTheDocument();
diff --git a/plugins/user-settings/src/components/AuthProviders/UserSettingsAuthProviders.test.tsx b/plugins/user-settings/src/components/AuthProviders/UserSettingsAuthProviders.test.tsx
index 085a884f2e..4e14dec2ef 100644
--- a/plugins/user-settings/src/components/AuthProviders/UserSettingsAuthProviders.test.tsx
+++ b/plugins/user-settings/src/components/AuthProviders/UserSettingsAuthProviders.test.tsx
@@ -14,22 +14,24 @@
* limitations under the License.
*/
-import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils';
+import {
+ renderWithEffects,
+ TestApiRegistry,
+ wrapInTestApp,
+} from '@backstage/test-utils';
import { fireEvent } from '@testing-library/react';
import React from 'react';
import { UserSettingsAuthProviders } from './UserSettingsAuthProviders';
-import {
- ApiProvider,
- ApiRegistry,
- ConfigReader,
-} from '@backstage/core-app-api';
+import { ApiProvider, ConfigReader } from '@backstage/core-app-api';
import { configApiRef, googleAuthApiRef } from '@backstage/core-plugin-api';
const mockSignInHandler = jest.fn().mockReturnValue('');
const mockGoogleAuth = {
sessionState$: () => ({
+ [Symbol.observable]: jest.fn(),
subscribe: () => ({
+ closed: false,
unsubscribe: () => null,
}),
}),
@@ -47,10 +49,10 @@ const createConfig = () =>
const config = createConfig();
-const apiRegistry = ApiRegistry.from([
+const apiRegistry = TestApiRegistry.from(
[configApiRef, config],
[googleAuthApiRef, mockGoogleAuth],
-]);
+);
describe('', () => {
it('displays a provider and calls its sign-in handler on click', async () => {
diff --git a/plugins/user-settings/src/components/General/UserSettingsThemeToggle.test.tsx b/plugins/user-settings/src/components/General/UserSettingsThemeToggle.test.tsx
index caae4d69bc..83d9e23f83 100644
--- a/plugins/user-settings/src/components/General/UserSettingsThemeToggle.test.tsx
+++ b/plugins/user-settings/src/components/General/UserSettingsThemeToggle.test.tsx
@@ -15,16 +15,16 @@
*/
import { AppTheme, appThemeApiRef } from '@backstage/core-plugin-api';
-import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils';
+import {
+ renderWithEffects,
+ TestApiRegistry,
+ wrapInTestApp,
+} from '@backstage/test-utils';
import { lightTheme } from '@backstage/theme';
import { fireEvent } from '@testing-library/react';
import React from 'react';
import { UserSettingsThemeToggle } from './UserSettingsThemeToggle';
-import {
- ApiProvider,
- ApiRegistry,
- AppThemeSelector,
-} from '@backstage/core-app-api';
+import { ApiProvider, AppThemeSelector } from '@backstage/core-app-api';
const mockTheme: AppTheme = {
id: 'light-theme',
@@ -33,8 +33,9 @@ const mockTheme: AppTheme = {
theme: lightTheme,
};
-const apiRegistry = ApiRegistry.from([
- [appThemeApiRef, AppThemeSelector.createWithStorage([mockTheme])],
+const apiRegistry = TestApiRegistry.from([
+ appThemeApiRef,
+ AppThemeSelector.createWithStorage([mockTheme]),
]);
describe('', () => {
diff --git a/plugins/xcmetrics/src/components/BuildDetails/BuildDetails.test.tsx b/plugins/xcmetrics/src/components/BuildDetails/BuildDetails.test.tsx
index 2d949d7abc..7083d890d6 100644
--- a/plugins/xcmetrics/src/components/BuildDetails/BuildDetails.test.tsx
+++ b/plugins/xcmetrics/src/components/BuildDetails/BuildDetails.test.tsx
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import React from 'react';
-import { renderInTestApp } from '@backstage/test-utils';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { BuildDetails, withRequest } from './BuildDetails';
import { xcmetricsApiRef } from '../../api';
@@ -35,11 +34,9 @@ jest.mock('../BuildTimeline', () => ({
describe('BuildDetails', () => {
it('should render', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText('accordion-Host')).toBeInTheDocument();
@@ -61,11 +58,9 @@ describe('BuildDetails with request', () => {
it('should fetch the build and render', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText(client.mockBuild.id)).toBeInTheDocument();
@@ -78,11 +73,9 @@ describe('BuildDetails with request', () => {
.mockRejectedValue({ message: errorMessage });
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText(errorMessage)).toBeInTheDocument();
@@ -92,11 +85,9 @@ describe('BuildDetails with request', () => {
client.XcmetricsClient.getBuild = jest.fn().mockReturnValue(undefined);
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(
diff --git a/plugins/xcmetrics/src/components/BuildList/BuildList.test.tsx b/plugins/xcmetrics/src/components/BuildList/BuildList.test.tsx
index eb141209e7..53471f5e9f 100644
--- a/plugins/xcmetrics/src/components/BuildList/BuildList.test.tsx
+++ b/plugins/xcmetrics/src/components/BuildList/BuildList.test.tsx
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import React from 'react';
-import { renderInTestApp } from '@backstage/test-utils';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { BuildList } from './BuildList';
import { xcmetricsApiRef } from '../../api';
import userEvent from '@testing-library/user-event';
@@ -35,11 +34,9 @@ jest.mock('../BuildDetails', () => ({
describe('BuildList', () => {
it('should render', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText('Builds')).toBeInTheDocument();
@@ -50,11 +47,9 @@ describe('BuildList', () => {
it('should show build details', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
userEvent.click(
@@ -70,11 +65,9 @@ describe('BuildList', () => {
.mockRejectedValue({ message });
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText(message)).toBeInTheDocument();
diff --git a/plugins/xcmetrics/src/components/BuildListFilter/BuildListFilter.test.tsx b/plugins/xcmetrics/src/components/BuildListFilter/BuildListFilter.test.tsx
index b997de68e0..06f4aed1b7 100644
--- a/plugins/xcmetrics/src/components/BuildListFilter/BuildListFilter.test.tsx
+++ b/plugins/xcmetrics/src/components/BuildListFilter/BuildListFilter.test.tsx
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import React from 'react';
-import { renderInTestApp } from '@backstage/test-utils';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import userEvent from '@testing-library/user-event';
import { BuildListFilter } from './BuildListFilter';
import { BuildFilters, xcmetricsApiRef } from '../../api';
@@ -37,14 +36,12 @@ const renderWithFiltersVisible = async (
callback?: (filters: BuildFilters) => void,
) => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
userEvent.click(rendered.getByLabelText('show filters'));
@@ -67,14 +64,12 @@ const setProjectFilter = async (rendered: RenderResult, option: string) => {
describe('BuildListFilter', () => {
it('should render', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText('Filters (0)')).toBeInTheDocument();
diff --git a/plugins/xcmetrics/src/components/Overview/Overview.test.tsx b/plugins/xcmetrics/src/components/Overview/Overview.test.tsx
index 3d24d2a422..42e3772d04 100644
--- a/plugins/xcmetrics/src/components/Overview/Overview.test.tsx
+++ b/plugins/xcmetrics/src/components/Overview/Overview.test.tsx
@@ -14,9 +14,8 @@
* limitations under the License.
*/
import React from 'react';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { xcmetricsApiRef } from '../../api';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import { Overview } from './Overview';
jest.mock('../../api/XcmetricsClient');
@@ -33,11 +32,9 @@ jest.mock('../StatusMatrix', () => ({
describe('Overview', () => {
it('should render', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText('XCMetrics Dashboard')).toBeInTheDocument();
@@ -49,9 +46,9 @@ describe('Overview', () => {
api.getBuilds = jest.fn().mockResolvedValue([]);
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText('No builds to show')).toBeInTheDocument();
@@ -64,9 +61,9 @@ describe('Overview', () => {
api.getBuilds = jest.fn().mockRejectedValue({ message: errorMessage });
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText(errorMessage)).toBeInTheDocument();
diff --git a/plugins/xcmetrics/src/components/OverviewTrends/OverviewTrends.test.tsx b/plugins/xcmetrics/src/components/OverviewTrends/OverviewTrends.test.tsx
index 76b47f4943..db7904a8d1 100644
--- a/plugins/xcmetrics/src/components/OverviewTrends/OverviewTrends.test.tsx
+++ b/plugins/xcmetrics/src/components/OverviewTrends/OverviewTrends.test.tsx
@@ -15,9 +15,8 @@
*/
import React from 'react';
import { OverviewTrends } from './OverviewTrends';
-import { renderInTestApp } from '@backstage/test-utils';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { xcmetricsApiRef } from '../../api';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
import userEvent from '@testing-library/user-event';
jest.mock('../../api/XcmetricsClient');
@@ -26,11 +25,9 @@ const client = require('../../api/XcmetricsClient');
describe('OverviewTrends', () => {
it('should render', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText('Trends for')).toBeInTheDocument();
expect(rendered.getAllByText('Build Count').length).toEqual(3);
@@ -42,20 +39,18 @@ describe('OverviewTrends', () => {
api.getBuildCounts = jest.fn().mockResolvedValue([]);
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText('--')).toBeInTheDocument();
});
it('should change number of days when select is changed', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
userEvent.click(rendered.getByText('14 days'));
@@ -76,9 +71,9 @@ describe('OverviewTrends', () => {
.mockRejectedValue({ message: buildTimesError });
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText(buildCountError)).toBeInTheDocument();
expect(rendered.getByText(buildTimesError)).toBeInTheDocument();
diff --git a/plugins/xcmetrics/src/components/StatusCell/StatusCell.test.tsx b/plugins/xcmetrics/src/components/StatusCell/StatusCell.test.tsx
index cac111d13e..6e5b7f73b9 100644
--- a/plugins/xcmetrics/src/components/StatusCell/StatusCell.test.tsx
+++ b/plugins/xcmetrics/src/components/StatusCell/StatusCell.test.tsx
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import React from 'react';
-import { renderInTestApp } from '@backstage/test-utils';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import userEvent from '@testing-library/user-event';
import { StatusCell } from './StatusCell';
import { xcmetricsApiRef } from '../../api';
@@ -27,9 +26,7 @@ const client = require('../../api/XcmetricsClient');
describe('StatusCell', () => {
it('should render', async () => {
const rendered = await renderInTestApp(
-
+
{
size={10}
spacing={10}
/>
- ,
+ ,
);
userEvent.hover(rendered.getByTestId(client.mockBuild.id));
diff --git a/plugins/xcmetrics/src/components/StatusMatrix/StatusMatrix.test.tsx b/plugins/xcmetrics/src/components/StatusMatrix/StatusMatrix.test.tsx
index 7d3854bbda..f18d322b43 100644
--- a/plugins/xcmetrics/src/components/StatusMatrix/StatusMatrix.test.tsx
+++ b/plugins/xcmetrics/src/components/StatusMatrix/StatusMatrix.test.tsx
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import React from 'react';
-import { renderInTestApp } from '@backstage/test-utils';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { StatusMatrix } from './StatusMatrix';
import { xcmetricsApiRef } from '../../api';
@@ -25,11 +24,9 @@ const client = require('../../api/XcmetricsClient');
describe('StatusMatrix', () => {
it('should render', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
const cell = rendered.getByTestId(client.mockBuild.id);
diff --git a/plugins/xcmetrics/src/components/XcmetricsLayout/XcmetricsLayout.test.tsx b/plugins/xcmetrics/src/components/XcmetricsLayout/XcmetricsLayout.test.tsx
index 84bd25624c..29d6407b03 100644
--- a/plugins/xcmetrics/src/components/XcmetricsLayout/XcmetricsLayout.test.tsx
+++ b/plugins/xcmetrics/src/components/XcmetricsLayout/XcmetricsLayout.test.tsx
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import React from 'react';
-import { renderInTestApp } from '@backstage/test-utils';
-import { ApiProvider, ApiRegistry } from '@backstage/core-app-api';
+import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { XcmetricsLayout } from './XcmetricsLayout';
import { xcmetricsApiRef } from '../../api';
import userEvent from '@testing-library/user-event';
@@ -34,11 +33,9 @@ jest.mock('../BuildList', () => ({
describe('XcmetricsLayout', () => {
it('should render', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
expect(rendered.getByText('Overview')).toBeInTheDocument();
@@ -49,11 +46,9 @@ describe('XcmetricsLayout', () => {
it('should show a list of builds when the Builds tab is selected', async () => {
const rendered = await renderInTestApp(
-
+
- ,
+ ,
);
userEvent.click(rendered.getByText('Builds'));