HeadRow.test.tsx
2.25 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
82
83
84
85
import { RenderResult } from '@testing-library/react';
import { DayPickerProps } from 'DayPicker';
import { customRender } from 'test/render';
import { HeadRow } from './HeadRow';
let container: HTMLElement;
let view: RenderResult;
let thElements: HTMLTableCellElement[];
function setup(dayPickerProps: DayPickerProps = {}) {
view = customRender(
<table>
<thead>
<HeadRow />
</thead>
</table>,
dayPickerProps
);
container = view.container.firstChild?.firstChild as HTMLTableRowElement;
thElements = Array.from(container.getElementsByTagName('th'));
}
const dayPickerProps = {
styles: {
head: { color: 'red' },
head_row: { color: 'blue' },
head_cell: { color: 'green' }
},
classNames: {
head: 'foo',
head_row: 'foo_row',
head_cell: 'foo_head-cell'
}
};
describe('when rendered', () => {
beforeEach(() => {
setup(dayPickerProps);
});
test('tr element should have the `head_row` style', () => {
expect(container.firstChild).toHaveStyle(dayPickerProps.styles.head_row);
});
test('tr element should have the `head_row` class', () => {
expect(container.firstChild).toHaveClass(
dayPickerProps.classNames.head_row
);
});
test('should render 7 head elements', () => {
expect(thElements).toHaveLength(7);
});
test('should render the head elements with the "head_cell" class name', () => {
thElements.forEach((el) => {
expect(el).toHaveClass(dayPickerProps.classNames.head_cell);
});
});
});
describe('when showing the week numbers', () => {
beforeEach(() => {
setup({ ...dayPickerProps, showWeekNumber: true });
});
test('should render 8 head elements', () => {
expect(thElements).toHaveLength(7);
});
test('should render the head elements with the "head_cell" class name', () => {
thElements.forEach((el) => {
expect(el).toHaveClass(dayPickerProps.classNames.head_cell);
});
});
test('should render the head elements with the "head_cell" style', () => {
thElements.forEach((el) => {
expect(el).toHaveStyle(dayPickerProps.styles.head_cell);
});
});
test('should render the head elements with the "col" scope', () => {
thElements.forEach((el) => {
expect(el).toHaveAttribute('scope', 'col');
});
});
});