1 | import React from 'react';
|
2 | import { render, screen } from '@testing-library/react';
|
3 | import user from '@testing-library/user-event';
|
4 | import { ListGroupItem } from '..';
|
5 | import { testForChildrenInComponent, testForDefaultClass } from '../testUtils';
|
6 |
|
7 | describe('ListGroupItem', () => {
|
8 | it('should render children', () => {
|
9 | testForChildrenInComponent(ListGroupItem);
|
10 | });
|
11 |
|
12 | it('should render with "list-group-item" class', () => {
|
13 | testForDefaultClass(ListGroupItem, 'list-group-item');
|
14 | });
|
15 |
|
16 | it('should render with "active" class when active is passed', () => {
|
17 | render(<ListGroupItem active>Yo!</ListGroupItem>);
|
18 | expect(screen.getByText('Yo!')).toHaveClass('active');
|
19 | });
|
20 |
|
21 | it('should render with "disabled" class when disabled is passed', () => {
|
22 | render(<ListGroupItem disabled>Yo!</ListGroupItem>);
|
23 | expect(screen.getByText('Yo!')).toHaveClass('disabled');
|
24 | });
|
25 |
|
26 | it('should render with "list-group-item-action" class when action is passed', () => {
|
27 | render(<ListGroupItem action>Yo!</ListGroupItem>);
|
28 | expect(screen.getByText('Yo!')).toHaveClass('list-group-item-action');
|
29 | });
|
30 |
|
31 | it('should render with "list-group-item-${color}" class when color is passed', () => {
|
32 | render(<ListGroupItem color="success">Yo!</ListGroupItem>);
|
33 | expect(screen.getByText('Yo!')).toHaveClass('list-group-item-success');
|
34 | });
|
35 |
|
36 | it('should prevent click event when disabled is passed', () => {
|
37 | const onDisableClick = jest.fn();
|
38 | render(
|
39 | <ListGroupItem disabled onClick={onDisableClick}>
|
40 | Yo!
|
41 | </ListGroupItem>,
|
42 | );
|
43 |
|
44 | user.click(screen.getByText('Yo!'));
|
45 | expect(onDisableClick).not.toHaveBeenCalled();
|
46 | });
|
47 | });
|