1 | import React from 'react';
|
2 | import '@testing-library/jest-dom';
|
3 | import { screen, render } from '@testing-library/react';
|
4 | import { Table } from '..';
|
5 | import {
|
6 | testForCustomClass,
|
7 | testForCustomTag,
|
8 | testForDefaultClass,
|
9 | } from '../testUtils';
|
10 |
|
11 | describe('Table', () => {
|
12 | it('should render with "table" class', () => {
|
13 | testForDefaultClass(Table, 'table');
|
14 | });
|
15 |
|
16 | it('should render additional classes', () => {
|
17 | testForCustomClass(Table);
|
18 | });
|
19 |
|
20 | it('should render custom tag', () => {
|
21 | testForCustomTag(Table);
|
22 | });
|
23 |
|
24 | it('should render modifier classes', () => {
|
25 | render(<Table data-testid="table" size="sm" bordered striped dark hover />);
|
26 | const node = screen.getByTestId('table');
|
27 | expect(node).toHaveClass('table');
|
28 | expect(node).toHaveClass('table-sm');
|
29 | expect(node).toHaveClass('table-bordered');
|
30 | expect(node).toHaveClass('table-striped');
|
31 | expect(node).toHaveClass('table-hover');
|
32 | expect(node).toHaveClass('table-dark');
|
33 | });
|
34 |
|
35 | it('should render a borderless table', () => {
|
36 | render(<Table data-testid="table" borderless />);
|
37 | expect(screen.getByTestId('table')).toHaveClass('table');
|
38 | expect(screen.getByTestId('table')).toHaveClass('table-borderless');
|
39 | });
|
40 |
|
41 | it('should render responsive wrapper class', () => {
|
42 | render(<Table data-testid="table" responsive />);
|
43 | expect(screen.getByTestId('table')).toHaveClass('table');
|
44 | expect(screen.getByTestId('table').parentNode).toHaveClass(
|
45 | 'table-responsive',
|
46 | );
|
47 | });
|
48 |
|
49 | it('should render responsive wrapper class for md', () => {
|
50 | render(<Table data-testid="table" responsive="md" />);
|
51 | expect(screen.getByTestId('table')).toHaveClass('table');
|
52 | expect(screen.getByTestId('table').parentNode).toHaveClass(
|
53 | 'table-responsive-md',
|
54 | );
|
55 | });
|
56 |
|
57 | it('should render responsive wrapper cssModule', () => {
|
58 | const cssModule = {
|
59 | table: 'scopedTable',
|
60 | 'table-responsive': 'scopedResponsive',
|
61 | };
|
62 | render(<Table data-testid="table" responsive cssModule={cssModule} />);
|
63 | expect(screen.getByTestId('table')).toHaveClass('scopedTable');
|
64 | expect(screen.getByTestId('table').parentNode).toHaveClass(
|
65 | 'scopedResponsive',
|
66 | );
|
67 | });
|
68 | });
|