/
Label.spec.js
143 lines (101 loc) · 4.67 KB
/
Label.spec.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import React from 'react';
import { shallow } from 'enzyme';
import { Label } from '../';
describe('Label', () => {
it('should render a label tag by default', () => {
const wrapper = shallow(<Label />);
expect(wrapper.type()).toBe('label');
});
it('should render children', () => {
const wrapper = shallow(<Label>Yo!</Label>);
expect(wrapper.text()).toBe('Yo!');
});
it('should pass additional classNames', () => {
const wrapper = shallow(<Label className="extra">Yo!</Label>);
expect(wrapper.hasClass('extra')).toBe(true);
});
it('should render with "col-form-label" class when a col is provided', () => {
const wrapper = shallow(<Label sm="6">Yo!</Label>);
expect(wrapper.hasClass('col-form-label')).toBe(true);
});
it('should render with "form-label" class when a col is not provided', () => {
const wrapper = shallow(<Label>Yo!</Label>);
expect(wrapper.hasClass('form-label')).toBe(true);
});
it('should pass col size specific classes as Strings', () => {
const wrapper = shallow(<Label sm="6">Yo!</Label>);
expect(wrapper.hasClass('col-sm-6')).toBe(true);
});
it('should pass col size specific classes as Strings (auto)', () => {
const wrapper = shallow(<Label sm="auto">Yo!</Label>);
expect(wrapper.hasClass('col-sm-auto')).toBe(true);
});
it('should pass col size specific classes as Strings ("")', () => {
const wrapper = shallow(<Label sm="">Yo!</Label>);
expect(wrapper.hasClass('col-sm')).toBe(true);
});
it('should pass col size specific classes as Strings (true)', () => {
const wrapper = shallow(<Label sm>Yo!</Label>);
expect(wrapper.hasClass('col-sm')).toBe(true);
});
it('should pass col size specific classes as Strings (xs)', () => {
const wrapper = shallow(<Label xs="6">Yo!</Label>);
expect(wrapper.hasClass('col-6')).toBe(true);
});
it('should pass col size specific classes as Strings (xs="")', () => {
const wrapper = shallow(<Label xs="">Yo!</Label>);
expect(wrapper.hasClass('col')).toBe(true);
});
it('should pass col size specific classes as Strings (xs (true))', () => {
const wrapper = shallow(<Label xs>Yo!</Label>);
expect(wrapper.hasClass('col')).toBe(true);
});
it('should pass col size specific classes as Strings (xs="auto")', () => {
const wrapper = shallow(<Label xs="auto">Yo!</Label>);
expect(wrapper.hasClass('col-auto')).toBe(true);
});
it('should render with "visually-hidden" class when hidden prop is truthy', () => {
const wrapper = shallow(<Label hidden>Yo!</Label>);
expect(wrapper.hasClass('visually-hidden')).toBe(true);
});
it('should render with "col-form-label-${size}" class when size is provided', () => {
const wrapper = shallow(<Label size="lg">Yo!</Label>);
expect(wrapper.hasClass('col-form-label-lg')).toBe(true);
});
it('should pass col size specific classes as Numbers', () => {
const wrapper = shallow(<Label sm={6}>Yo!</Label>);
expect(wrapper.hasClass('col-sm-6')).toBe(true);
});
it('should pass col size specific classes as Numbers (xs)', () => {
const wrapper = shallow(<Label xs={6}>Yo!</Label>);
expect(wrapper.hasClass('col-6')).toBe(true);
});
it('should pass col size specific classes via Objects', () => {
const wrapper = shallow(<Label sm={{ size: 6, order: 2, offset: 2 }}>Yo!</Label>);
expect(wrapper.hasClass('col-sm-6')).toBe(true);
expect(wrapper.hasClass('order-sm-2')).toBe(true);
expect(wrapper.hasClass('offset-sm-2')).toBe(true);
});
it('should pass col size specific classes via Objects (xs)', () => {
const wrapper = shallow(<Label xs={{ size: 6, order: 2, offset: 2 }}>Yo!</Label>);
expect(wrapper.hasClass('col-6')).toBe(true);
expect(wrapper.hasClass('order-2')).toBe(true);
expect(wrapper.hasClass('offset-2')).toBe(true);
});
it('should pass multiple col size specific classes via Objects', () => {
const wrapper = shallow(<Label xs={{ size: 4, order: 3, offset: 3 }} sm={{ size: 6, order: 2, offset: 2 }} md={{ size: 7, order: 1, offset: 1 }}>Yo!</Label>);
expect(wrapper.hasClass('col-4')).toBe(true);
expect(wrapper.hasClass('order-3')).toBe(true);
expect(wrapper.hasClass('offset-3')).toBe(true);
expect(wrapper.hasClass('col-sm-6')).toBe(true);
expect(wrapper.hasClass('order-sm-2')).toBe(true);
expect(wrapper.hasClass('offset-sm-2')).toBe(true);
expect(wrapper.hasClass('col-md-7')).toBe(true);
expect(wrapper.hasClass('order-md-1')).toBe(true);
expect(wrapper.hasClass('offset-md-1')).toBe(true);
});
it('should render custom tag', () => {
const wrapper = shallow(<Label tag="main">Yo!</Label>);
expect(wrapper.type()).toBe('main');
});
});