Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed setting initial value for enum type #1354

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -76,7 +76,7 @@ test('<SelectField> - renders a Select with correct value (default)', () => {
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 @@ -232,7 +232,7 @@ test('<SelectField checkboxes> - renders a set of Radio buttons with correct val
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 @@ -29,7 +29,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 @@ -228,7 +228,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 @@ -251,10 +251,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 @@ -522,7 +522,7 @@ export function testSelectField(
const checkboxes = screen
.getAllByRole(/checkbox|radio/)
.filter(element => element instanceof HTMLInputElement);
expect(checkboxes?.[0]).toBeChecked();
expect(checkboxes?.[0]).not.toBeChecked();
expect(checkboxes?.[1]).not.toBeChecked();
});

Expand Down
Loading