Skip to content

Commit

Permalink
rewritten few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zaxovaiko committed Apr 19, 2024
1 parent f955d8f commit e16db3c
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 99 deletions.
3 changes: 3 additions & 0 deletions packages/uniforms-antd/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ describe('@RTL', () => {
suites.testTextField(theme.TextField);
suites.testValidatedForm(theme.ValidatedForm);
suites.testValidatedQuickForm(theme.ValidatedQuickForm);
suites.testWrapField(theme.wrapField, {
skipForAntD: true,
});
});
75 changes: 0 additions & 75 deletions packages/uniforms-antd/__tests__/wrapField.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/uniforms-bootstrap3/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ describe('@RTL', () => {
suites.testTextField(theme.TextField, { testWrapClassName: true });
suites.testValidatedForm(theme.ValidatedForm);
suites.testValidatedQuickForm(theme.ValidatedQuickForm);
suites.testWrapField(theme.wrapField, { feedbackable: true });
suites.testWrapField(theme.wrapField, { onlyForBootstrap3: true });
});
150 changes: 127 additions & 23 deletions packages/uniforms/__suites__/wrapField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export function testWrapField(
wrapField: (wrapperProps: any, children: ReactNode) => ReactElement,
options?: {
skipForMUI?: boolean;
feedbackable?: boolean;
skipForAntD?: boolean;
onlyForBootstrap3?: boolean;
},
) {
skipTestIf(!options?.feedbackable)(
skipTestIf(!options?.onlyForBootstrap3)(
'<wrapField> - renders wrapper with (feedbackable=true)',
() => {
const error = new Error();
Expand Down Expand Up @@ -43,7 +44,7 @@ export function testWrapField(
).toBe(true);
});

skipTestIf(options?.skipForMUI)(
skipTestIf(options?.skipForMUI || options?.skipForAntD)(
'<wrapField> - renders wrapper with correct class',
() => {
renderWithZod({
Expand All @@ -70,7 +71,7 @@ export function testWrapField(
expect(screen.getByText('Hint')).toBeInTheDocument();
});

skipTestIf(options?.skipForMUI)(
skipTestIf(options?.skipForMUI || options?.skipForAntD)(
'<wrapField> - renders help block with specified class',
() => {
renderWithZod({
Expand All @@ -97,25 +98,18 @@ export function testWrapField(
expect(screen.getByText('Error')).toBeInTheDocument();
});

// FIXME: fix
// skipTestIf(options?.skipForMUI)(
// '<wrapField> - renders error block (showInlineError=false)',
// () => {
// // TODO: Add proper test for this
// const error = new Error();
// renderWithZod({
// element: wrapField(
// { error, showInlineError: false, errorMessage: 'Error' },
// <div />,
// ),
// schema: z.object({}),
// });
// screen.debug();
// // expect(wrapper.find('.text-danger')).toHaveLength(0);
// },
// );

skipTestIf(options?.skipForMUI)(
'<wrapField> - renders wrapper with label',
() => {
renderWithZod({
element: wrapField({ label: 'Label' }, <div />),
schema: z.object({}),
});
expect(screen.getByText('Label')).toBeInTheDocument();
},
);

skipTestIf(options?.skipForMUI || options?.skipForAntD)(
'<wrapField> - label has custom class (String)',
() => {
renderWithZod({
Expand All @@ -130,7 +124,7 @@ export function testWrapField(
},
);

skipTestIf(options?.skipForMUI)(
skipTestIf(options?.skipForMUI || options?.skipForAntD)(
'<wrapField> - label has custom class (Array[String])',
() => {
renderWithZod({
Expand All @@ -145,4 +139,114 @@ export function testWrapField(
expect(label.classList.contains('custom-2')).toBe(true);
},
);

skipTestIf(!options?.skipForAntD)(
'<wrapField> - renders wrapper with a custom validateStatus',
() => {
renderWithZod({
element: wrapField(
{ validateStatus: 'success' },
<div data-testid="x" />,
),
schema: z.object({}),
});
expect(
screen
.getByTestId('x')
.closest('.ant-form-item-has-feedback.ant-form-item-has-success'),
).toBeInTheDocument();
},
);

skipTestIf(!options?.skipForAntD)(
'<wrapField> - renders wrapper with extra style',
() => {
renderWithZod({
element: wrapField(
{ wrapperStyle: { backgroundColor: 'red' } },
<div data-testid="x" />,
),
schema: z.object({}),
});
expect(
screen
.getByTestId('x')
.closest('.ant-form-item')
?.getAttribute('style'),
).toBe('background-color: red;');
},
);

skipTestIf(options?.skipForMUI)(
'<wrapField> - renders wrapper with extra text',
() => {
renderWithZod({
element: wrapField({ extra: 'Extra' }, <div data-testid="x" />),
schema: z.object({}),
});
if (options?.skipForAntD) {
expect(screen.getByText('Extra')).toBeInTheDocument();
} else {
expect(screen.getByTestId('x').parentElement).toHaveAttribute('extra');
}
},
);

skipTestIf(!options?.skipForAntD)(
'<wrapField> - renders wrapper with an error status (error)',
() => {
const error = new Error();
renderWithZod({
element: wrapField({ error }, <div data-testid="x" />),
schema: z.object({}),
});
expect(
screen
.getByTestId('x')
.closest('.ant-form-item-has-feedback.ant-form-item-has-error'),
).toBeInTheDocument();
},
);

skipTestIf(options?.skipForMUI)(
'<wrapField> - renders error block (showInlineError=false)',
() => {
const error = new Error();
renderWithZod({
element: wrapField(
{ error, showInlineError: false, errorMessage: 'Error' },
<div data-testid="x" />,
),
schema: z.object({}),
});
if (options?.skipForAntD) {
expect(
screen
.getByTestId('x')
.closest('.ant-form-item-has-feedback.ant-form-item-has-error'),
).toBeInTheDocument();
} else {
expect(
screen
.getByTestId('x')
.parentElement?.classList.contains(
options?.onlyForBootstrap3 ? 'has-error' : 'is-invalid',
),
).toBe(true);
}
},
);

skipTestIf(!options?.skipForAntD)(
'<wrapField> - renders wrapper with label and info',
() => {
renderWithZod({
element: wrapField({ label: 'Label', info: 'Info' }, <div />),
schema: z.object({}),
});
expect(screen.getByRole('img').getAttribute('aria-label')).toBe(
'question-circle',
);
},
);
}

0 comments on commit e16db3c

Please sign in to comment.