Skip to content

Commit

Permalink
Migrated ListItemField tests to @testing-library/react (#1304)
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Pośpiech <[email protected]>
zendranm and piotrpospiech authored Feb 23, 2024
1 parent 9ae8eb5 commit eed59c6
Showing 18 changed files with 49 additions and 416 deletions.
52 changes: 0 additions & 52 deletions packages/uniforms-antd/__tests__/ListItemField.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/uniforms-antd/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ describe('@RTL', () => {
testTooltip: true,
testStyle: 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);
52 changes: 0 additions & 52 deletions packages/uniforms-bootstrap3/__tests__/ListItemField.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/uniforms-bootstrap3/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ describe('@RTL', () => {
getListAddField: screen => screen.getByRole('button'),
disableInlineError: true,
});
suites.testListItemField(theme.ListItemField);
suites.testLongTextField(theme.LongTextField);
suites.testNestField(theme.NestField);
suites.testNumField(theme.NumField);
52 changes: 0 additions & 52 deletions packages/uniforms-bootstrap4/__tests__/ListItemField.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/uniforms-bootstrap4/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ describe('@RTL', () => {
getListAddField: screen => screen.getByRole('button'),
disableInlineError: true,
});
suites.testListItemField(theme.ListItemField);
suites.testLongTextField(theme.LongTextField);
suites.testNestField(theme.NestField);
suites.testNumField(theme.NumField);
52 changes: 0 additions & 52 deletions packages/uniforms-bootstrap5/__tests__/ListItemField.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/uniforms-bootstrap5/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ describe('@RTL', () => {
getListAddField: screen => screen.getByRole('button'),
disableInlineError: true,
});
suites.testListItemField(theme.ListItemField);
suites.testLongTextField(theme.LongTextField, {
testMinMaxLength: true,
});
52 changes: 0 additions & 52 deletions packages/uniforms-material/__tests__/ListItemField.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/uniforms-material/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ describe('@RTL', () => {
getListAddField: screen => screen.getByText(/\+/),
testError: false,
});
suites.testListItemField(theme.ListItemField);
suites.testLongTextField(theme.LongTextField);
suites.testNestField(theme.NestField, { skipInMuiTests: true });
suites.testNumField(theme.NumField);
52 changes: 0 additions & 52 deletions packages/uniforms-mui/__tests__/ListItemField.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/uniforms-mui/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ describe('@RTL', () => {
getListAddField: screen => screen.getByText(/\+/),
testError: false,
});
suites.testListItemField(theme.ListItemField);
suites.testLongTextField(theme.LongTextField);
suites.testNestField(theme.NestField, { skipInMuiTests: true });
suites.testNumField(theme.NumField);
52 changes: 0 additions & 52 deletions packages/uniforms-semantic/__tests__/ListItemField.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/uniforms-semantic/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ describe('@RTL', () => {
getListAddField: screen => screen.getByRole('button'),
disableInlineError: true,
});
suites.testListItemField(theme.ListItemField);
suites.testLongTextField(theme.LongTextField);
suites.testNestField(theme.NestField);
suites.testNumField(theme.NumField);
52 changes: 0 additions & 52 deletions packages/uniforms-unstyled/__tests__/ListItemField.tsx

This file was deleted.

1 change: 1 addition & 0 deletions packages/uniforms-unstyled/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ describe('@RTL', () => {
getListAddField: screen => screen.getByRole('button'),
testError: false,
});
suites.testListItemField(theme.ListItemField);
suites.testLongTextField(theme.LongTextField, {
skipShowInlineErrorTests: true,
});
40 changes: 40 additions & 0 deletions packages/uniforms/__suites__/ListItemField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { screen } from '@testing-library/react';
import React, { ComponentType } from 'react';
import z from 'zod';

import { renderWithZod } from './render-zod';

export function testListItemField(ListItemField: ComponentType<any>) {
test('<ListItemField> - works', () => {
renderWithZod({
element: <ListItemField name="field" />,
schema: z.object({ field: z.string().optional() }),
});

expect(screen.getByLabelText('Field')).toBeInTheDocument();
});

test('<ListItemField> - renders ListDelField', () => {
renderWithZod({
element: <ListItemField name="field" />,
schema: z.object({ field: z.string() }),
});

expect(screen.getByRole('button')).toBeInTheDocument();
});

test('<ListItemField> - renders children if specified', () => {
const Child = jest.fn(() => <div />) as React.FC<any>;

renderWithZod({
element: (
<ListItemField name="field">
<Child />
</ListItemField>
),
schema: z.object({ field: z.string() }),
});

expect(Child).toHaveBeenCalledTimes(1);
});
}
1 change: 1 addition & 0 deletions packages/uniforms/__suites__/index.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ export * from './HiddenField';
export * from './ListAddField';
export * from './ListDelField';
export * from './ListField';
export * from './ListItemField';
export * from './LongTextField';
export * from './NestField';
export * from './NumField';

0 comments on commit eed59c6

Please sign in to comment.