From 87aada5823082a31a497c09e49b4fb924fce7979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Po=C5=9Bpiech?= Date: Fri, 16 Feb 2024 13:37:26 +0100 Subject: [PATCH] moved test from suites to tests --- packages/uniforms-antd/__tests__/index.ts | 5 +-- packages/uniforms-material/__tests__/index.ts | 4 +- packages/uniforms-mui/__tests__/index.ts | 4 +- .../uniforms/__suites__/ListItemField.tsx | 40 +++++-------------- 4 files changed, 12 insertions(+), 41 deletions(-) diff --git a/packages/uniforms-antd/__tests__/index.ts b/packages/uniforms-antd/__tests__/index.ts index 348024350..30c9151dc 100644 --- a/packages/uniforms-antd/__tests__/index.ts +++ b/packages/uniforms-antd/__tests__/index.ts @@ -48,10 +48,7 @@ describe('@RTL', () => { suites.testListField(theme.ListField, { getListAddField: screen => screen.getByRole('img', { name: 'plus-square' }), }); - suites.testListItemField(theme.ListItemField, { - isSelectCombobox: true, - useInputAsSelectField: true, - }); + suites.testListItemField(theme.ListItemField); suites.testLongTextField(theme.LongTextField); // FIXME: AntD number input doesn't work with new RTL test implementation // suites.testNumField(antd.NumField); diff --git a/packages/uniforms-material/__tests__/index.ts b/packages/uniforms-material/__tests__/index.ts index e3fb7bbdd..bcb6a4090 100644 --- a/packages/uniforms-material/__tests__/index.ts +++ b/packages/uniforms-material/__tests__/index.ts @@ -50,9 +50,7 @@ describe('@RTL', () => { suites.testListField(theme.ListField, { getListAddField: screen => screen.getByText(/\+/), }); - suites.testListItemField(theme.ListItemField, { - useInputAsSelectField: true, - }); + suites.testListItemField(theme.ListItemField); suites.testLongTextField(theme.LongTextField); suites.testNestField(theme.NestField, { skipInMuiTests: true }); suites.testNumField(theme.NumField); diff --git a/packages/uniforms-mui/__tests__/index.ts b/packages/uniforms-mui/__tests__/index.ts index 281a1c0be..f4b8e164b 100644 --- a/packages/uniforms-mui/__tests__/index.ts +++ b/packages/uniforms-mui/__tests__/index.ts @@ -47,9 +47,7 @@ describe('@RTL', () => { suites.testListField(theme.ListField, { getListAddField: screen => screen.getByText(/\+/), }); - suites.testListItemField(theme.ListItemField, { - useInputAsSelectField: true, - }); + suites.testListItemField(theme.ListItemField); suites.testLongTextField(theme.LongTextField); suites.testNestField(theme.NestField, { skipInMuiTests: true }); suites.testNumField(theme.NumField); diff --git a/packages/uniforms/__suites__/ListItemField.tsx b/packages/uniforms/__suites__/ListItemField.tsx index 8065f3798..da636928d 100644 --- a/packages/uniforms/__suites__/ListItemField.tsx +++ b/packages/uniforms/__suites__/ListItemField.tsx @@ -4,13 +4,7 @@ import z from 'zod'; import { renderWithZod } from './render-zod'; -export function testListItemField( - ListItemField: ComponentType, - options?: { - isSelectCombobox?: boolean; - useInputAsSelectField?: boolean; - }, -) { +export function testListItemField(ListItemField: ComponentType) { test(' - works', () => { renderWithZod({ element: , @@ -30,36 +24,20 @@ export function testListItemField( }); test(' - renders AutoField', () => { - const { container } = renderWithZod({ + const AutoField = jest.fn(() => null) as React.FC; + + renderWithZod({ element: ( - <> - - - - + + + ), schema: z.object({ - string: z.string(), - number: z.number(), - select: z.enum(['a', 'b']), + field: z.string(), }), }); - if (options?.useInputAsSelectField) { - expect(container.getElementsByTagName('input')).toHaveLength(3); - - if (options?.isSelectCombobox) { - expect(screen.getByRole('combobox')).toBeInTheDocument(); - } else { - expect(container.getElementsByTagName('input')?.[2]).toHaveAttribute( - 'name', - 'select', - ); - } - } else { - expect(container.getElementsByTagName('input')).toHaveLength(2); - expect(container.getElementsByTagName('select')).toHaveLength(1); - } + expect(AutoField).toHaveBeenCalledTimes(1); }); test(' - renders children if specified', () => {