Skip to content

Commit

Permalink
Migrating tests WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zendranm committed Feb 9, 2024
1 parent 1a6ca83 commit 1ab1f41
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/uniforms-bootstrap3/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('@RTL', () => {
suites.testListField(theme.ListField, {
getListAddField: screen => screen.getByRole('button'),
});
suites.testListItemField(theme.ListItemField);
suites.testLongTextField(theme.LongTextField);
suites.testNestField(theme.NestField);
suites.testNumField(theme.NumField);
Expand Down
1 change: 1 addition & 0 deletions packages/uniforms-unstyled/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('@RTL', () => {
suites.testListField(theme.ListField, {
getListAddField: screen => screen.getByRole('button'),
});
suites.testListItemField(theme.ListItemField);
suites.testLongTextField(theme.LongTextField, {
skipShowInlineErrorTests: true,
});
Expand Down
60 changes: 60 additions & 0 deletions packages/uniforms/__suites__/ListItemField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { screen } from '@testing-library/react';
// import userEvent from '@testing-library/user-event';
import React, { ComponentType } from 'react';
import z from 'zod';

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

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

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

test('<ListItemField> - aaa', () => {
renderWithZod({
element: <ListItemField name="x" />,
schema: z.object({ x: z.string() }),
model: { x: 'Testttt' },
});

expect(screen.getByRole('textbox')).toHaveAttribute('value', 'Testttt');
});

// Bootstrap only
test('<ListItemField> - renders custom del field', () => {
renderWithZod({
element: (
<ListItemField
name="x"
removeIcon={<div data-testid="asdf">Test</div>}
/>
),
schema: z.object({ x: z.string() }),
});

expect(screen.getByTestId('asdf')).toBeInTheDocument();
});

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

expect(screen.getAllByRole('button')).toHaveLength(1);
});

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

expect(screen.getAllByRole('spinbutton')).toHaveLength(1);
});
}
1 change: 1 addition & 0 deletions packages/uniforms/__suites__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 1ab1f41

Please sign in to comment.