Skip to content

Commit

Permalink
Removed setting initial value for enum type (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpospiech authored Oct 29, 2024
1 parent 36eb052 commit 38c3acf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/uniforms-bridge-zod/__tests__/ZodBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('ZodBridge', () => {
it('works with enum (array)', () => {
const schema = object({ a: enum_(['x', 'y', 'z']) });
const bridge = new ZodBridge({ schema });
expect(bridge.getInitialValue('a')).toEqual('x');
expect(bridge.getInitialValue('a')).toEqual(undefined);
});

it('works with enum (native, numbers)', () => {
Expand Down
4 changes: 0 additions & 4 deletions packages/uniforms-bridge-zod/src/ZodBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ export default class ZodBridge<T extends ZodRawShape> extends Bridge {
return field._def.defaultValue();
}

if (field instanceof ZodEnum) {
return field.options[0];
}

if (field instanceof ZodNativeEnum) {
const values = Object.values(field.enum as Record<string, unknown>);
return values.find(isNativeEnumValue) ?? values[0];
Expand Down
4 changes: 2 additions & 2 deletions packages/uniforms-mui/__tests__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('@RTL - SelectField tests', () => {
schema: z.object({ x: z.enum(['a', 'b']) }),
});

expect(screen.getByText('a')).toBeInTheDocument();
expect(screen.queryByText('a')).not.toBeInTheDocument();
expect(screen.queryByText('b')).not.toBeInTheDocument();
});

Expand Down Expand Up @@ -233,7 +233,7 @@ describe('@RTL - SelectField tests', () => {
schema: z.object({ x: z.enum(['a', 'b']) }),
});

expect(screen.getByLabelText('a *')).toBeChecked();
expect(screen.getByLabelText('a *')).not.toBeChecked();
expect(screen.getByLabelText('b *')).not.toBeChecked();
});

Expand Down
5 changes: 3 additions & 2 deletions packages/uniforms/__suites__/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function testRadioField(
schema: z.object({ x: z.enum(['a', 'b']) }),
});

expect(screen.getAllByRole('radio')[0]).toHaveAttribute('checked');
expect(screen.getAllByRole('radio')[0]).not.toHaveAttribute('checked');
expect(screen.getAllByRole('radio')[1]).not.toHaveAttribute('checked');
});

Expand Down Expand Up @@ -161,8 +161,9 @@ export function testRadioField(
onChange,
});
await userEvent.click(screen.getByRole('radio', { name: 'a' }));
await userEvent.click(screen.getByRole('radio', { name: 'a' }));

expect(onChange).not.toHaveBeenCalled();
expect(onChange).toHaveBeenCalledTimes(1);
});

test('<RadioField> - renders a label', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/uniforms/__suites__/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function testSelectField(
element: <SelectField name="x" label="y" />,
schema: z.object({ x: z.enum(['a', 'b']) }),
});
expect(screen.getByText('y')).toBeInTheDocument();
expect(screen.getByLabelText(/y\*?/)).toBeInTheDocument();
});

skipTestIf(isTheme(['mui', 'antd']))(
Expand Down Expand Up @@ -237,7 +237,7 @@ export function testSelectField(
element: <SelectField name="x" label="y" placeholder="" />,
schema: z.object({ x: z.enum(['a', 'b']) }),
});
expect(screen.getByText('y')).toBeInTheDocument();
expect(screen.queryByPlaceholderText('y')).not.toBeInTheDocument();
});

skipTestIf(isTheme(['antd', 'mui']))(
Expand All @@ -260,10 +260,10 @@ export function testSelectField(
});
const select = screen.getByRole('combobox');
if (options?.theme === 'antd') {
expect(screen.getByText('a')).toBeInTheDocument();
expect(screen.queryByText('a')).not.toBeInTheDocument();
expect(screen.queryByText('b')).not.toBeInTheDocument();
} else {
expect(select).toHaveValue('a');
expect(select).not.toHaveValue();
}
},
);
Expand Down Expand Up @@ -538,7 +538,7 @@ export function testSelectField(
const checkboxes = fields.filter(
element => element instanceof HTMLInputElement,
);
expect(checkboxes?.[0]).toBeChecked();
expect(checkboxes?.[0]).not.toBeChecked();
expect(checkboxes?.[1]).not.toBeChecked();
});

Expand Down

0 comments on commit 38c3acf

Please sign in to comment.