fix: review changes

Signed-off-by: Federico Morreale <frc.morreale@gmail.com>
This commit is contained in:
Federico Morreale
2023-11-14 10:32:59 +01:00
parent e516bf4da8
commit 64358b0980
2 changed files with 53 additions and 4 deletions
@@ -112,6 +112,54 @@ describe('Stepper', () => {
);
});
it('should remember the state of the form when cycling through the pages by directly clicking on the step labels', async () => {
const manifest: TemplateParameterSchema = {
steps: [
{
title: 'Step 1',
schema: {
properties: {
name: {
type: 'string',
},
},
},
},
{
title: 'Step 2',
schema: {
properties: {
description: {
type: 'string',
},
},
},
},
],
title: 'React JSON Schema Form Test',
};
const { getByRole, getByLabelText } = await renderInTestApp(
<Stepper manifest={manifest} extensions={[]} onCreate={jest.fn()} />,
);
await fireEvent.change(getByRole('textbox', { name: 'name' }), {
target: { value: 'im a test value' },
});
await act(async () => {
await fireEvent.click(getByRole('button', { name: 'Next' }));
});
await act(async () => {
await fireEvent.click(getByLabelText('Step 1'));
});
expect(getByRole('textbox', { name: 'name' })).toHaveValue(
'im a test value',
);
});
it('should merge nested formData correctly in multiple steps', async () => {
const Repo = ({
onChange,
@@ -192,13 +192,14 @@ export const Stepper = (stepperProps: StepperProps) => {
{isValidating && <LinearProgress variant="indeterminate" />}
<MuiStepper activeStep={activeStep} alternativeLabel variant="elevation">
{steps.map((step, index) => {
const isAllowedTitleClick = activeStep > index;
const isAllowedLabelClick = activeStep > index;
return (
<MuiStep key={step.title}>
<MuiStep key={index}>
<MuiStepLabel
style={{ cursor: isAllowedTitleClick ? 'pointer' : 'text' }}
aria-label={`Step ${index + 1}`}
style={{ cursor: isAllowedLabelClick ? 'pointer' : 'default' }}
onClick={() => {
if (isAllowedTitleClick) setActiveStep(index);
if (isAllowedLabelClick) setActiveStep(index);
}}
>
{step.title}