Debian Codegraph @

node/@patternfly/react-table/src/components/Table/__tests__/Td.test.tsx

raw
1 import { render, screen } from '@testing-library/react';
2 import styles from '@patternfly/react-styles/css/components/Table/table';
3 import { Td } from '../Td';
4
5 test('Renders without children', () => {
6 render(
7 <table>
8 <tbody>
9 <tr>
10 <Td />
11 </tr>
12 </tbody>
13 </table>
14 );
15
16 expect(screen.getByRole('cell')).toBeInTheDocument();
17 });
18
19 test('Renders with children', () => {
20 render(
21 <table>
22 <tbody>
23 <tr>
24 <Td>Cell content</Td>
25 </tr>
26 </tbody>
27 </table>
28 );
29
30 expect(screen.getByRole('cell')).toHaveTextContent('Cell content');
31 });
32
33 test(`Applies ${styles.modifiers.action} when hasAction is true`, () => {
34 render(
35 <table>
36 <tbody>
37 <tr>
38 <Td hasAction>Cell with action</Td>
39 </tr>
40 </tbody>
41 </table>
42 );
43
44 expect(screen.getByRole('cell')).toHaveClass('pf-m-action');
45 });
46
47 test(`Does not apply ${styles.modifiers.action} when hasAction is false`, () => {
48 render(
49 <table>
50 <tbody>
51 <tr>
52 <Td hasAction={false}>Cell without action</Td>
53 </tr>
54 </tbody>
55 </table>
56 );
57
58 expect(screen.getByRole('cell')).not.toHaveClass('pf-m-action');
59 });
60
61 test('Matches snapshot without children', () => {
62 const { asFragment } = render(
63 <table>
64 <tbody>
65 <tr>
66 <Td />
67 </tr>
68 </tbody>
69 </table>
70 );
71
72 expect(asFragment()).toMatchSnapshot();
73 });
74
75 test('Matches snapshot with children', () => {
76 const { asFragment } = render(
77 <table>
78 <tbody>
79 <tr>
80 <Td>Cell content</Td>
81 </tr>
82 </tbody>
83 </table>
84 );
85
86 expect(asFragment()).toMatchSnapshot();
87 });