1 | import React from 'react';
|
2 | import {Simulate} from 'react-dom/test-utils';
|
3 | import {shallow, mount} from 'enzyme';
|
4 |
|
5 | import {Radio} from './radio__item';
|
6 |
|
7 | describe('Radio Item', () => {
|
8 | function noop() {}
|
9 |
|
10 | const factory = props => (
|
11 | <Radio
|
12 | checked={false}
|
13 | onChange={noop}
|
14 | value="test"
|
15 | {...props}
|
16 | >
|
17 | {'test'}
|
18 | </Radio>
|
19 | );
|
20 | const mountRadioItem = props => mount(factory(props));
|
21 | const shallowRadioItem = props => shallow(factory(props));
|
22 |
|
23 | it('should create component', () => {
|
24 | shallowRadioItem().should.exist;
|
25 | });
|
26 |
|
27 | it('should render radio item', () => {
|
28 | mountRadioItem().instance().input.should.have.property('type', 'radio');
|
29 | });
|
30 |
|
31 | it('should generate id if not passed', () => {
|
32 | mountRadioItem().instance().input.should.have.property('id');
|
33 | });
|
34 |
|
35 | it('should generate unique id', () => {
|
36 | const firstRadioItem = mountRadioItem();
|
37 | const secondRadioItem = mountRadioItem();
|
38 | const secondRadioId = secondRadioItem.instance().input.getAttribute('id');
|
39 | firstRadioItem.instance().input.should.not.have.id(secondRadioId);
|
40 | });
|
41 |
|
42 | it('should set custom id', () => {
|
43 | const radioItem = mountRadioItem({
|
44 | id: 'test'
|
45 | });
|
46 |
|
47 | radioItem.instance().input.should.have.id('test');
|
48 | });
|
49 |
|
50 | it('should set name', () => {
|
51 | const radioItem = mountRadioItem({
|
52 | name: 'test'
|
53 | });
|
54 |
|
55 | radioItem.instance().input.should.have.property('name', 'test');
|
56 | });
|
57 |
|
58 | it('should call handler for click event', () => {
|
59 | const clickHandler = sandbox.stub();
|
60 | const radioItem = mountRadioItem({
|
61 | onClick: clickHandler
|
62 | });
|
63 |
|
64 | Simulate.click(radioItem.instance().input);
|
65 | clickHandler.should.have.been.called;
|
66 | });
|
67 |
|
68 | it('should be unchecked by default', () => {
|
69 | const radioItem = mountRadioItem();
|
70 |
|
71 | radioItem.instance().input.should.not.have.property('checked', true);
|
72 | });
|
73 |
|
74 | it('should check control', () => {
|
75 | const radioItem = mountRadioItem({
|
76 | checked: true,
|
77 | onChange: () => {}
|
78 | });
|
79 |
|
80 | radioItem.instance().input.should.have.property('checked', true);
|
81 | });
|
82 |
|
83 | it('should be disabled', () => {
|
84 | const radioItem = mountRadioItem({
|
85 | disabled: true
|
86 | });
|
87 |
|
88 | radioItem.instance().input.should.be.disabled;
|
89 | });
|
90 |
|
91 |
|
92 | it('should connect labels with input by id', () => {
|
93 | const radioItem = mountRadioItem();
|
94 | const id = radioItem.instance().input.getAttribute('id');
|
95 |
|
96 | radioItem.instance().label.should.have.attribute('for', id);
|
97 | });
|
98 | });
|