-
-
Notifications
You must be signed in to change notification settings - Fork 268
/
Copy pathSwitch.test.js
74 lines (68 loc) · 2.74 KB
/
Switch.test.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
import expect from 'expect'
import React from 'react'
import {renderToStaticMarkup as render} from 'react-dom/server'
import { configure, mount, shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { spy, mock } from 'sinon'
import CSwitch from 'src/CSwitch'
configure({ adapter: new Adapter() });
describe('CSwitch', () => {
it('renders label with class="c-switch"', () => {
expect(render(<CSwitch />))
.toContain('<label class="c-switch')
});
it('should render with c-switch class', () => {
const wrapper = shallow(<CSwitch />);
expect(wrapper.hasClass('c-switch')).toBe(true);
});
it('should render with outline class', () => {
const wrapper = shallow(<CSwitch outline />);
expect(wrapper.hasClass('c-switch-outline-secondary')).toBe(true);
});
it('should render with outline alt class', () => {
const wrapper = shallow(<CSwitch outline={'alt'} />);
expect(wrapper.hasClass('c-switch-outline-secondary-alt')).toBe(true);
});
it('should render with outline alt class', () => {
const wrapper = shallow(<CSwitch outline color="primary-alt" />);
expect(wrapper.hasClass('c-switch-outline-primary-alt')).toBe(true);
});
it('should render with info class', () => {
const wrapper = shallow(<CSwitch color="info" />);
expect(wrapper.hasClass('c-switch-info')).toBe(true);
});
it('should render with pill class', () => {
const wrapper = shallow(<CSwitch variant="pill" />);
expect(wrapper.hasClass('c-switch-pill')).toBe(true);
});
it('should render with 3d class', () => {
const wrapper = shallow(<CSwitch variant="3d" />);
expect(wrapper.hasClass('c-switch-3d')).toBe(true);
});
it('should render with lg class', () => {
const wrapper = shallow(<CSwitch size="lg" />);
expect(wrapper.hasClass('c-switch-lg')).toBe(true);
});
it('should render with label class', () => {
const wrapper = shallow(<CSwitch label />);
expect(wrapper.hasClass('c-switch-label')).toBe(true);
});
describe('onChange', () => {
it('calls props.onChange if it exists', () => {
const onChangeMock = mock()
const wrapper = mount(<CSwitch onChange={onChangeMock} />);
wrapper.find('input').hostNodes().simulate('change');
expect(onChangeMock.called).toBe(true);
});
it('should call handleChange()', () => {
const onChange = spy(CSwitch.prototype, 'handleChange');
const event = { target: { checked: true } };
const wrapper = shallow(<CSwitch label size="lg" />);
expect(wrapper.find('input').props().checked).toBe(false);
wrapper.find('input').simulate('change', event)
expect(onChange.called).toBe(true);
expect(wrapper.find('input').props().checked).toBe(true);
})
}
)
})