From abbdf52d3b80bd29bda351145e2dbccdce1dff87 Mon Sep 17 00:00:00 2001 From: Volodymyr Zakhovaiko Date: Sat, 24 Feb 2024 22:54:31 +0100 Subject: [PATCH] Added few more tests --- packages/uniforms/__suites__/SelectField.tsx | 57 +++++++++++++++++--- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/packages/uniforms/__suites__/SelectField.tsx b/packages/uniforms/__suites__/SelectField.tsx index acb95742c..8ef8ea3af 100644 --- a/packages/uniforms/__suites__/SelectField.tsx +++ b/packages/uniforms/__suites__/SelectField.tsx @@ -110,7 +110,7 @@ export function testSelectField( if (options?.antdTests) { expect(selectField.getAttribute('name')).toBe('x'); } else if (options?.skipInMuiTests) { - expect(screen.getByText('X')).toBeDefined(); + expect(screen.getByText('X')).toBeInTheDocument(); } else { const select = selectField.querySelector('select'); expect(select?.getAttribute('name')).toBe('x'); @@ -173,11 +173,44 @@ export function testSelectField( expect(select.querySelector('option')?.getAttribute('disabled')).toBeNull(); }); - // test(' - renders a set of checkboxes', () => {}); + test(' - renders a set of checkboxes', () => { + renderWithZod({ + element: , + schema: z.object({ x: z.enum(['a', 'b']) }), + }); + const checkboxes = + options?.skipInMuiTests || options?.antdTests + ? screen.getByText('X').closest('body')?.querySelectorAll('input') + : screen.getAllByRole('checkbox'); + expect(checkboxes).toHaveLength(2); + }); - // test(' - renders a set of checkboxes with correct disabled state', () => {}); + test(' - renders a set of checkboxes with correct disabled state', () => { + renderWithZod({ + element: , + schema: z.object({ x: z.enum(['a', 'b']) }), + }); + const checkboxes = + options?.skipInMuiTests || options?.antdTests + ? screen.getByText('X').closest('body')?.querySelectorAll('input') + : screen.getAllByRole('checkbox'); + expect(checkboxes?.[0]).toBeDisabled(); + expect(checkboxes?.[1]).toBeDisabled(); + }); - // test(' - renders a set of checkboxes with correct readOnly state', () => {}); + test(' - renders a set of checkboxes with correct readOnly state', () => { + const onChange = jest.fn(); + renderWithZod({ + element: , + schema: z.object({ x: z.enum(['a', 'b']) }), + }); + const checkboxes = + options?.skipInMuiTests || options?.antdTests + ? screen.getByText('X').closest('body')?.querySelectorAll('input') + : screen.getAllByRole('checkbox'); + checkboxes?.[1].click(); + expect(onChange).not.toHaveBeenCalled(); + }); // TODO: refactor a bit test(' - renders a set of checkboxes with correct id (inherited)', () => { @@ -196,7 +229,7 @@ export function testSelectField( expect(checkboxes?.[0]).toHaveAttribute('id'); }); - test.only(' - renders a set of checkboxes with correct id (specified)', () => { + test(' - renders a set of checkboxes with correct id (specified)', () => { renderWithZod({ element: , schema: z.object({ x: z.enum(['a', 'b']) }), @@ -234,7 +267,19 @@ export function testSelectField( // test(' - renders a set of checkboxes with correct value (specified)', () => {}); - // test(' - renders a set of checkboxes which correctly reacts on change', () => {}); + test(' - renders a set of checkboxes which correctly reacts on change', () => { + renderWithZod({ + element: , + schema: z.object({ x: z.enum(['a', 'b']) }), + }); + const checkbox = + options?.antdTests || options?.skipInMuiTests + ? screen.getByDisplayValue('b') + : screen.getByRole('checkbox', { name: 'b' }); + expect(checkbox).not.toBeChecked(); + checkbox?.click(); + expect(checkbox).toBeChecked(); + }); // test(' - renders a set of checkboxes which correctly reacts on change (array check)', () => {});