forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTh.test.tsx
More file actions
56 lines (41 loc) · 1.72 KB
/
Copy pathTh.test.tsx
File metadata and controls
56 lines (41 loc) · 1.72 KB
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
import { render, screen } from '@testing-library/react';
import { Th } from '../Th';
test('Does not render with aria-label by default', () => {
render(<Th />);
expect(screen.getByRole('columnheader')).not.toHaveAccessibleName();
});
test('Renders with aria-label when passed in', () => {
render(<Th aria-label="Test" />);
expect(screen.getByRole('columnheader')).toHaveAccessibleName('Test');
});
test('Does not render with screen reader text by default', () => {
render(<Th />);
expect(screen.getByRole('columnheader')).toBeEmptyDOMElement();
});
test('Does not render with screen reader text when children are passed in', () => {
render(<Th screenReaderText="Test">Heading label</Th>);
expect(screen.getByRole('columnheader')).not.toHaveTextContent('Test');
});
test('Renders with screen reader text when screenReaderText is passed in', () => {
render(<Th screenReaderText="Test" />);
expect(screen.getByRole('columnheader')).toHaveTextContent('Test');
});
test('Does not render with additional content by default', () => {
render(<Th />);
expect(screen.getByRole('columnheader')).toBeEmptyDOMElement();
});
test('Render with additional content when additionalContent is passed in', () => {
render(<Th additionalContent={<div>Extra</div>}>Test</Th>);
expect(screen.getByRole('columnheader')).toHaveTextContent('Extra');
});
test('Additional content renders after children when additionalContent is passed in', () => {
render(
<Th additionalContent={<div>Extra</div>}>
<div>Test</div>
</Th>
);
const th = screen.getByRole('columnheader');
const thChildren = th.children;
expect(thChildren.item(0)?.textContent).toEqual('Test');
expect(thChildren.item(1)?.textContent).toEqual('Extra');
});