From f955d8f1c308ede2bc88c374837017563f0a5474 Mon Sep 17 00:00:00 2001 From: Volodymyr Zakhovaiko Date: Fri, 19 Apr 2024 13:57:28 +0200 Subject: [PATCH] Added missing test for bootstrap3 --- .../uniforms-bootstrap3/__tests__/index.ts | 2 +- .../__tests__/wrapField.tsx | 84 ------------------- .../__tests__/wrapField.tsx | 76 ----------------- .../__tests__/wrapField.tsx | 76 ----------------- .../uniforms-material/__tests__/wrapField.tsx | 35 -------- packages/uniforms-mui/__tests__/wrapField.tsx | 35 -------- packages/uniforms/__suites__/index.ts | 2 + packages/uniforms/__suites__/wrapField.tsx | 20 +++++ 8 files changed, 23 insertions(+), 307 deletions(-) delete mode 100644 packages/uniforms-bootstrap3/__tests__/wrapField.tsx delete mode 100644 packages/uniforms-bootstrap4/__tests__/wrapField.tsx delete mode 100644 packages/uniforms-bootstrap5/__tests__/wrapField.tsx delete mode 100644 packages/uniforms-material/__tests__/wrapField.tsx delete mode 100644 packages/uniforms-mui/__tests__/wrapField.tsx diff --git a/packages/uniforms-bootstrap3/__tests__/index.ts b/packages/uniforms-bootstrap3/__tests__/index.ts index 66d974e35..a815e2fb7 100644 --- a/packages/uniforms-bootstrap3/__tests__/index.ts +++ b/packages/uniforms-bootstrap3/__tests__/index.ts @@ -63,5 +63,5 @@ describe('@RTL', () => { suites.testTextField(theme.TextField, { testWrapClassName: true }); suites.testValidatedForm(theme.ValidatedForm); suites.testValidatedQuickForm(theme.ValidatedQuickForm); - suites.testWrapField(theme.wrapField); + suites.testWrapField(theme.wrapField, { feedbackable: true }); }); diff --git a/packages/uniforms-bootstrap3/__tests__/wrapField.tsx b/packages/uniforms-bootstrap3/__tests__/wrapField.tsx deleted file mode 100644 index 9089eec21..000000000 --- a/packages/uniforms-bootstrap3/__tests__/wrapField.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import React from 'react'; -import { wrapField } from 'uniforms-bootstrap3'; - -import mount from './_mount'; - -test(' - renders wrapper with correct class', () => { - const element = wrapField({ wrapClassName: 'container' },
); - const wrapper = mount(element); - - expect(wrapper.find('.container')).toHaveLength(1); -}); - -test(' - renders help block', () => { - const element = wrapField({ help: 'Hint' },
); - const wrapper = mount(element); - - expect(wrapper.find('.help-block').text()).toBe('Hint'); -}); - -test(' - renders help block with specified class', () => { - const element = wrapField( - { help: 'Hint', helpClassName: 'text-hint' }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('.help-block.text-hint')).toHaveLength(1); -}); - -test(' - renders error block', () => { - const error = new Error(); - const element = wrapField( - { error, showInlineError: true, errorMessage: 'Error' }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('.help-block').text()).toBe('Error'); -}); - -test(' - renders error block (feedbackable)', () => { - const error = new Error(); - const element = wrapField({ error, feedbackable: true },
); - const wrapper = mount(element); - - expect(wrapper.find('.form-control-feedback')).toHaveLength(1); -}); - -test(' - renders error block (showInlineError=false)', () => { - const error = new Error(); - const element = wrapField( - { error, showInlineError: false, errorMessage: 'Error' }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('.help-block')).toHaveLength(0); -}); - -test(' - label has custom class (String)', () => { - const element = wrapField( - { - label: 'A field label', - labelClassName: 'custom-label-class', - }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('label.custom-label-class')).toHaveLength(1); -}); - -test(' - label has custom class (Array[String])', () => { - const element = wrapField( - { - label: 'A field label', - labelClassName: ['custom-1', 'custom-2'], - }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('label.custom-1.custom-2')).toHaveLength(1); -}); diff --git a/packages/uniforms-bootstrap4/__tests__/wrapField.tsx b/packages/uniforms-bootstrap4/__tests__/wrapField.tsx deleted file mode 100644 index ec97accf1..000000000 --- a/packages/uniforms-bootstrap4/__tests__/wrapField.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import React from 'react'; -import { wrapField } from 'uniforms-bootstrap4'; - -import mount from './_mount'; - -test(' - renders wrapper with correct class', () => { - const element = wrapField({ wrapClassName: 'container' },
); - const wrapper = mount(element); - - expect(wrapper.find('.container')).toHaveLength(1); -}); - -test(' - renders help block', () => { - const element = wrapField({ help: 'Hint' },
); - const wrapper = mount(element); - - expect(wrapper.find('.form-text').text()).toBe('Hint'); -}); - -test(' - renders help block with specified class', () => { - const element = wrapField( - { help: 'Hint', helpClassName: 'text-hint' }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('.form-text.text-hint')).toHaveLength(1); -}); - -test(' - renders error block', () => { - const error = new Error(); - const element = wrapField( - { error, showInlineError: true, errorMessage: 'Error' }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('.text-danger').text()).toBe('Error'); -}); - -test(' - renders error block (showInlineError=false)', () => { - const error = new Error(); - const element = wrapField( - { error, showInlineError: false, errorMessage: 'Error' }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('.text-danger')).toHaveLength(0); -}); - -test(' - label has custom class (String)', () => { - const element = wrapField( - { - label: 'A field label', - labelClassName: 'custom-label-class', - }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('label.custom-label-class')).toHaveLength(1); -}); - -test(' - label has custom class (Array[String])', () => { - const element = wrapField( - { - label: 'A field label', - labelClassName: ['custom-1', 'custom-2'], - }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('label.custom-1.custom-2')).toHaveLength(1); -}); diff --git a/packages/uniforms-bootstrap5/__tests__/wrapField.tsx b/packages/uniforms-bootstrap5/__tests__/wrapField.tsx deleted file mode 100644 index 88b7b8bbd..000000000 --- a/packages/uniforms-bootstrap5/__tests__/wrapField.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import React from 'react'; -import { wrapField } from 'uniforms-bootstrap5'; - -import mount from './_mount'; - -test(' - renders wrapper with correct class', () => { - const element = wrapField({ wrapClassName: 'container' },
); - const wrapper = mount(element); - - expect(wrapper.find('.container')).toHaveLength(1); -}); - -test(' - renders help block', () => { - const element = wrapField({ help: 'Hint' },
); - const wrapper = mount(element); - - expect(wrapper.find('.form-text').text()).toBe('Hint'); -}); - -test(' - renders help block with specified class', () => { - const element = wrapField( - { help: 'Hint', helpClassName: 'text-hint' }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('.form-text.text-hint')).toHaveLength(1); -}); - -test(' - renders error block', () => { - const error = new Error(); - const element = wrapField( - { error, showInlineError: true, errorMessage: 'Error' }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('.text-danger').text()).toBe('Error'); -}); - -test(' - renders error block (showInlineError=false)', () => { - const error = new Error(); - const element = wrapField( - { error, showInlineError: false, errorMessage: 'Error' }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('.text-danger')).toHaveLength(0); -}); - -test(' - label has custom class (String)', () => { - const element = wrapField( - { - label: 'A field label', - labelClassName: 'custom-label-class', - }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('label.custom-label-class')).toHaveLength(1); -}); - -test(' - label has custom class (Array[String])', () => { - const element = wrapField( - { - label: 'A field label', - labelClassName: ['custom-1', 'custom-2'], - }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find('label.custom-1.custom-2')).toHaveLength(1); -}); diff --git a/packages/uniforms-material/__tests__/wrapField.tsx b/packages/uniforms-material/__tests__/wrapField.tsx deleted file mode 100644 index 27f25020f..000000000 --- a/packages/uniforms-material/__tests__/wrapField.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import FormControl from '@material-ui/core/FormControl'; -import FormHelperText from '@material-ui/core/FormHelperText'; -import React from 'react'; -import { wrapField } from 'uniforms-material'; - -import mount from './_mount'; - -test(' - renders wrapper', () => { - const element = wrapField({},
); - const wrapper = mount(element); - - expect(wrapper.find(FormControl)).toHaveLength(1); -}); - -test(' - renders wrapper with helper text', () => { - const element = wrapField({ helperText: 'Helper text' },
); - const wrapper = mount(element); - - expect(wrapper.find(FormHelperText).text()).toBe('Helper text'); -}); - -test(' - renders wrapper with error', () => { - const element = wrapField( - { - showInlineError: true, - error: new Error(), - errorMessage: 'Error message', - }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find(FormControl).prop('error')).toBe(true); - expect(wrapper.find(FormHelperText).text()).toBe('Error message'); -}); diff --git a/packages/uniforms-mui/__tests__/wrapField.tsx b/packages/uniforms-mui/__tests__/wrapField.tsx deleted file mode 100644 index af882cc7a..000000000 --- a/packages/uniforms-mui/__tests__/wrapField.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import FormControl from '@mui/material/FormControl'; -import FormHelperText from '@mui/material/FormHelperText'; -import React from 'react'; -import { wrapField } from 'uniforms-mui'; - -import mount from './_mount'; - -test(' - renders wrapper', () => { - const element = wrapField({},
); - const wrapper = mount(element); - - expect(wrapper.find(FormControl)).toHaveLength(1); -}); - -test(' - renders wrapper with helper text', () => { - const element = wrapField({ helperText: 'Helper text' },
); - const wrapper = mount(element); - - expect(wrapper.find(FormHelperText).text()).toBe('Helper text'); -}); - -test(' - renders wrapper with error', () => { - const element = wrapField( - { - showInlineError: true, - error: new Error(), - errorMessage: 'Error message', - }, -
, - ); - const wrapper = mount(element); - - expect(wrapper.find(FormControl).prop('error')).toBe(true); - expect(wrapper.find(FormHelperText).text()).toBe('Error message'); -}); diff --git a/packages/uniforms/__suites__/index.ts b/packages/uniforms/__suites__/index.ts index dbb71d992..5b5921d47 100644 --- a/packages/uniforms/__suites__/index.ts +++ b/packages/uniforms/__suites__/index.ts @@ -16,6 +16,8 @@ export * from './NestField'; export * from './NumField'; export * from './QuickForm'; export * from './RadioField'; +export * from './render-zod'; +export * from './render'; export * from './SelectField'; export * from './SubmitField'; export * from './TextField'; diff --git a/packages/uniforms/__suites__/wrapField.tsx b/packages/uniforms/__suites__/wrapField.tsx index 45ce59353..08e5cd036 100644 --- a/packages/uniforms/__suites__/wrapField.tsx +++ b/packages/uniforms/__suites__/wrapField.tsx @@ -9,8 +9,28 @@ export function testWrapField( wrapField: (wrapperProps: any, children: ReactNode) => ReactElement, options?: { skipForMUI?: boolean; + feedbackable?: boolean; }, ) { + skipTestIf(!options?.feedbackable)( + ' - renders wrapper with (feedbackable=true)', + () => { + const error = new Error(); + renderWithZod({ + element: wrapField( + { error, feedbackable: true }, +
, + ), + schema: z.object({}), + }); + const x = screen.getByTestId('x'); + expect(x.parentElement?.classList.contains('has-feedback')).toBe(true); + expect( + x.nextElementSibling?.classList.contains('form-control-feedback'), + ).toBe(true); + }, + ); + skipTestIf(!options?.skipForMUI)(' - renders wrapper', () => { renderWithZod({ element: wrapField({},
),