diff --git a/plugins/catalog-graph/src/components/CatalogGraphPage/SelectedKindsFilter.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphPage/SelectedKindsFilter.test.tsx
index 4349d7005a..74c596b197 100644
--- a/plugins/catalog-graph/src/components/CatalogGraphPage/SelectedKindsFilter.test.tsx
+++ b/plugins/catalog-graph/src/components/CatalogGraphPage/SelectedKindsFilter.test.tsx
@@ -15,13 +15,10 @@
*/
import { ApiProvider } from '@backstage/core-app-api';
-import { AlertApi, alertApiRef, errorApiRef } from '@backstage/core-plugin-api';
+import { alertApiRef, errorApiRef } from '@backstage/core-plugin-api';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
-import {
- mockApis,
- renderWithEffects,
- TestApiRegistry,
-} from '@backstage/test-utils';
+import { renderWithEffects, TestApiRegistry } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import { waitFor, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { SelectedKindsFilter } from './SelectedKindsFilter';
@@ -42,7 +39,7 @@ const catalogApi = catalogApiMock.mock({
});
const apis = TestApiRegistry.from(
[catalogApiRef, catalogApi],
- [alertApiRef, {} as AlertApi],
+ [alertApiRef, mockApis.alert()],
[translationApiRef, mockApis.translation()],
[errorApiRef, { post: jest.fn() }],
);
diff --git a/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.test.tsx b/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.test.tsx
index b2de7522b6..9fa8e6e097 100644
--- a/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.test.tsx
+++ b/plugins/catalog-react/src/components/EntityKindPicker/EntityKindPicker.test.tsx
@@ -19,6 +19,7 @@ import { Entity } from '@backstage/catalog-model';
import { ApiProvider } from '@backstage/core-app-api';
import { alertApiRef } from '@backstage/core-plugin-api';
import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import { fireEvent, waitFor, screen, within } from '@testing-library/react';
import { capitalize } from 'lodash';
import { catalogApiRef } from '../../api';
@@ -65,12 +66,7 @@ describe('', () => {
} as GetEntityFacetsResponse),
},
],
- [
- alertApiRef,
- {
- post: jest.fn(),
- },
- ],
+ [alertApiRef, mockApis.alert()],
);
it('renders available entity kinds', async () => {
diff --git a/plugins/catalog-react/src/components/EntityTypePicker/EntityTypePicker.test.tsx b/plugins/catalog-react/src/components/EntityTypePicker/EntityTypePicker.test.tsx
index 281b94251e..58e731f197 100644
--- a/plugins/catalog-react/src/components/EntityTypePicker/EntityTypePicker.test.tsx
+++ b/plugins/catalog-react/src/components/EntityTypePicker/EntityTypePicker.test.tsx
@@ -23,6 +23,7 @@ import { EntityKindFilter, EntityTypeFilter } from '../../filters';
import { alertApiRef } from '@backstage/core-plugin-api';
import { ApiProvider } from '@backstage/core-app-api';
import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import { GetEntityFacetsResponse } from '@backstage/catalog-client';
const entities: Entity[] = [
@@ -72,12 +73,7 @@ const apis = TestApiRegistry.from(
} as GetEntityFacetsResponse),
},
],
- [
- alertApiRef,
- {
- post: jest.fn(),
- },
- ],
+ [alertApiRef, mockApis.alert()],
);
describe('', () => {
diff --git a/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx b/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx
index 595cd70fc4..eea5f95e89 100644
--- a/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx
+++ b/plugins/catalog-react/src/components/UnregisterEntityDialog/UnregisterEntityDialog.test.tsx
@@ -25,22 +25,12 @@ import { catalogApiRef } from '../../api';
import { entityRouteRef } from '../../routes';
import { screen, waitFor } from '@testing-library/react';
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import * as state from './useUnregisterEntityDialogState';
-import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
+import { alertApiRef } from '@backstage/core-plugin-api';
describe('UnregisterEntityDialog', () => {
- const alertApi: AlertApi = {
- post() {
- return undefined;
- },
- alert$() {
- throw new Error('not implemented');
- },
- };
-
- beforeEach(() => {
- jest.spyOn(alertApi, 'post').mockImplementation(() => {});
- });
+ const alertApi = mockApis.alert();
const entity = {
apiVersion: 'backstage.io/v1alpha1',
@@ -340,11 +330,13 @@ describe('UnregisterEntityDialog', () => {
await waitFor(() => {
expect(deleteEntity).toHaveBeenCalled();
expect(onConfirm).toHaveBeenCalled();
- expect(alertApi.post).toHaveBeenCalledWith({
- message: 'Removed entity n',
- severity: 'success',
- display: 'transient',
- });
+ expect(alertApi.getAlerts()).toContainEqual(
+ expect.objectContaining({
+ message: 'Removed entity n',
+ severity: 'success',
+ display: 'transient',
+ }),
+ );
});
});
});
diff --git a/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx b/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx
index 711fb09f8c..a5fda1bf5b 100644
--- a/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx
+++ b/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx
@@ -25,7 +25,8 @@ import {
} from '@backstage/core-plugin-api';
import { translationApiRef } from '@backstage/core-plugin-api/alpha';
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
-import { mockApis, TestApiProvider } from '@backstage/test-utils';
+import { TestApiProvider } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import { useMountEffect } from '@react-hookz/web';
import { act, renderHook, waitFor } from '@testing-library/react';
import qs from 'qs';
@@ -111,7 +112,7 @@ const createWrapper =
[identityApiRef, mockIdentityApi],
[storageApiRef, mockApis.storage()],
[starredEntitiesApiRef, new MockStarredEntitiesApi()],
- [alertApiRef, { post: jest.fn() }],
+ [alertApiRef, mockApis.alert()],
[translationApiRef, mockApis.translation()],
[errorApiRef, { error$: jest.fn(), post: jest.fn() }],
]}
diff --git a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx
index 9ae448a9fc..c43db8746c 100644
--- a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx
+++ b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx
@@ -32,11 +32,11 @@ import {
import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
import { permissionApiRef } from '@backstage/plugin-permission-react';
import {
- mockApis,
renderInTestApp,
TestApiProvider,
TestApiRegistry,
} from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
import { EntityLayout } from './EntityLayout';
import { rootRouteRef, unregisterRedirectRouteRef } from '../../routes';
@@ -52,7 +52,7 @@ describe('EntityLayout', () => {
const apis = TestApiRegistry.from(
[catalogApiRef, catalogApiMock()],
- [alertApiRef, {} as AlertApi],
+ [alertApiRef, mockApis.alert()],
[starredEntitiesApiRef, new MockStarredEntitiesApi()],
[permissionApiRef, mockApis.permission()],
);
diff --git a/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx b/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx
index 80d97a2e1e..40085d195d 100644
--- a/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx
+++ b/plugins/catalog/src/components/EntityOrphanWarning/DeleteEntityDialog.test.tsx
@@ -22,13 +22,11 @@ import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
import { screen, waitFor } from '@testing-library/react';
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
-import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
+import { alertApiRef } from '@backstage/core-plugin-api';
+import { mockApis } from '@backstage/frontend-test-utils';
describe('DeleteEntityDialog', () => {
- const alertApi: jest.Mocked = {
- post: jest.fn(),
- alert$: jest.fn(),
- };
+ const alertApi = mockApis.alert();
const catalogClient = catalogApiMock.mock();
@@ -123,7 +121,9 @@ describe('DeleteEntityDialog', () => {
await waitFor(() => {
expect(catalogClient.removeEntityByUid).toHaveBeenCalledWith('123');
- expect(alertApi.post).toHaveBeenCalledWith({ message: 'no no no' });
+ expect(alertApi.getAlerts()).toContainEqual(
+ expect.objectContaining({ message: 'no no no' }),
+ );
});
});
});
diff --git a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx
index 66affd86f1..6d5df6fb10 100644
--- a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx
+++ b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx
@@ -24,10 +24,10 @@ import { ReactNode, useEffect } from 'react';
import { isKind } from './conditions';
import { EntitySwitch } from './EntitySwitch';
import { featureFlagsApiRef } from '@backstage/core-plugin-api';
-import { LocalStorageFeatureFlags } from '@backstage/core-app-api';
import { TestApiProvider } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
-const mockFeatureFlagsApi = new LocalStorageFeatureFlags();
+const mockFeatureFlagsApi = mockApis.featureFlags.mock();
const Wrapper = ({ children }: { children?: ReactNode }) => (
{children}
diff --git a/plugins/scaffolder-react/package.json b/plugins/scaffolder-react/package.json
index 840f210c78..077824950b 100644
--- a/plugins/scaffolder-react/package.json
+++ b/plugins/scaffolder-react/package.json
@@ -98,6 +98,7 @@
"devDependencies": {
"@backstage/cli": "workspace:^",
"@backstage/core-app-api": "workspace:^",
+ "@backstage/frontend-test-utils": "workspace:^",
"@backstage/plugin-catalog": "workspace:^",
"@backstage/plugin-catalog-common": "workspace:^",
"@backstage/plugin-permission-common": "workspace:^",
diff --git a/plugins/scaffolder-react/src/next/components/TemplateCategoryPicker/TemplateCategoryPicker.test.tsx b/plugins/scaffolder-react/src/next/components/TemplateCategoryPicker/TemplateCategoryPicker.test.tsx
index cfbe8a40b4..9489321854 100644
--- a/plugins/scaffolder-react/src/next/components/TemplateCategoryPicker/TemplateCategoryPicker.test.tsx
+++ b/plugins/scaffolder-react/src/next/components/TemplateCategoryPicker/TemplateCategoryPicker.test.tsx
@@ -17,6 +17,7 @@
import { useEntityTypeFilter } from '@backstage/plugin-catalog-react';
import { TemplateCategoryPicker } from './TemplateCategoryPicker';
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import { alertApiRef } from '@backstage/core-plugin-api';
import { fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
@@ -26,10 +27,10 @@ jest.mock('@backstage/plugin-catalog-react', () => ({
}));
describe('TemplateCategoryPicker', () => {
- const mockAlertApi = { post: jest.fn() };
+ const mockAlertApi = mockApis.alert();
beforeEach(() => {
- mockAlertApi.post.mockClear();
+ mockAlertApi.clearAlerts();
});
it('should post the error to errorApi if an errors is returned', async () => {
@@ -37,13 +38,16 @@ describe('TemplateCategoryPicker', () => {
error: new Error('something broked'),
});
+ mockAlertApi.clearAlerts();
+
await renderInTestApp(
,
);
- expect(mockAlertApi.post).toHaveBeenCalledWith({
+ expect(mockAlertApi.getAlerts().length).toBeGreaterThanOrEqual(1);
+ expect(mockAlertApi.getAlerts()[0]).toMatchObject({
message: expect.stringContaining('something broked'),
severity: 'error',
});
diff --git a/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx b/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx
index 78c2064c4b..293ef54bc2 100644
--- a/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx
+++ b/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx
@@ -18,11 +18,10 @@ import { renderHook } from '@testing-library/react';
import { useFilteredSchemaProperties } from './useFilteredSchemaProperties';
import { TemplateParameterSchema } from '../../types';
import { TestApiProvider } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import { featureFlagsApiRef } from '@backstage/core-plugin-api';
-const mockFeatureFlagApi = {
- isActive: jest.fn(),
-};
+const mockFeatureFlagApi = mockApis.featureFlags.mock();
describe('useFilteredSchemaProperties', () => {
it('should return the same manifest if no feature flag is set', () => {
diff --git a/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.test.tsx b/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.test.tsx
index dff5500b51..b2cf94edbe 100644
--- a/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.test.tsx
+++ b/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.test.tsx
@@ -16,6 +16,7 @@
import { useTemplateSchema } from './useTemplateSchema';
import { renderHook } from '@testing-library/react';
import { TestApiProvider } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import { PropsWithChildren } from 'react';
import { featureFlagsApiRef } from '@backstage/core-plugin-api';
import { TemplateParameterSchema } from '../../types';
@@ -49,11 +50,13 @@ describe('useTemplateSchema', () => {
],
};
+ const mockFeatureFlagsApi = mockApis.featureFlags.mock({
+ isActive: jest.fn(() => false),
+ });
+
const { result } = renderHook(() => useTemplateSchema(manifest), {
wrapper: ({ children }: PropsWithChildren<{}>) => (
- false }]]}
- >
+
{children}
),
@@ -119,7 +122,12 @@ describe('useTemplateSchema', () => {
const { result } = renderHook(() => useTemplateSchema(manifest), {
wrapper: ({ children }: PropsWithChildren<{}>) => (
false }]]}
+ apis={[
+ [
+ featureFlagsApiRef,
+ mockApis.featureFlags.mock({ isActive: jest.fn(() => false) }),
+ ],
+ ]}
>
{children}
@@ -163,7 +171,12 @@ describe('useTemplateSchema', () => {
const { result } = renderHook(() => useTemplateSchema(manifest), {
wrapper: ({ children }: PropsWithChildren<{}>) => (
true }]]}
+ apis={[
+ [
+ featureFlagsApiRef,
+ mockApis.featureFlags.mock({ isActive: jest.fn(() => true) }),
+ ],
+ ]}
>
{children}
@@ -214,7 +227,12 @@ describe('useTemplateSchema', () => {
const { result } = renderHook(() => useTemplateSchema(manifest), {
wrapper: ({ children }: PropsWithChildren<{}>) => (
false }]]}
+ apis={[
+ [
+ featureFlagsApiRef,
+ mockApis.featureFlags.mock({ isActive: jest.fn(() => false) }),
+ ],
+ ]}
>
{children}
@@ -252,7 +270,12 @@ describe('useTemplateSchema', () => {
const { result } = renderHook(() => useTemplateSchema(manifest), {
wrapper: ({ children }: PropsWithChildren<{}>) => (
false }]]}
+ apis={[
+ [
+ featureFlagsApiRef,
+ mockApis.featureFlags.mock({ isActive: jest.fn(() => false) }),
+ ],
+ ]}
>
{children}
@@ -356,7 +379,12 @@ describe('useTemplateSchema', () => {
const { result } = renderHook(() => useTemplateSchema(manifest), {
wrapper: ({ children }: PropsWithChildren<{}>) => (
false }]]}
+ apis={[
+ [
+ featureFlagsApiRef,
+ mockApis.featureFlags.mock({ isActive: jest.fn(() => false) }),
+ ],
+ ]}
>
{children}
diff --git a/plugins/scaffolder/package.json b/plugins/scaffolder/package.json
index 9b505fc2b6..c08f507f42 100644
--- a/plugins/scaffolder/package.json
+++ b/plugins/scaffolder/package.json
@@ -108,6 +108,7 @@
"@backstage/cli": "workspace:^",
"@backstage/core-app-api": "workspace:^",
"@backstage/dev-utils": "workspace:^",
+ "@backstage/frontend-test-utils": "workspace:^",
"@backstage/plugin-catalog": "workspace:^",
"@backstage/plugin-permission-common": "workspace:^",
"@backstage/plugin-techdocs": "workspace:^",
diff --git a/plugins/scaffolder/src/components/TemplateTypePicker/TemplateTypePicker.test.tsx b/plugins/scaffolder/src/components/TemplateTypePicker/TemplateTypePicker.test.tsx
index 5968f1da4f..cc45547827 100644
--- a/plugins/scaffolder/src/components/TemplateTypePicker/TemplateTypePicker.test.tsx
+++ b/plugins/scaffolder/src/components/TemplateTypePicker/TemplateTypePicker.test.tsx
@@ -23,9 +23,10 @@ import {
EntityKindFilter,
} from '@backstage/plugin-catalog-react';
import { MockEntityListContextProvider } from '@backstage/plugin-catalog-react/testUtils';
-import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
+import { alertApiRef } from '@backstage/core-plugin-api';
import { ApiProvider } from '@backstage/core-app-api';
import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils';
+import { mockApis } from '@backstage/frontend-test-utils';
import { GetEntityFacetsResponse } from '@backstage/catalog-client';
const entities: Entity[] = [
@@ -75,12 +76,7 @@ const apis = TestApiRegistry.from(
} as GetEntityFacetsResponse),
},
],
- [
- alertApiRef,
- {
- post: jest.fn(),
- } as unknown as AlertApi,
- ],
+ [alertApiRef, mockApis.alert()],
);
describe('', () => {
diff --git a/yarn.lock b/yarn.lock
index 20a3bd3b48..f00bf67f21 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7037,6 +7037,7 @@ __metadata:
"@backstage/core-components": "workspace:^"
"@backstage/core-plugin-api": "workspace:^"
"@backstage/frontend-plugin-api": "workspace:^"
+ "@backstage/frontend-test-utils": "workspace:^"
"@backstage/plugin-catalog": "workspace:^"
"@backstage/plugin-catalog-common": "workspace:^"
"@backstage/plugin-catalog-react": "workspace:^"
@@ -7106,6 +7107,7 @@ __metadata:
"@backstage/dev-utils": "workspace:^"
"@backstage/errors": "workspace:^"
"@backstage/frontend-plugin-api": "workspace:^"
+ "@backstage/frontend-test-utils": "workspace:^"
"@backstage/integration": "workspace:^"
"@backstage/integration-react": "workspace:^"
"@backstage/plugin-catalog": "workspace:^"