1+ import React from 'react' ;
2+ import { DataViewTable , DataViewTrTree } from '@patternfly/react-data-view/dist/dynamic/DataViewTable' ;
3+
4+ interface Repository {
5+ name : string ;
6+ branches : string | null ;
7+ prs : string | null ;
8+ workspaces : string ;
9+ lastCommit : string ;
10+ children ?: Repository [ ] ;
11+ }
12+
13+ const repositories : Repository [ ] = [
14+ { name : 'Repository one' , branches : 'Branch one' , prs : 'Pull request one' , workspaces : 'Workspace one' , lastCommit : 'Timestamp one' } ,
15+ { name : 'Repository two' , branches : 'Branch two' , prs : 'Pull request two' , workspaces : 'Workspace two' , lastCommit : 'Timestamp two' } ,
16+ { name : 'Repository three' , branches : 'Branch three' , prs : 'Pull request three' , workspaces : 'Workspace three' , lastCommit : 'Timestamp three' } ,
17+ { name : 'Repository four' , branches : 'Branch four' , prs : 'Pull request four' , workspaces : 'Workspace four' , lastCommit : 'Timestamp four' } ,
18+ { name : 'Repository five' , branches : 'Branch five' , prs : 'Pull request five' , workspaces : 'Workspace five' , lastCommit : 'Timestamp five' } ,
19+ { name : 'Repository six' , branches : 'Branch six' , prs : 'Pull request six' , workspaces : 'Workspace six' , lastCommit : 'Timestamp six' }
20+ ] ;
21+ const rows = repositories . map ( item => Object . values ( item ) ) ;
22+
23+ const repositoriesTree : Repository [ ] = [
24+ {
25+ name : 'Repository one' ,
26+ branches : 'Branch one' ,
27+ prs : 'Pull request one' ,
28+ workspaces : 'Workspace one' ,
29+ lastCommit : 'Timestamp one' ,
30+ children : [
31+ { name : 'Repository two' , branches : 'Branch two' , prs : 'Pull request two' , workspaces : 'Workspace two' , lastCommit : 'Timestamp two' } ,
32+ { name : 'Repository three' , branches : 'Branch three' , prs : 'Pull request three' , workspaces : 'Workspace three' , lastCommit : 'Timestamp three' } ,
33+ ]
34+ } ,
35+ {
36+ name : 'Repository four' ,
37+ branches : 'Branch four' ,
38+ prs : 'Pull request four' ,
39+ workspaces : 'Workspace four' ,
40+ lastCommit : 'Timestamp four' ,
41+ children : [ { name : 'Repository five' , branches : 'Branch five' , prs : 'Pull request five' , workspaces : 'Workspace five' , lastCommit : 'Timestamp five' } ]
42+ } ,
43+ { name : 'Repository six' , branches : 'Branch six' , prs : 'Pull request six' , workspaces : 'Workspace six' , lastCommit : 'Timestamp six' }
44+ ] ;
45+
46+
47+
48+ const buildRows = ( repositories : Repository [ ] ) : DataViewTrTree [ ] => repositories . map ( ( repo ) => ( {
49+ row : [ repo . name , repo . branches , repo . prs , repo . workspaces , repo . lastCommit ] ,
50+ id : repo . name , // unique ID for each row
51+ ...( repo . children
52+ ? {
53+ children : buildRows ( repo . children ) // build rows for children
54+ }
55+ : { } )
56+ } ) ) ;
57+
58+ const treeRows = buildRows ( repositoriesTree ) ;
59+
60+ const columns = [ 'Repositories' , 'Branches' , 'Pull requests' , 'Workspaces' , 'Last commit' ] ;
61+
62+ describe ( 'DataViewTable' , ( ) => {
63+
64+ it ( 'renders a basic data view table' , ( ) => {
65+ const ouiaId = 'data' ;
66+
67+ cy . mount (
68+ < DataViewTable aria-label = 'Repositories table' ouiaId = { ouiaId } columns = { columns } rows = { rows } />
69+ ) ;
70+
71+ cy . get ( '[data-ouia-component-id="data-th-0"]' ) . contains ( 'Repositories' ) ;
72+ cy . get ( '[data-ouia-component-id="data-th-1"]' ) . contains ( 'Branches' ) ;
73+ cy . get ( '[data-ouia-component-id="data-th-2"]' ) . contains ( 'Pull requests' ) ;
74+ cy . get ( '[data-ouia-component-id="data-th-3"]' ) . contains ( 'Workspaces' ) ;
75+ cy . get ( '[data-ouia-component-id="data-th-4"]' ) . contains ( 'Last commit' ) ;
76+
77+ cy . get ( '[data-ouia-component-id="data-td-0-0"]' ) . contains ( 'Repository one' ) ;
78+ cy . get ( '[data-ouia-component-id="data-td-2-1"]' ) . contains ( 'Branch three' ) ;
79+ cy . get ( '[data-ouia-component-id="data-td-3-2"]' ) . contains ( 'Pull request four' ) ;
80+ cy . get ( '[data-ouia-component-id="data-td-4-3"]' ) . contains ( 'Workspace five' ) ;
81+ cy . get ( '[data-ouia-component-id="data-td-5-4"]' ) . contains ( 'Timestamp six' ) ;
82+ } ) ;
83+
84+ it ( 'renders a tree data view table' , ( ) => {
85+ const ouiaId = 'tree' ;
86+
87+ cy . mount (
88+ < DataViewTable isTreeTable aria-label = 'Repositories table' ouiaId = { ouiaId } columns = { columns } rows = { treeRows } />
89+ ) ;
90+
91+ cy . get ( '[data-ouia-component-id="tree-td-0-0"]' )
92+ . should ( 'exist' )
93+ . find ( 'button' )
94+ . should ( 'have.length' , 2 ) ;
95+
96+ cy . get ( '[data-ouia-component-id="tree-td-3-0"]' )
97+ . should ( 'exist' )
98+ . find ( 'button' )
99+ . should ( 'have.length' , 2 ) ;
100+
101+ cy . get ( '[data-ouia-component-id="tree-td-5-0"]' )
102+ . should ( 'exist' )
103+ . find ( 'button' )
104+ . should ( 'have.length' , 1 ) ;
105+
106+ cy . get ( '[data-ouia-component-id="tree-th-0"]' ) . contains ( 'Repositories' ) ;
107+ cy . get ( '[data-ouia-component-id="tree-th-1"]' ) . contains ( 'Branches' ) ;
108+ cy . get ( '[data-ouia-component-id="tree-th-2"]' ) . contains ( 'Pull requests' ) ;
109+ cy . get ( '[data-ouia-component-id="tree-th-3"]' ) . contains ( 'Workspaces' ) ;
110+ cy . get ( '[data-ouia-component-id="tree-th-4"]' ) . contains ( 'Last commit' ) ;
111+
112+ cy . get ( '[data-ouia-component-id="tree-td-0-0"]' ) . contains ( 'Repository one' ) ;
113+ cy . get ( '[data-ouia-component-id="tree-td-0-0"]' ) . should ( 'be.visible' ) ;
114+ cy . get ( '[data-ouia-component-id="tree-td-2-1"]' ) . contains ( 'Branch three' ) ;
115+ cy . get ( '[data-ouia-component-id="tree-td-2-1"]' ) . should ( 'not.be.visible' ) ;
116+ cy . get ( '[data-ouia-component-id="tree-td-3-2"]' ) . contains ( 'Pull request four' ) ;
117+ cy . get ( '[data-ouia-component-id="tree-td-4-3"]' ) . contains ( 'Workspace five' ) ;
118+ cy . get ( '[data-ouia-component-id="tree-td-4-3"]' ) . should ( 'not.be.visible' ) ;
119+ cy . get ( '[data-ouia-component-id="tree-td-5-4"]' ) . contains ( 'Timestamp six' ) ;
120+ cy . get ( '[data-ouia-component-id="tree-td-5-4"]' ) . should ( 'be.visible' ) ;
121+ } ) ;
122+ } ) ;
0 commit comments