chore: working out the review step a little more

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-08-19 13:23:16 +02:00
parent 784673638a
commit d8e317e661
4 changed files with 15 additions and 11 deletions
@@ -16,6 +16,7 @@
import React from 'react';
import { ReviewState } from './ReviewState';
import { render } from '@testing-library/react';
import { ParsedTemplateSchema } from './useTemplateSchema';
describe('ReviewState', () => {
it('should render the text as normal with no options', () => {
@@ -38,7 +39,7 @@ describe('ReviewState', () => {
test: 'bob',
};
const schemas = [
const schemas: ParsedTemplateSchema[] = [
{
mergedSchema: {
type: 'object',
@@ -49,6 +50,10 @@ describe('ReviewState', () => {
},
},
},
schema: {},
title: 'test',
uiSchema: {},
description: 'asd',
},
];
@@ -47,17 +47,17 @@ describe('Stepper', () => {
title: 'React JSON Schema Form Test',
};
const { getByText } = await renderInTestApp(
const { getByRole } = await renderInTestApp(
<Stepper manifest={manifest} extensions={[]} />,
);
expect(getByText('Next')).toBeInTheDocument();
expect(getByRole('button', { name: 'Next' })).toBeInTheDocument();
await act(async () => {
await fireEvent.click(getByText('Next'));
await fireEvent.click(getByRole('button', { name: 'Next' }));
});
expect(getByText('Review')).toBeInTheDocument();
expect(getByRole('button', { name: 'Review' })).toBeInTheDocument();
});
it('should remember the state of the form when cycling through the pages', async () => {
@@ -87,7 +87,7 @@ describe('Stepper', () => {
title: 'React JSON Schema Form Test',
};
const { getByRole, getByText } = await renderInTestApp(
const { getByRole } = await renderInTestApp(
<Stepper manifest={manifest} extensions={[]} />,
);
@@ -96,11 +96,11 @@ describe('Stepper', () => {
});
await act(async () => {
await fireEvent.click(getByText('Next'));
await fireEvent.click(getByRole('button', { name: 'Next' }));
});
await act(async () => {
await fireEvent.click(getByText('Back'));
await fireEvent.click(getByRole('button', { name: 'Back' }));
});
expect(getByRole('textbox', { name: 'name' })).toHaveValue(
@@ -75,8 +75,7 @@ export const Stepper = (props: StepperProps) => {
}, [props.extensions]);
const validation = useMemo(() => {
const { mergedSchema } = steps[activeStep] ?? {};
return createAsyncValidators(mergedSchema, validators, {
return createAsyncValidators(steps[activeStep].mergedSchema, validators, {
apiHolder,
});
}, [steps, activeStep, validators, apiHolder]);
@@ -28,7 +28,7 @@ export interface ParsedTemplateSchema {
}
export const useTemplateSchema = (
manifest: TemplateParameterSchema,
): { steps: ParsedTemplateSchema } => {
): { steps: ParsedTemplateSchema[] } => {
const featureFlags = useApi(featureFlagsApiRef);
const steps = manifest.steps.map(({ title, description, schema }) => ({
title,