This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
IconToggle.spec.tsx
99 lines (86 loc) · 3.05 KB
/
IconToggle.spec.tsx
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
94
95
96
97
98
99
import * as React from 'react';
import { mount, shallow } from 'enzyme';
import { iconToggleDriverFactory } from './IconToggle.driver';
import { createDriverFactory } from 'wix-ui-test-utils/driver-factory';
import { IconToggle, LabelPlacement } from '.';
import { iconToggleTestkitFactory } from '../../testkit';
import { isTestkitExists } from 'wix-ui-test-utils/vanilla';
import { isEnzymeTestkitExists } from 'wix-ui-test-utils/enzyme';
import { iconToggleTestkitFactory as enzymeAutocompleteTestkitFactory } from '../../testkit/enzyme';
import { ReactComponent as Heart } from '../../assets/icons/Heart.svg';
const ICON = <Heart />;
const LABEL = 'Like';
describe('IconToggle', () => {
const createDriver = createDriverFactory(iconToggleDriverFactory);
it('should render', () => {
const driver = createDriver(<IconToggle icon={ICON} />);
expect(driver.exists()).toBe(true);
});
it('should render label', () => {
const driver = createDriver(<IconToggle icon={ICON} label={LABEL} />);
expect(driver.getLabel().textContent).toBe(LABEL);
});
it('should not render label when empty', () => {
const driver = createDriver(<IconToggle icon={ICON} label="" />);
expect(driver.getLabel()).toBe(null);
});
it('should render label at start', () => {
const driver = createDriver(
<IconToggle
icon={ICON}
label={LABEL}
labelPlacement={LabelPlacement.START}
/>,
);
expect(driver.getLabelPlacement()).toBe(LabelPlacement.START);
});
it('by default should render label at end', () => {
const driver = createDriver(<IconToggle icon={ICON} label={LABEL} />);
expect(driver.getLabelPlacement()).toBe(LabelPlacement.END);
});
it('should render icon', () => {
const driver = createDriver(<IconToggle icon={ICON} />);
expect(driver.getIcon().innerHTML).toBe(shallow(ICON).html());
});
it('should call onChange with actual value', () => {
const onChangeSpy = jest.fn();
onChangeSpy.mockImplementation(() => Promise.resolve());
const driver = createDriver(
<IconToggle icon={<div />} onChange={onChangeSpy} />,
);
expect(onChangeSpy).not.toHaveBeenCalled();
driver.click();
expect(onChangeSpy).toHaveBeenCalledWith(
expect.objectContaining({ checked: true }),
);
});
it('should be disabled', () => {
const driver = createDriver(<IconToggle icon={<div />} disabled />);
expect(driver.isDisabled()).toBe(true);
});
it('should be checked', () => {
const driver = createDriver(<IconToggle icon={<div />} checked />);
expect(driver.isChecked()).toBe(true);
});
describe('testkit', () => {
it('should exist', () => {
expect(
isTestkitExists(
<IconToggle icon={<div />} />,
iconToggleTestkitFactory,
),
).toBe(true);
});
});
describe('enzyme testkit', () => {
it('should exist', () => {
expect(
isEnzymeTestkitExists(
<IconToggle icon={<div />} />,
enzymeAutocompleteTestkitFactory,
mount,
),
).toBe(true);
});
});
});