1 | import React from 'react';
|
2 | import { render, screen } from '@testing-library/react';
|
3 | import user from '@testing-library/user-event';
|
4 | import '@testing-library/jest-dom';
|
5 | import {
|
6 | InputGroup,
|
7 | DropdownMenu,
|
8 | DropdownToggle,
|
9 | DropdownItem,
|
10 | Input,
|
11 | } from '..';
|
12 | import Dropdown from '../Dropdown';
|
13 | import {
|
14 | testForChildrenInComponent,
|
15 | testForCustomClass,
|
16 | testForCustomTag,
|
17 | testForDefaultClass,
|
18 | testForDefaultTag,
|
19 | } from '../testUtils';
|
20 |
|
21 | describe('InputGroup', () => {
|
22 | it('should render with "div" tag', () => {
|
23 | testForDefaultTag(InputGroup, 'div');
|
24 | });
|
25 |
|
26 | it('should render children', () => {
|
27 | testForChildrenInComponent(InputGroup);
|
28 | });
|
29 |
|
30 | it('should render with "input-group" class', () => {
|
31 | testForDefaultClass(InputGroup, 'input-group');
|
32 | });
|
33 |
|
34 | it('should render with "input-group-${size}" class when size is passed', () => {
|
35 | render(<InputGroup size="whatever">Yo!</InputGroup>);
|
36 |
|
37 | expect(screen.getByText(/yo!/i)).toHaveClass('input-group-whatever');
|
38 | });
|
39 |
|
40 | it('should render additional classes', () => {
|
41 | testForCustomClass(InputGroup);
|
42 | });
|
43 |
|
44 | it('should render custom tag', () => {
|
45 | testForCustomTag(InputGroup);
|
46 | });
|
47 |
|
48 | describe('When type="dropdown"', () => {
|
49 | it('should render Dropdown', () => {
|
50 | render(<InputGroup type="dropdown" data-testid="drpdwn" />);
|
51 | expect(screen.getByTestId('drpdwn')).toHaveClass('dropdown');
|
52 | });
|
53 |
|
54 | it('should call toggle when input is clicked', () => {
|
55 | const toggle = jest.fn();
|
56 |
|
57 | render(
|
58 | <InputGroup type="dropdown" isOpen toggle={toggle}>
|
59 | <Input />
|
60 | <DropdownToggle>Toggle</DropdownToggle>
|
61 | <DropdownMenu right>
|
62 | <DropdownItem>Test</DropdownItem>
|
63 | <DropdownItem id="divider" divider />
|
64 | </DropdownMenu>
|
65 | </InputGroup>,
|
66 | );
|
67 |
|
68 | expect(toggle).not.toBeCalled();
|
69 | user.click(document.querySelector('input.form-control'));
|
70 | expect(toggle).toBeCalled();
|
71 | });
|
72 | });
|
73 | });
|