1 | import React from 'react';
|
2 | import {Simulate} from 'react-dom/test-utils';
|
3 | import {shallow, mount} from 'enzyme';
|
4 |
|
5 | import Checkbox from './checkbox';
|
6 |
|
7 | describe('Checkbox', () => {
|
8 | const shallowCheckbox = props => shallow(<Checkbox {...props}/>);
|
9 | const mountCheckbox = props => mount(<Checkbox {...props}/>);
|
10 |
|
11 | it('should create component', () => {
|
12 | shallowCheckbox().should.exist;
|
13 | });
|
14 |
|
15 | it('should render checkbox', () => {
|
16 | const checkbox = mountCheckbox().instance();
|
17 | checkbox.input.should.have.property('type', 'checkbox');
|
18 | });
|
19 |
|
20 | it('should set name', () => {
|
21 | const checkbox = mountCheckbox({name: 'test'}).instance();
|
22 |
|
23 | checkbox.input.should.have.property('name', 'test');
|
24 | });
|
25 |
|
26 | it('should call handler for click event', () => {
|
27 | const clickHandler = sandbox.stub();
|
28 |
|
29 | const checkbox = mountCheckbox({onClick: clickHandler}).instance();
|
30 | Simulate.click(checkbox.input);
|
31 |
|
32 | clickHandler.should.have.been.called;
|
33 | });
|
34 |
|
35 | it('should not call handler on change event if disabled', () => {
|
36 | const onChange = sandbox.stub();
|
37 |
|
38 | const checkbox = shallowCheckbox({
|
39 | disabled: true,
|
40 | onChange
|
41 | });
|
42 |
|
43 | checkbox.simulate('click');
|
44 | onChange.should.have.not.been.called;
|
45 | });
|
46 |
|
47 | it('should be unchecked by default', () => {
|
48 | const checkbox = shallowCheckbox();
|
49 |
|
50 | checkbox.should.not.be.checked();
|
51 | });
|
52 |
|
53 | it('should check control', () => {
|
54 | const checkbox = mountCheckbox({defaultChecked: true}).instance();
|
55 |
|
56 | checkbox.input.should.be.checked;
|
57 | });
|
58 |
|
59 | it('should be disabled', () => {
|
60 | const checkbox = mountCheckbox({
|
61 | disabled: true
|
62 | }).instance();
|
63 |
|
64 | checkbox.input.should.be.disabled;
|
65 | });
|
66 |
|
67 | it('should check control on change event', () => {
|
68 | const eventMock = {
|
69 | target: {
|
70 | checked: true
|
71 | }
|
72 | };
|
73 | const checkbox = mountCheckbox().instance();
|
74 |
|
75 | Simulate.change(checkbox.input, eventMock);
|
76 | checkbox.input.should.be.checked;
|
77 | });
|
78 | });
|