forked from patternfly/react-data-view
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataViewTableTree.test.tsx
More file actions
121 lines (109 loc) · 3.94 KB
/
DataViewTableTree.test.tsx
File metadata and controls
121 lines (109 loc) · 3.94 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { render } from '@testing-library/react';
import { FolderIcon, FolderOpenIcon, LeafIcon } from '@patternfly/react-icons';
import { DataView } from '../DataView';
import { DataViewTable } from '../DataViewTable';
import { DataViewSelection } from '../InternalContext';
const repositories = [
{
name: 'Repository one',
branches: 'Branch one',
prs: 'Pull request one',
workspaces: 'Workspace one',
lastCommit: 'Timestamp one',
children: [
{
name: 'Repository two',
branches: 'Branch two',
prs: 'Pull request two',
workspaces: 'Workspace two',
lastCommit: 'Timestamp two',
},
{
name: 'Repository three',
branches: 'Branch three',
prs: 'Pull request three',
workspaces: 'Workspace three',
lastCommit: 'Timestamp three',
},
],
},
{
name: 'Repository four',
branches: 'Branch four',
prs: 'Pull request four',
workspaces: 'Workspace four',
lastCommit: 'Timestamp four',
children: [
{
name: 'Repository five',
branches: 'Branch five',
prs: 'Pull request five',
workspaces: 'Workspace five',
lastCommit: 'Timestamp five',
},
],
},
{
name: 'Repository six',
branches: 'Branch six',
prs: 'Pull request six',
workspaces: 'Workspace six',
lastCommit: 'Timestamp six',
},
];
// Build rows for DataViewTable
const buildRows = (repositories) => repositories.map((repo) => ({
row: [ repo.name, repo.branches, repo.prs, repo.workspaces, repo.lastCommit ],
id: repo.name,
...(repo.children ? { children: buildRows(repo.children) } : {}),
}));
const rows = buildRows(repositories);
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
const ouiaId = 'TreeTableExample';
describe('DataViewTableTree component', () => {
const mockSelection: DataViewSelection = {
onSelect: jest.fn(),
isSelected: jest.fn(),
isSelectDisabled: jest.fn(),
};
test('should render the tree table correctly', () => {
const { container } = render(
<DataView selection={mockSelection}>
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} leafIcon={<LeafIcon/>} expandedIcon={<FolderOpenIcon aria-hidden />} collapsedIcon={<FolderIcon aria-hidden />} />
</DataView>
);
expect(container).toMatchSnapshot();
});
test('should render tree table with an empty state', () => {
const { container } = render(
<DataView activeState="empty">
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ empty: "No data found" }} rows={[]} />
</DataView>
);
expect(container).toMatchSnapshot();
});
test('should render tree table with an error state', () => {
const { container } = render(
<DataView activeState="error">
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ error: "Some error" }} rows={[]} />
</DataView>
);
expect(container).toMatchSnapshot();
});
test('should render tree table with all expandable nodes expanded', () => {
const { container } = render(
<DataView selection={mockSelection}>
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} expandAll rows={rows} leafIcon={<LeafIcon/>} expandedIcon={<FolderOpenIcon aria-hidden />} collapsedIcon={<FolderIcon aria-hidden />} />
</DataView>
);
expect(container).toMatchSnapshot();
});
test('should render tree table with a loading state', () => {
const { container } = render(
<DataView activeState="loading">
<DataViewTable isTreeTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} bodyStates={{ loading: "Data is loading" }} rows={[]} />
</DataView>
);
expect(container).toMatchSnapshot();
});
});