-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathTimeZoneToggle.test.js
37 lines (30 loc) · 1.47 KB
/
TimeZoneToggle.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
import React from 'react';
import { mount } from 'enzyme';
import TimeZoneToggle from '../TimeZoneToggle.react';
describe('TimeZoneToggle', () => {
it('should render UTC text when value is false', () => {
const wrapper = mount(<TimeZoneToggle value={false} onChange={() => {}} />);
expect(wrapper.find('.option').text()).toBe('UTC');
expect(wrapper.find('.switch').hasClass('left')).toBe(true);
});
it('should render Local text when value is true', () => {
const wrapper = mount(<TimeZoneToggle value={true} onChange={() => {}} />);
expect(wrapper.find('.option').text()).toBe('Local');
expect(wrapper.find('.switch').hasClass('right')).toBe(true);
});
it('should call onChange with opposite value when clicked', () => {
const onChange = jest.fn();
const wrapper = mount(<TimeZoneToggle value={false} onChange={onChange} />);
wrapper.find('.container').simulate('click');
expect(onChange).toHaveBeenCalledWith(true);
wrapper.setProps({ value: true });
wrapper.find('.container').simulate('click');
expect(onChange).toHaveBeenCalledWith(false);
});
it('should have correct background color based on value', () => {
const wrapper = mount(<TimeZoneToggle value={false} onChange={() => {}} />);
expect(wrapper.find('.switch').prop('style').backgroundColor).toBe('rgb(204, 204, 204)');
wrapper.setProps({ value: true });
expect(wrapper.find('.switch').prop('style').backgroundColor).toBe('rgb(0, 219, 124)');
});
});