/
InputGroup.spec.js
74 lines (54 loc) · 2.22 KB
/
InputGroup.spec.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 React, { useState } from 'react';
import { shallow, mount } from 'enzyme';
import { InputGroup, DropdownMenu, DropdownToggle, DropdownItem, Input } from '../';
import Dropdown from '../Dropdown';
describe('InputGroup', () => {
it('should render with "div" tag', () => {
const wrapper = shallow(<InputGroup>Yo!</InputGroup>);
expect(wrapper.type()).toBe('div');
});
it('should render children', () => {
const wrapper = shallow(<InputGroup>Yo!</InputGroup>);
expect(wrapper.text()).toBe('Yo!');
});
it('should render with "input-group" class', () => {
const wrapper = shallow(<InputGroup>Yo!</InputGroup>);
expect(wrapper.hasClass('input-group')).toBe(true);
});
it('should render with "input-group-${size}" class when size is passed', () => {
const wrapper = shallow(<InputGroup size="whatever">Yo!</InputGroup>);
expect(wrapper.hasClass('input-group-whatever')).toBe(true);
});
it('should render additional classes', () => {
const wrapper = shallow(<InputGroup className="other">Yo!</InputGroup>);
expect(wrapper.hasClass('other')).toBe(true);
expect(wrapper.hasClass('input-group')).toBe(true);
});
it('should render custom tag', () => {
const wrapper = shallow(<InputGroup tag="main">Yo!</InputGroup>);
expect(wrapper.type()).toBe('main');
});
describe('When type="dropdown"', () => {
it('should render Dropdown', () => {
const wrapper = shallow(<InputGroup type="dropdown" />);
expect(wrapper.type()).toBe(Dropdown);
});
it('should call toggle when input is clicked', () => {
jest.spyOn(Dropdown.prototype, 'toggle');
const wrapper = mount(
<InputGroup type="dropdown" isOpen={true} toggle={() => {}}>
<Input />
<DropdownToggle>Toggle</DropdownToggle>
<DropdownMenu right>
<DropdownItem>Test</DropdownItem>
<DropdownItem id="divider" divider />
</DropdownMenu>
</InputGroup>
, { attachTo: document.body });
expect(Dropdown.prototype.toggle.mock.calls.length).toBe(0);
document.querySelector('input.form-control').click();
expect(Dropdown.prototype.toggle.mock.calls.length).toBe(1);
wrapper.detach();
});
});
});