diff --git a/plugins/scaffolder-react/package.json b/plugins/scaffolder-react/package.json
index 631fa2031e..24a5441488 100644
--- a/plugins/scaffolder-react/package.json
+++ b/plugins/scaffolder-react/package.json
@@ -94,7 +94,6 @@
"@testing-library/dom": "^9.0.0",
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^14.0.0",
- "@testing-library/react-hooks": "^8.0.0",
"@testing-library/user-event": "^14.0.0",
"@types/humanize-duration": "^3.18.1",
"@types/luxon": "^3.0.0"
diff --git a/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx b/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx
index 1264e7d2e2..3e568fa7bd 100644
--- a/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx
+++ b/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx
@@ -14,12 +14,21 @@
* limitations under the License.
*/
-import { renderHook } from '@testing-library/react-hooks';
+import { renderHook } from '@testing-library/react';
import { useFilteredSchemaProperties } from './useFilteredSchemaProperties';
import { TemplateParameterSchema } from '../../types';
+import { TestApiProvider } from '@backstage/test-utils';
+import React from 'react';
+import { featureFlagsApiRef } from '@backstage/core-plugin-api';
+
+const mockFeatureFlagApi = {
+ isActive: jest.fn(),
+};
describe('useFilteredSchemaProperties', () => {
- it('should hide "Fill in some steps" from steps of template', () => {
+ it('should return the same manifest if no feature flag is set', () => {
+ mockFeatureFlagApi.isActive.mockReturnValue(true);
+
const manifest: TemplateParameterSchema = {
title: 'Test Action template',
description: 'scaffolder v1beta3 template demo',
@@ -55,8 +64,147 @@ describe('useFilteredSchemaProperties', () => {
],
};
- const sortedManifest = renderHook(() =>
- useFilteredSchemaProperties(manifest),
+ const filteredManifest = renderHook(
+ () => useFilteredSchemaProperties(manifest),
+ {
+ wrapper: ({ children }) => (
+
+ {children}
+
+ ),
+ },
+ );
+
+ expect(filteredManifest.result.current).toEqual(manifest);
+ });
+
+ it('should hide individual fields from steps of template', () => {
+ mockFeatureFlagApi.isActive.mockReturnValue(false);
+
+ const manifest: TemplateParameterSchema = {
+ title: 'Test Action template',
+ description: 'scaffolder v1beta3 template demo',
+ steps: [
+ {
+ title: 'Fill in some steps',
+ schema: {
+ type: 'object',
+ properties: {
+ name: {
+ description: 'Unique name of the component',
+ title: 'Name',
+ type: 'string',
+ 'ui:autofocus': true,
+ },
+ },
+ },
+ },
+ {
+ title: 'Choose a location',
+ schema: {
+ type: 'object',
+ properties: {
+ repoUrl: {
+ type: 'string',
+ title: 'Repository Location',
+ 'ui:field': 'RepoUrlPicker',
+ 'backstage:featureFlag': 'experimental-feature',
+ },
+ },
+ },
+ },
+ ],
+ };
+
+ const filteredManifest = renderHook(
+ () => useFilteredSchemaProperties(manifest),
+ {
+ wrapper: ({ children }) => (
+
+ {children}
+
+ ),
+ },
+ );
+
+ const expectedManifest: TemplateParameterSchema = {
+ title: 'Test Action template',
+ description: 'scaffolder v1beta3 template demo',
+ steps: [
+ {
+ title: 'Fill in some steps',
+ schema: {
+ type: 'object',
+ properties: {
+ name: {
+ description: 'Unique name of the component',
+ title: 'Name',
+ type: 'string',
+ 'ui:autofocus': true,
+ },
+ },
+ },
+ },
+ {
+ title: 'Choose a location',
+ schema: {
+ type: 'object',
+ properties: {},
+ },
+ },
+ ],
+ };
+
+ expect(filteredManifest.result.current).toEqual(expectedManifest);
+ });
+
+ it('should hide "Fill in some steps" from steps of template', () => {
+ mockFeatureFlagApi.isActive.mockReturnValue(false);
+
+ const manifest: TemplateParameterSchema = {
+ title: 'Test Action template',
+ description: 'scaffolder v1beta3 template demo',
+ steps: [
+ {
+ title: 'Fill in some steps',
+ schema: {
+ type: 'object',
+ 'backstage:featureFlag': 'experimental-feature',
+ properties: {
+ name: {
+ description: 'Unique name of the component',
+ title: 'Name',
+ type: 'string',
+ 'ui:autofocus': true,
+ },
+ },
+ },
+ },
+ {
+ title: 'Choose a location',
+ schema: {
+ type: 'object',
+ properties: {
+ repoUrl: {
+ type: 'string',
+ title: 'Repository Location',
+ 'ui:field': 'RepoUrlPicker',
+ },
+ },
+ },
+ },
+ ],
+ };
+
+ const filteredManifest = renderHook(
+ () => useFilteredSchemaProperties(manifest),
+ {
+ wrapper: ({ children }) => (
+
+ {children}
+
+ ),
+ },
);
const expectedManifest: TemplateParameterSchema = {
@@ -79,6 +227,6 @@ describe('useFilteredSchemaProperties', () => {
],
};
- expect(sortedManifest).toEqual(expectedManifest);
+ expect(filteredManifest.result.current).toEqual(expectedManifest);
});
});
diff --git a/yarn.lock b/yarn.lock
index 07ae34399d..81b6b6affa 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -8973,7 +8973,6 @@ __metadata:
"@testing-library/dom": ^9.0.0
"@testing-library/jest-dom": ^6.0.0
"@testing-library/react": ^14.0.0
- "@testing-library/react-hooks": ^8.0.0
"@testing-library/user-event": ^14.0.0
"@types/humanize-duration": ^3.18.1
"@types/json-schema": ^7.0.9