@@ -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:^",
|
||||
|
||||
+7
-3
@@ -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(
|
||||
<TestApiProvider apis={[[alertApiRef, mockAlertApi]]}>
|
||||
<TemplateCategoryPicker />
|
||||
</TestApiProvider>,
|
||||
);
|
||||
|
||||
expect(mockAlertApi.post).toHaveBeenCalledWith({
|
||||
expect(mockAlertApi.getAlerts().length).toBeGreaterThanOrEqual(1);
|
||||
expect(mockAlertApi.getAlerts()[0]).toMatchObject({
|
||||
message: expect.stringContaining('something broked'),
|
||||
severity: 'error',
|
||||
});
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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<{}>) => (
|
||||
<TestApiProvider
|
||||
apis={[[featureFlagsApiRef, { isActive: () => false }]]}
|
||||
>
|
||||
<TestApiProvider apis={[[featureFlagsApiRef, mockFeatureFlagsApi]]}>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
),
|
||||
@@ -119,7 +122,12 @@ describe('useTemplateSchema', () => {
|
||||
const { result } = renderHook(() => useTemplateSchema(manifest), {
|
||||
wrapper: ({ children }: PropsWithChildren<{}>) => (
|
||||
<TestApiProvider
|
||||
apis={[[featureFlagsApiRef, { isActive: () => false }]]}
|
||||
apis={[
|
||||
[
|
||||
featureFlagsApiRef,
|
||||
mockApis.featureFlags.mock({ isActive: jest.fn(() => false) }),
|
||||
],
|
||||
]}
|
||||
>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
@@ -163,7 +171,12 @@ describe('useTemplateSchema', () => {
|
||||
const { result } = renderHook(() => useTemplateSchema(manifest), {
|
||||
wrapper: ({ children }: PropsWithChildren<{}>) => (
|
||||
<TestApiProvider
|
||||
apis={[[featureFlagsApiRef, { isActive: () => true }]]}
|
||||
apis={[
|
||||
[
|
||||
featureFlagsApiRef,
|
||||
mockApis.featureFlags.mock({ isActive: jest.fn(() => true) }),
|
||||
],
|
||||
]}
|
||||
>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
@@ -214,7 +227,12 @@ describe('useTemplateSchema', () => {
|
||||
const { result } = renderHook(() => useTemplateSchema(manifest), {
|
||||
wrapper: ({ children }: PropsWithChildren<{}>) => (
|
||||
<TestApiProvider
|
||||
apis={[[featureFlagsApiRef, { isActive: () => false }]]}
|
||||
apis={[
|
||||
[
|
||||
featureFlagsApiRef,
|
||||
mockApis.featureFlags.mock({ isActive: jest.fn(() => false) }),
|
||||
],
|
||||
]}
|
||||
>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
@@ -252,7 +270,12 @@ describe('useTemplateSchema', () => {
|
||||
const { result } = renderHook(() => useTemplateSchema(manifest), {
|
||||
wrapper: ({ children }: PropsWithChildren<{}>) => (
|
||||
<TestApiProvider
|
||||
apis={[[featureFlagsApiRef, { isActive: () => false }]]}
|
||||
apis={[
|
||||
[
|
||||
featureFlagsApiRef,
|
||||
mockApis.featureFlags.mock({ isActive: jest.fn(() => false) }),
|
||||
],
|
||||
]}
|
||||
>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
@@ -356,7 +379,12 @@ describe('useTemplateSchema', () => {
|
||||
const { result } = renderHook(() => useTemplateSchema(manifest), {
|
||||
wrapper: ({ children }: PropsWithChildren<{}>) => (
|
||||
<TestApiProvider
|
||||
apis={[[featureFlagsApiRef, { isActive: () => false }]]}
|
||||
apis={[
|
||||
[
|
||||
featureFlagsApiRef,
|
||||
mockApis.featureFlags.mock({ isActive: jest.fn(() => false) }),
|
||||
],
|
||||
]}
|
||||
>
|
||||
{children}
|
||||
</TestApiProvider>
|
||||
|
||||
Reference in New Issue
Block a user