diff --git a/plugins/scaffolder-react/src/next/components/Workflow/Workflow.tsx b/plugins/scaffolder-react/src/next/components/Workflow/Workflow.tsx index 204df49f99..8c202eb3b3 100644 --- a/plugins/scaffolder-react/src/next/components/Workflow/Workflow.tsx +++ b/plugins/scaffolder-react/src/next/components/Workflow/Workflow.tsx @@ -31,8 +31,6 @@ import { useFilteredSchemaProperties } from '../../hooks/useFilteredSchemaProper import { ReviewStepProps } from '@backstage/plugin-scaffolder-react'; import { useTemplateTimeSavedMinutes } from '../../hooks/useTemplateTimeSaved'; import { JsonValue } from '@backstage/types'; -// eslint-disable-next-line @backstage/no-relative-monorepo-imports -import { useFormDecorators } from '../../../../../scaffolder/src/alpha/hooks/useFormDecorators'; const useStyles = makeStyles({ markdown: { diff --git a/plugins/scaffolder/src/alpha/hooks/useFormDecorators.test.tsx b/plugins/scaffolder/src/alpha/hooks/useFormDecorators.test.tsx index 66e2389a45..92475c3eea 100644 --- a/plugins/scaffolder/src/alpha/hooks/useFormDecorators.test.tsx +++ b/plugins/scaffolder/src/alpha/hooks/useFormDecorators.test.tsx @@ -15,13 +15,14 @@ */ import { DefaultScaffolderFormDecoratorsApi } from '../api/FormDecoratorsApi'; import { createScaffolderFormDecorator } from '@backstage/plugin-scaffolder-react/alpha'; -import { createApiRef } from '@backstage/core-plugin-api'; +import { createApiRef, errorApiRef } from '@backstage/core-plugin-api'; import { TestApiProvider } from '@backstage/test-utils'; import { renderHook, waitFor } from '@testing-library/react'; import { useFormDecorators } from './useFormDecorators'; import React from 'react'; import { formDecoratorsApiRef } from '../api/ref'; +import { TemplateParameterSchema } from '@backstage/plugin-scaffolder-react'; describe('useFormDecorators', () => { const mockApiRef = createApiRef<{ @@ -43,8 +44,14 @@ describe('useFormDecorators', () => { }, }); - it('should wrap up the form decorators', async () => { - const renderedHook = renderHook(() => useFormDecorators(), { + const manifest: TemplateParameterSchema = { + EXPERIMENTAL_formDecorators: [{ id: 'test', input: { test: 'hello' } }], + steps: [], + title: 'test', + }; + + it('should run the form decorators for a given manifest with the correct input', async () => { + const renderedHook = renderHook(() => useFormDecorators({ manifest }), { wrapper: ({ children }) => ( { decorators: [mockDecorator], }), ], + [errorApiRef, { post: () => {} }], ]} > {children} @@ -65,41 +73,12 @@ describe('useFormDecorators', () => { await waitFor(async () => { const result = renderedHook.result.current!; - expect(result.size).toBe(1); - - const testDecorator = result.get('test')!; - expect(testDecorator).toBeDefined(); - - await testDecorator.decorator({ + await result.run({ formState: {}, - setFormState: () => {}, - setSecrets: () => {}, - input: { test: 'input value' }, + secrets: {}, }); - expect(mockApiImplementation.test).toHaveBeenCalledWith('input value'); + expect(mockApiImplementation.test).toHaveBeenCalledWith('hello'); }); }); - - it('should skip failing deps', async () => { - const renderedHook = renderHook(() => useFormDecorators(), { - wrapper: ({ children }) => ( - - {children} - - ), - }); - - const result = renderedHook.result.current!; - expect(result.size).toBe(0); - }); });