forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormLabelSpec.js
93 lines (82 loc) · 2.6 KB
/
FormLabelSpec.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
import React from 'react';
import { mount } from 'enzyme';
import FormLabel from '../src/FormLabel';
import FormGroup from '../src/FormGroup';
import { shouldWarn } from './helpers';
describe('<FormLabel>', () => {
it('should render correctly', () => {
mount(
<FormLabel id="foo" name="bar" className="my-control" />,
).assertSingle('label#foo.form-label.my-control[name="bar"]');
});
it('should use controlId for htmlFor', () => {
mount(
<FormGroup controlId="foo">
<FormLabel type="text" />
</FormGroup>,
).assertSingle('label[htmlFor="foo"].form-label');
});
it('should render as a Col', () => {
mount(
<FormLabel column sm={4}>
Label
</FormLabel>,
).assertSingle('label.col-sm-4.col-form-label');
});
it('should use controlId for htmlFor when render as Col', () => {
mount(
<FormGroup controlId="foo">
<FormLabel column sm={4} />
</FormGroup>,
).assertSingle('label[htmlFor="foo"].col-sm-4.col-form-label');
});
it('should respect srOnly', () => {
mount(<FormLabel srOnly>Label</FormLabel>).assertSingle(
'label.form-label.sr-only',
);
});
it('should prefer explicit htmlFor', () => {
shouldWarn('ignored');
mount(
<FormGroup controlId="foo">
<FormLabel type="text" htmlFor="bar" />
</FormGroup>,
).assertSingle('label[htmlFor="bar"]');
});
it('should support ref forwarding', () => {
class Container extends React.Component {
render() {
return (
<FormGroup controlId="foo">
<FormLabel
type="text"
ref={(ref) => {
this.input = ref;
}}
/>
</FormGroup>
);
}
}
const instance = mount(<Container />).instance();
expect(instance.input.tagName).to.equal('LABEL');
});
it('accepts as prop', () => {
mount(<FormLabel as="legend">body</FormLabel>).assertSingle('legend');
});
it('should properly size itself when rendered as a Col', () => {
mount(<FormLabel column="sm">Label</FormLabel>).assertSingle(
'label.col-form-label.col-form-label-sm',
);
mount(<FormLabel column>Label</FormLabel>).assertSingle(
'label.col-form-label',
);
mount(<FormLabel column="lg">Label</FormLabel>).assertSingle(
'label.col-form-label.col-form-label-lg',
);
let labelComponent = mount(<FormLabel>Label</FormLabel>);
labelComponent.assertNone('label.col-form-label');
labelComponent.assertNone('label.col-form-label-sm');
labelComponent.assertNone('label.col-form-label-lg');
});
});