-
-
Notifications
You must be signed in to change notification settings - Fork 239
/
wrapField.tsx
75 lines (61 loc) · 1.98 KB
/
wrapField.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react';
import { mount } from 'enzyme';
import { wrapField } from 'uniforms-bootstrap4';
test('<wrapField> - renders wrapper with correct class', () => {
const element = wrapField({ wrapClassName: 'container' }, <div />);
const wrapper = mount(element);
expect(wrapper.find('.container')).toHaveLength(1);
});
test('<wrapField> - renders help block', () => {
const element = wrapField({ help: 'Hint' }, <div />);
const wrapper = mount(element);
expect(wrapper.find('.form-text').text()).toBe('Hint');
});
test('<wrapField> - renders help block with specified class', () => {
const element = wrapField(
{ help: 'Hint', helpClassName: 'text-hint' },
<div />,
);
const wrapper = mount(element);
expect(wrapper.find('.form-text.text-hint')).toHaveLength(1);
});
test('<wrapField> - renders error block', () => {
const error = new Error();
const element = wrapField(
{ error, showInlineError: true, errorMessage: 'Error' },
<div />,
);
const wrapper = mount(element);
expect(wrapper.find('.text-danger').text()).toBe('Error');
});
test('<wrapField> - renders error block (showInlineError=false)', () => {
const error = new Error();
const element = wrapField(
{ error, showInlineError: false, errorMessage: 'Error' },
<div />,
);
const wrapper = mount(element);
expect(wrapper.find('.text-danger')).toHaveLength(0);
});
test('<wrapField> - label has custom class (String)', () => {
const element = wrapField(
{
label: 'A field label',
labelClassName: 'custom-label-class',
},
<div />,
);
const wrapper = mount(element);
expect(wrapper.find('label.custom-label-class')).toHaveLength(1);
});
test('<wrapField> - label has custom class (Array[String])', () => {
const element = wrapField(
{
label: 'A field label',
labelClassName: ['custom-1', 'custom-2'],
},
<div />,
);
const wrapper = mount(element);
expect(wrapper.find('label.custom-1.custom-2')).toHaveLength(1);
});