Added tests

Signed-off-by: tperehinets <tetiana.perehinets@gmail.com>
This commit is contained in:
tperehinets
2023-11-12 19:21:18 -05:00
committed by blam
parent 20c6880c25
commit 1944b1f5b9
5 changed files with 93 additions and 6 deletions
@@ -27,8 +27,9 @@ import { errorApiRef, useApi } from '@backstage/core-plugin-api';
import { useTemplateParameterSchema } from '../../hooks/useTemplateParameterSchema';
import { Stepper, type StepperProps } from '../Stepper/Stepper';
import { SecretsContextProvider } from '../../../secrets/SecretsContext';
import { ReviewStepProps } from '@backstage/plugin-scaffolder-react';
import { useFeatureFlaggedProperties } from '../../hooks/useFeatureFlaggedProperties';
import { useFilteredSchemaProperties } from '../../hooks/useFilteredSchemaProperties';
import { ReviewStepProps } from '../../../components';
const useStyles = makeStyles<BackstageTheme>(() => ({
markdown: {
@@ -82,7 +83,7 @@ export const Workflow = (workflowProps: WorkflowProps): JSX.Element | null => {
const { loading, manifest, error } = useTemplateParameterSchema(templateRef);
const sortedManifest = useFeatureFlaggedProperties(manifest);
const sortedManifest = useFilteredSchemaProperties(manifest);
useEffect(() => {
if (error) {
@@ -19,4 +19,4 @@ export {
type ParsedTemplateSchema,
} from './useTemplateSchema';
export { useTemplateParameterSchema } from './useTemplateParameterSchema';
export { useFeatureFlaggedProperties } from './useFeatureFlaggedProperties';
export { useFilteredSchemaProperties } from './useFilteredSchemaProperties';
@@ -0,0 +1,86 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { TestApiProvider } from '@backstage/test-utils';
import { useFilteredSchemaProperties } from './useFilteredSchemaProperties';
import { TemplateParameterSchema } from '../../types';
describe('useFilteredSchemaProperties', () => {
it('should hide "Fill in some steps" from steps of template', () => {
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 sortedManifest = renderHook(() =>
useFilteredSchemaProperties(manifest),
);
const expectedManifest: TemplateParameterSchema = {
title: 'Test Action template',
description: 'scaffolder v1beta3 template demo',
steps: [
{
title: 'Choose a location',
schema: {
type: 'object',
properties: {
repoUrl: {
type: 'string',
title: 'Repository Location',
'ui:field': 'RepoUrlPicker',
},
},
},
},
],
};
expect(sortedManifest).toEqual(expectedManifest);
});
});
@@ -22,7 +22,7 @@ import { TemplateParameterSchema } from '@backstage/plugin-scaffolder-react';
* @alpha
*/
export const useFeatureFlaggedProperties = (
export const useFilteredSchemaProperties = (
manifest: TemplateParameterSchema | undefined,
) => {
const featureFlagKey = 'backstage:featureFlag';