forked from openedx/paragon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableHeaderRow.test.jsx
More file actions
81 lines (66 loc) · 2.08 KB
/
Copy pathTableHeaderRow.test.jsx
File metadata and controls
81 lines (66 loc) · 2.08 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React from 'react';
import { render, screen } from '@testing-library/react';
import TableHeaderRow from '../TableHeaderRow';
const header1Name = 'Name';
const header2Name = 'DOB';
const props = {
headerGroups: [{
getHeaderGroupProps: () => ({ className: 'red', key: '1' }),
headers: [
{
Header: header1Name,
getHeaderProps: () => ({ className: 'bears', key: '1' }),
render: () => header1Name,
isSorted: false,
isSortedDesc: false,
getSortByToggleProps: () => ({}),
canSort: false,
},
{
Header: header2Name,
getHeaderProps: () => ({ className: 'bears', key: '2' }),
render: () => header2Name,
isSorted: false,
isSortedDesc: false,
getSortByToggleProps: () => ({}),
canSort: true,
},
],
}],
};
function renderTableHeaderRow() {
render(<table><TableHeaderRow {...props} /></table>);
}
describe('<TableHeaderRow />', () => {
it('renders a table head and row', () => {
renderTableHeaderRow();
const head = screen.getByRole('rowgroup');
const row = screen.getByRole('row');
expect(head).toBeInTheDocument();
expect(row).toBeInTheDocument();
});
it('adds props to the row', () => {
renderTableHeaderRow();
const row = screen.getByRole('row');
expect(row.className).toEqual('red');
});
it('renders cells', () => {
renderTableHeaderRow();
const cells = screen.getAllByRole('columnheader');
expect(cells.length).toEqual(2);
expect(cells[0]).toHaveTextContent(header1Name);
expect(cells[1]).toHaveTextContent(header2Name);
});
it('does not spread React keys from react-table prop getters', () => {
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
try {
renderTableHeaderRow();
const keySpreadWarning = consoleError.mock.calls.some(([message]) => (
String(message).includes('A props object containing a "key" prop')
));
expect(keySpreadWarning).toEqual(false);
} finally {
consoleError.mockRestore();
}
});
});