Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpospiech committed Oct 23, 2024
1 parent d41421a commit e90a4da
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 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: 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

0 comments on commit e90a4da

Please sign in to comment.