-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathAnalyticalTable.cy.tsx
4942 lines (4635 loc) · 166 KB
/
AnalyticalTable.cy.tsx
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import ValueState from '@ui5/webcomponents-base/dist/types/ValueState.js';
import { ThemingParameters } from '@ui5/webcomponents-react-base';
import { useCallback, useEffect, useMemo, useRef, useState, version as reactVersion } from 'react';
import type { AnalyticalTableDomRef, AnalyticalTablePropTypes } from '../..';
import { AnalyticalTable, AnalyticalTableHooks, Button, Input } from '../..';
import {
AnalyticalTableScaleWidthMode,
AnalyticalTableSelectionBehavior,
AnalyticalTableSelectionMode,
AnalyticalTableSubComponentsBehavior,
AnalyticalTableVisibleRowCountMode,
IndicationColor
} from '../../enums/index.js';
import { useManualRowSelect } from './pluginHooks/useManualRowSelect';
import { useRowDisableSelection } from './pluginHooks/useRowDisableSelection';
import { cssVarToRgb, cypressPassThroughTestsFactory } from '@/cypress/support/utils';
const generateMoreData = (count) => {
return new Array(count).fill('').map((item, index) => ({
name: `Name-${index}`,
age: index,
friend: {
name: `FriendName-${index}`,
age: index + 10
}
}));
};
type PropTypes = AnalyticalTablePropTypes['onRowSelect'];
const columns = [
{
Header: 'Name',
headerTooltip: 'Full Name',
accessor: 'name'
},
{
Header: 'Age',
accessor: 'age'
},
{
Header: 'Friend Name',
accessor: 'friend.name' // Custom value accessors!
},
{
Header: () => <span>Friend Age</span>, // Custom header components!
accessor: 'friend.age',
headerLabel: 'Custom Label'
}
];
const data = [
{
name: 'A',
age: 40,
friend: {
name: 'Lorem',
age: 28
},
status: ValueState.Positive,
navigation: ValueState.Negative
},
{
name: 'B',
age: 20,
friend: {
name: 'Ipsum',
age: 50
}
},
{
name: 'X',
age: 17,
friend: {
name: 'Dolor',
age: 42
}
},
{
name: 'C',
age: 79,
friend: {
name: 'Sit',
age: 50
}
}
];
describe('AnalyticalTable', () => {
it('sorting', () => {
const sort = cy.spy().as('onSortSpy');
cy.mount(<AnalyticalTable data={data} columns={columns} onSort={sort} />);
cy.findByText('Name').click();
cy.get('[ui5-popover]').should('not.exist');
cy.mount(<AnalyticalTable data={data} columns={columns} onSort={sort} sortable />);
cy.get('[aria-rowindex="3"] > [aria-colindex="1"]').should('text', 'X');
cy.findByText('Name').click();
cy.get('[ui5-popover]').should('be.visible');
cy.findByText('Sort Ascending').shadow().findByRole('listitem').click({ force: true });
cy.get('@onSortSpy').should('have.been.calledWithMatch', {
detail: { column: { id: 'name' }, sortDirection: 'asc' }
});
cy.get('[aria-rowindex="3"] > [aria-colindex="1"]').should('text', 'C');
cy.findByText('Name').click();
cy.findByText('Clear Sorting').shadow().findByRole('listitem').click({ force: true });
cy.get('@onSortSpy').should('have.been.calledWithMatch', {
detail: { column: { id: 'name' }, sortDirection: 'clear' }
});
cy.get('[aria-rowindex="3"] > [aria-colindex="1"]').should('text', 'X');
cy.findByText('Name').click();
cy.findByText('Sort Descending').shadow().findByRole('listitem').click({ force: true });
cy.get('@onSortSpy').should('have.been.calledWithMatch', {
detail: { column: { id: 'name' }, sortDirection: 'desc' }
});
cy.get('[aria-rowindex="3"] > [aria-colindex="1"]').should('text', 'B');
});
it('row count modes', () => {
[AnalyticalTableVisibleRowCountMode.Auto, AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows].forEach(
(visibleRowCountMode) => {
cy.mount(
<div style={{ height: '200px' }}>
<AnalyticalTable
data={data}
columns={columns}
visibleRowCountMode={visibleRowCountMode}
overscanCount={10}
/>
</div>
);
cy.findByRole('grid').should('have.attr', 'data-per-page', '3');
cy.findByText('X').should('be.visible');
cy.findByText('C').should('not.be.visible');
cy.get('[data-empty-row]').should('not.be.visible').should('have.length', 1);
}
);
[AnalyticalTableVisibleRowCountMode.Auto, AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows].forEach(
(visibleRowCountMode) => {
cy.mount(
<AnalyticalTable
style={{ height: '4400px' }}
data={generateMoreData(200)}
columns={columns}
visibleRowCountMode={visibleRowCountMode}
/>
);
cy.findByRole('grid').should('have.attr', 'data-per-page', '99'); //rows(99*44) + header(44) = 4400
cy.findByText('Name-98').should('be.visible');
cy.findByText('Name-99').should('not.be.visible');
cy.get('[data-empty-row]').should('not.exist');
}
);
[AnalyticalTableVisibleRowCountMode.Auto, AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows].forEach(
(visibleRowCountMode) => {
cy.mount(
<AnalyticalTable
style={{ height: '4400px' }}
data={data}
columns={columns}
visibleRowCountMode={visibleRowCountMode}
/>
);
if (visibleRowCountMode === AnalyticalTableVisibleRowCountMode.Auto) {
cy.get('[data-empty-row]').should('be.visible').should('have.length', 1);
} else {
cy.get('[data-empty-row]').should('be.visible').should('have.length', 95);
}
}
);
//test if visibleRows prop is ignored when row-count-mode is "Auto" or "AutoWithEmptyRows"
[AnalyticalTableVisibleRowCountMode.Auto, AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows].forEach(
(visibleRowCountMode) => {
cy.mount(
<AnalyticalTable
style={{ height: '200px' }}
data={data}
columns={columns}
visibleRowCountMode={visibleRowCountMode}
visibleRows={1337}
/>
);
cy.findByRole('grid').should('have.attr', 'data-per-page', '3');
cy.findByText('X').should('be.visible');
cy.findByText('C').should('not.be.visible');
}
);
//test default visibleRow count
cy.mount(
<AnalyticalTable
data={generateMoreData(50)}
columns={columns}
visibleRowCountMode={AnalyticalTableVisibleRowCountMode.Fixed}
/>
);
cy.findByRole('grid').should('have.attr', 'data-per-page', '15');
cy.findByText('Name-14').should('be.visible');
cy.findByText('Name-15').should('not.be.visible');
cy.mount(
<AnalyticalTable
data={generateMoreData(50)}
columns={columns}
visibleRowCountMode={AnalyticalTableVisibleRowCountMode.Fixed}
visibleRows={20}
/>
);
cy.findByRole('grid').should('have.attr', 'data-per-page', '20');
cy.findByText('Name-19').should('be.visible');
cy.findByText('Name-20').should('not.be.visible');
cy.mount(
<AnalyticalTable
data={generateMoreData(50)}
columns={columns}
visibleRowCountMode={AnalyticalTableVisibleRowCountMode.Interactive}
visibleRows={10}
/>
);
cy.findByRole('grid').should('have.attr', 'data-per-page', '10');
cy.findByText('Name-9').should('be.visible');
cy.findByText('Name-10').should('not.be.visible');
cy.findByTitle('Drag to resize')
.trigger('mousedown')
.trigger('mousemove', { pageY: 742, force: true })
.trigger('mouseup', { pageY: 742 });
cy.findByRole('grid').should('have.attr', 'data-per-page', '15');
cy.findByText('Name-14').should('be.visible');
cy.findByText('Name-15').should('not.be.visible');
cy.findByTitle('Drag to resize')
.trigger('mousedown')
.trigger('mousemove', { pageY: 200, force: true })
.trigger('mouseup', { pageY: 200 });
cy.findByRole('grid').should('have.attr', 'data-per-page', '3');
cy.findByText('Name-2').should('be.visible');
cy.findByText('Name-3').should('not.be.visible');
});
it('autoResize', () => {
let resizeColumns = columns.map((el) => {
return { ...el, autoResizable: true };
});
let dataFixed = data.map((el, i) => {
if (i === 2) return { ...el, name: 'Longer Name Too' };
return el;
});
const resizeSpy = cy.spy().as('resize');
cy.mount(
<AnalyticalTable
data={dataFixed}
columns={resizeColumns}
onAutoResize={(e) => {
resizeSpy(e);
e.preventDefault();
}}
/>
);
cy.wait(100);
cy.get('[data-component-name="AnalyticalTableResizer"]').eq(0).as('resizer1');
cy.get('[data-component-name="AnalyticalTableResizer"]').eq(1).as('resizer2');
cy.get('@resizer2').should('be.visible').dblclick();
cy.get('[data-column-id="age"]').invoke('outerWidth').should('equal', 476);
cy.get('@resizer1').should('be.visible').dblclick();
cy.get('[data-column-id="name"]').invoke('outerWidth').should('equal', 476);
cy.get('@resize').should('have.callCount', 2);
cy.mount(<AnalyticalTable data={dataFixed} columns={resizeColumns} onAutoResize={resizeSpy} />);
cy.wait(100);
cy.get('@resizer2').should('be.visible').dblclick();
cy.get('[data-column-id="age"]').invoke('outerWidth').should('equal', 60);
cy.get('@resizer1').should('be.visible').dblclick();
cy.get('[data-column-id="name"]').invoke('outerWidth').should('equal', 129);
cy.get('@resize').should('have.callCount', 4);
dataFixed = generateMoreData(200);
dataFixed = dataFixed.map((el, i) => {
if (i === 2) return { ...el, name: 'Much Longer Name To Resize Larger For Testing A Larger Auto Resize' };
else if (i > 50) return { ...el, name: 'Short Name' };
return el;
});
const loadMore = cy.spy().as('more');
cy.mount(
<AnalyticalTable
data={dataFixed}
columns={resizeColumns}
onLoadMore={loadMore}
infiniteScroll={true}
infiniteScrollThreshold={0}
onAutoResize={resizeSpy}
/>
);
cy.get('[data-component-name="AnalyticalTableBody"]').scrollTo('bottom');
cy.get('@resizer1').should('be.visible').dblclick();
cy.get('[data-column-id="name"]').invoke('outerWidth').should('equal', 93);
cy.get('@resize').should('have.callCount', 5);
resizeColumns = columns.map((el) => {
return { ...el, autoResizable: false };
});
cy.mount(<AnalyticalTable data={dataFixed} columns={resizeColumns} />);
cy.wait(100);
cy.get('@resizer2').should('be.visible').dblclick();
cy.get('[data-column-id="age"]').invoke('outerWidth').should('equal', 472.75);
cy.get('@resizer1').should('be.visible').dblclick();
cy.get('[data-column-id="name"]').invoke('outerWidth').should('equal', 472.75);
cy.get('@resize').should('have.callCount', 5);
const dataSub = data.map((el, i) => {
if (i === 2) return { ...el, name: 'Longer Name Too' };
return el;
});
resizeColumns = columns.map((el) => {
return { ...el, autoResizable: true };
});
const renderRowSubComponent = () => {
return <div title="subcomponent">SubComponent</div>;
};
cy.mount(
<AnalyticalTable
data={dataSub}
columns={resizeColumns}
renderRowSubComponent={renderRowSubComponent}
onAutoResize={resizeSpy}
/>
);
cy.wait(100);
cy.get('@resizer2').should('be.visible').dblclick();
cy.get('[data-column-id="age"]').invoke('outerWidth').should('equal', 60);
cy.get('@resizer1').should('be.visible').dblclick();
cy.get('[data-column-id="name"]').invoke('outerWidth').should('equal', 165);
cy.get('@resize').should('have.callCount', 7);
const dataResizeTree = [...dataTree];
dataResizeTree[0].subRows[0].name = 'Longer Name To Resize Here';
cy.mount(<AnalyticalTable columns={resizeColumns} data={dataResizeTree} isTreeTable onAutoResize={resizeSpy} />);
cy.wait(100);
cy.get('@resizer1').should('be.visible').dblclick();
cy.get('[data-column-id="name"]').invoke('outerWidth').should('equal', 169);
cy.get('[aria-rowindex="1"] > [aria-colindex="1"] > [title="Expand Node"] > [ui5-button]').click();
cy.get('@resizer1').should('be.visible').dblclick();
cy.get('[data-column-id="name"]').invoke('outerWidth').should('equal', 251);
cy.get('@resize').should('have.callCount', 9);
});
it('scrollTo', () => {
interface ScrollTableProps {
scrollFn: string;
args: Array<string | number>;
onTableScroll?: AnalyticalTablePropTypes['onTableScroll'];
}
const scroll = cy.spy().as('scroll');
const ScrollTable = (props: ScrollTableProps) => {
const { scrollFn, args, onTableScroll } = props;
const tableRef = useRef(null);
const handleScroll = () => {
tableRef.current[scrollFn](...args);
};
return (
<>
<Button onClick={handleScroll}>Click</Button>
<AnalyticalTable
data-testid="table"
style={{ width: '170px' }}
ref={tableRef}
onTableScroll={onTableScroll}
header="Table Title"
data={data}
columns={columns}
visibleRows={1}
minRows={1}
/>
</>
);
};
cy.mount(<ScrollTable scrollFn="scrollToItem" args={[1, 'start']} onTableScroll={scroll} />);
cy.findByText('A').should('be.visible');
// should not be rendered due to virtualization
cy.findByText('B').should('not.exist', { timeout: 100 });
cy.findByText('Click').click();
cy.findByText('B').should('be.visible');
cy.findByText('A').should('not.exist', { timeout: 100 });
cy.mount(<ScrollTable scrollFn="scrollTo" args={[50]} onTableScroll={scroll} />);
cy.findByText('Click').click();
cy.get('[data-component-name="AnalyticalTableBody"]').invoke('scrollTop').should('equal', 50);
cy.mount(<ScrollTable scrollFn="horizontalScrollToItem" args={[1, 'start']} onTableScroll={scroll} />);
cy.findByText('A').should('be.visible');
cy.findByText('28').should('not.be.visible');
cy.findByText('Click').click();
cy.findByText('28').should('be.visible');
cy.findByText('A').should('not.be.visible');
cy.mount(<ScrollTable scrollFn="horizontalScrollTo" args={[20]} onTableScroll={scroll} />);
cy.findByText('Click').click();
cy.findByRole('grid').invoke('scrollLeft').should('equal', 20);
cy.get('@scroll').should('have.been.called');
});
it('horizontal scrolling - rtl', () => {
function generateMockData() {
const data = [];
for (let i = 1; i <= 200; i++) {
const row = {};
for (let j = 1; j <= 200; j++) {
row[`column${j}`] = `${i}-${j}`;
}
data.push(row);
}
return data;
}
const data = generateMockData();
const columns = new Array(100)
.fill('')
.map((_, i) => ({ accessor: `column${i + 1}`, Header: `${i + 1} Column`, width: 100 }));
cy.mount(<AnalyticalTable dir="rtl" columns={columns} data={data} />);
cy.get('[data-component-name="AnalyticalTableContainer"]').scrollTo(-10000, 0);
cy.findByText('100 Column').should('be.visible');
cy.findByText('1-100').should('be.visible');
});
it('tree - no subrows spacer', () => {
const data = [...dataTree, { name: 'No Subrows', age: 1337 }];
cy.mount(<AnalyticalTable columns={columns} data={data} isTreeTable />);
cy.get('[data-component-name="AnalyticalTableNonExpandableCellSpacer"]').should('have.length', 1);
});
it('tree selection & filtering', () => {
const TreeSelectFilterTable = (props: PropTypes) => {
const [filter, setFilter] = useState('');
const [relevantPayload, setRelevantPayload] = useState<Record<string, any>>({});
return (
<>
<Input data-testid="input" onInput={(e) => setFilter(e.target.value)} />
<AnalyticalTable
{...props}
isTreeTable
filterable
columns={columns}
onRowSelect={(e) => {
const { allRowsSelected, isSelected, row, rowsById, selectedRowIds } = e.detail;
const selectedRowIdsArrayMapped = Object.keys(selectedRowIds).reduce((acc, key) => {
if (selectedRowIds[key]) {
acc.push(rowsById[key]);
}
return acc;
}, []);
setRelevantPayload({
allRowsSelected,
isSelected,
row: row.id,
selectedFlatRows: selectedRowIdsArrayMapped.map((item) => ({
id: item?.id
})),
selectedRowIds
});
props.onRowSelect(e);
}}
data={dataTree}
globalFilterValue={filter}
selectionMode="Multiple"
/>
<div data-testid="payloadHelper">
{JSON.stringify(relevantPayload?.selectedFlatRows?.filter(Boolean).length)}
{JSON.stringify(relevantPayload?.selectedRowIds)}
</div>
</>
);
};
const select = cy.spy().as('onRowSelectSpy');
cy.mount(<TreeSelectFilterTable onRowSelect={select} />);
// expand
cy.findByText('Robin Moreno').should('not.exist', { timeout: 100 });
cy.findByText('Judith Mathews').should('not.exist', { timeout: 100 });
cy.get('[aria-rowindex="1"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-button]').click();
cy.findByText('Robin Moreno').should('be.visible');
cy.get('[aria-rowindex="4"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-button]')
.shadow()
.find('button')
.focus();
cy.realPress('Enter');
cy.findByText('Judith Mathews').should('be.visible');
// select
cy.findByText('Robin Moreno').click();
cy.get('@onRowSelectSpy').should('have.been.calledWithMatch', {
detail: { isSelected: true }
});
cy.findByTestId('payloadHelper').should('have.text', '1{"0.2":true}');
cy.findByText('Judith Mathews').click();
cy.get('@onRowSelectSpy').should('have.been.calledWithMatch', {
detail: { isSelected: true }
});
cy.findByTestId('payloadHelper').should('have.text', '2{"0.2":true,"0.2.0":true}');
// global filter + select
cy.findByTestId('input').typeIntoUi5Input('Katy Bradshaw');
cy.findByText('Robin Moreno').should('not.exist', { timeout: 100 });
cy.findByText('Judith Mathews').should('not.exist', { timeout: 100 });
cy.findByText('Katy Bradshaw').click();
cy.get('@onRowSelectSpy').should('have.been.calledWithMatch', {
detail: { isSelected: true }
});
cy.get('@onRowSelectSpy').should('have.been.calledThrice');
cy.findByTestId('payloadHelper').should('have.text', '3{"1":true,"0.2":true,"0.2.0":true}');
cy.findByTestId('input').typeIntoUi5Input('{selectall}{backspace}');
// column filter + select
cy.findByText('Name').click();
cy.get(`[ui5-input][show-clear-icon]`).typeIntoUi5Input('Flowers Mcfarland', { force: true });
cy.findByText('Robin Moreno').should('not.exist', { timeout: 100 });
cy.findByText('Judith Mathews').should('not.exist', { timeout: 100 });
cy.findByText('Katy Bradshaw').should('not.exist', { timeout: 100 });
cy.findByText('Flowers Mcfarland').click({ force: true });
cy.get('@onRowSelectSpy').should('have.been.calledWithMatch', {
detail: { isSelected: true }
});
cy.get('@onRowSelectSpy').should('have.callCount', 4);
cy.findByTestId('payloadHelper').should('have.text', '4{"0":true,"1":true,"0.2":true,"0.2.0":true}');
});
it('programmatic and user selection + filtering', () => {
const data = [
...generateMoreData(20),
{
name: `Name-7`,
age: 22,
friend: {
name: `FriendName-X`,
age: 22 + 10
}
}
];
const TestComp = ({ onRowSelect }: PropTypes) => {
const [selectedRowIds, setSelectedRowIds] = useState({});
const [selectedFlatRows, setSelectedFlatRows] = useState([]);
const [selectedRowIdsCb, setSelectedRowIdsCb] = useState({});
const [allRowsSelected, setAllRowsSelected] = useState(false);
const [globalFilterVal, setGlobalFilterVal] = useState('');
return (
<>
<Button onClick={() => setSelectedRowIds({ 2: true, 3: false })}>Set selected rows</Button>
<input
data-testid="input"
value={globalFilterVal}
onInput={(e) => {
setGlobalFilterVal(e.target.value);
}}
/>
<AnalyticalTable
filterable
data={data}
columns={columns}
globalFilterValue={globalFilterVal}
onRowSelect={(e) => {
const { selectedRowIds: _selectedRowIds, rowsById } = e.detail;
const selectedRowIdsArrayMapped = Object.keys(_selectedRowIds).reduce((acc, key) => {
if (_selectedRowIds[key]) {
acc.push(rowsById[key]);
}
return acc;
}, []);
setSelectedFlatRows(selectedRowIdsArrayMapped.map((item) => item.id));
setSelectedRowIdsCb(e.detail.selectedRowIds);
setAllRowsSelected(e.detail.allRowsSelected);
onRowSelect(e);
}}
selectionMode={AnalyticalTableSelectionMode.Multiple}
selectedRowIds={selectedRowIds}
/>
<p>
"selectedFlatRows (state - not part of event):"
<span data-testid="payload">{JSON.stringify(selectedFlatRows)}</span>
</p>
<p>
"e.detail.selectedRowIds:"<span data-testid="payloadRowsById">{JSON.stringify(selectedRowIdsCb)}</span>
</p>
<p>
"e.detail.allRowsSelected:"
<span data-testid="payloadAllRowsSelected">{`${allRowsSelected}`}</span>
</p>
</>
);
};
const select = cy.spy().as('onRowSelectSpy');
cy.mount(<TestComp onRowSelect={select} />);
cy.findByText('Name-0').click();
cy.findByText('Name-1').click();
cy.findByText('Name-5').click();
cy.findByText('Name-5').click();
cy.findByTestId('payload').should('have.text', '["0","1"]');
cy.findByTestId('payloadRowsById').should('have.text', '{"0":true,"1":true}');
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'false');
cy.get('@onRowSelectSpy').should('have.callCount', 4);
cy.findByText('Set selected rows').click();
cy.get('@onRowSelectSpy').should('have.callCount', 4);
cy.findByText('Name-1').click();
cy.get('@onRowSelectSpy').should('have.callCount', 5);
cy.findByTestId('payload').should('have.text', '["1","2"]');
cy.findByTestId('payloadRowsById').should('have.text', '{"1":true,"2":true,"3":false}');
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'false');
//select all
//click
cy.get('[data-row-index="0"][data-column-index="0"]').click();
cy.get('@onRowSelectSpy').should('have.callCount', 6);
cy.findByTestId('payload').should(
'have.text',
'["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"]'
);
cy.findByTestId('payloadRowsById').should(
'have.text',
'{"0":true,"1":true,"2":true,"3":true,"4":true,"5":true,"6":true,"7":true,"8":true,"9":true,"10":true,"11":true,"12":true,"13":true,"14":true,"15":true,"16":true,"17":true,"18":true,"19":true,"20":true}'
);
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'true');
// enter (keydown)
cy.get('[data-row-index="0"][data-column-index="0"]').realPress('Enter');
cy.get('@onRowSelectSpy').should('have.callCount', 7);
cy.findByTestId('payload').should('have.text', '[]');
cy.findByTestId('payloadRowsById').should('have.text', '{}');
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'false');
// Space (keyup) + ArrowDown => 1st row selected
cy.get('[data-row-index="0"][data-column-index="0"]').realPress(['Space', 'ArrowDown']);
cy.get('@onRowSelectSpy').should('have.callCount', 8);
cy.findByTestId('payload').should('have.text', '["0"]');
cy.findByTestId('payloadRowsById').should('have.text', '{"0":true}');
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'false');
// Space (keyup) + ArrowUp => all rows selected
cy.get('[data-row-index="0"][data-column-index="0"]').realPress(['Space', 'ArrowUp']);
cy.get('@onRowSelectSpy').should('have.callCount', 9);
cy.findByTestId('payload').should(
'have.text',
'["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"]'
);
cy.findByTestId('payloadRowsById').should(
'have.text',
'{"0":true,"1":true,"2":true,"3":true,"4":true,"5":true,"6":true,"7":true,"8":true,"9":true,"10":true,"11":true,"12":true,"13":true,"14":true,"15":true,"16":true,"17":true,"18":true,"19":true,"20":true}'
);
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'true');
cy.get('[data-row-index="0"][data-column-index="0"]').click();
cy.findByText('Name-0').click();
cy.findByText('Name-1').click();
cy.findByText('Name-5').click();
cy.findByText('Name').click();
cy.get('[ui5-li-custom]').shadow().get('[ui5-input]').typeIntoUi5Input('7{enter}');
cy.findByTestId('payload').should('have.text', '["0","1","5"]');
cy.findByTestId('payloadRowsById').should('have.text', '{"0":true,"1":true,"5":true}');
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'false');
cy.get('[data-row-index="0"][data-column-index="0"]').click();
cy.get('@onRowSelectSpy').should('have.callCount', 14);
cy.findByTestId('payload').should('have.text', '["0","1","5","7","17","20"]');
cy.findByTestId('payloadRowsById').should('have.text', '{"0":true,"1":true,"5":true,"7":true,"17":true,"20":true}');
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'false');
cy.findByText('Name').click();
cy.get('[ui5-li-custom]').shadow().get('[ui5-input]').typeIntoUi5Input('{selectall}{backspace}{enter}');
cy.get('[data-row-index="0"][data-column-index="0"]').click();
cy.findByText('Name-17').click({ force: true });
cy.findByText('Name').click();
cy.get('[ui5-li-custom]').shadow().get('[ui5-input]').typeIntoUi5Input('7{enter}');
cy.findByTestId('payload').should(
'have.text',
'["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","18","19","20"]'
);
cy.findByTestId('payloadRowsById').should(
'have.text',
'{"0":true,"1":true,"2":true,"3":true,"4":true,"5":true,"6":true,"7":true,"8":true,"9":true,"10":true,"11":true,"12":true,"13":true,"14":true,"15":true,"16":true,"18":true,"19":true,"20":true}'
);
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'false');
cy.findByText('Name-17').click();
cy.findByTestId('payload').should(
'have.text',
'["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"]'
);
cy.findByTestId('payloadRowsById').should(
'have.text',
'{"0":true,"1":true,"2":true,"3":true,"4":true,"5":true,"6":true,"7":true,"8":true,"9":true,"10":true,"11":true,"12":true,"13":true,"14":true,"15":true,"16":true,"17":true,"18":true,"19":true,"20":true}'
);
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'true');
cy.findByText('Name').click();
cy.get('[ui5-li-custom]').shadow().get('[ui5-input]').typeIntoUi5Input('{selectall}{backspace}{enter}');
cy.findByText('Name-17').click({ force: true });
cy.findByTestId('input').type('7{enter}');
cy.findByTestId('payload').should(
'have.text',
'["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","18","19","20"]'
);
cy.findByTestId('payloadRowsById').should(
'have.text',
'{"0":true,"1":true,"2":true,"3":true,"4":true,"5":true,"6":true,"7":true,"8":true,"9":true,"10":true,"11":true,"12":true,"13":true,"14":true,"15":true,"16":true,"18":true,"19":true,"20":true}'
);
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'false');
cy.findByText('Name-17').click();
cy.findByTestId('payload').should(
'have.text',
'["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"]'
);
cy.findByTestId('payloadRowsById').should(
'have.text',
'{"0":true,"1":true,"2":true,"3":true,"4":true,"5":true,"6":true,"7":true,"8":true,"9":true,"10":true,"11":true,"12":true,"13":true,"14":true,"15":true,"16":true,"17":true,"18":true,"19":true,"20":true}'
);
cy.findByTestId('payloadAllRowsSelected').should('have.text', 'true');
cy.get('@onRowSelectSpy').should('have.callCount', 19);
});
it('row & header height', () => {
const TestComponent = () => {
const [rowHeight, setRowHeight] = useState<number>();
const [headerRowHeight, setHeaderRowHeight] = useState<number>();
return (
<>
<Input
data-testid="rowHeight"
onInput={(e) => {
if (e.target.value === '') {
setRowHeight(undefined);
} else {
setRowHeight(parseInt(e.target.value));
}
}}
/>
<Input
data-testid="headerRowHeight"
onInput={(e) => {
if (e.target.value === '') {
setHeaderRowHeight(undefined);
} else {
setHeaderRowHeight(parseInt(e.target.value));
}
}}
/>
<AnalyticalTable data={data} columns={columns} rowHeight={rowHeight} headerRowHeight={headerRowHeight} />
</>
);
};
cy.mount(<TestComponent />);
cy.findAllByRole('columnheader').invoke('outerHeight').should('equal', 44);
cy.findAllByRole('gridcell').invoke('outerHeight').should('equal', 44);
cy.findByTestId('rowHeight').typeIntoUi5Input('100');
cy.findAllByRole('columnheader').invoke('outerHeight').should('equal', 100);
cy.findAllByRole('gridcell').invoke('outerHeight').should('equal', 100);
cy.findByTestId('headerRowHeight').typeIntoUi5Input('200');
cy.findAllByRole('columnheader').invoke('outerHeight').should('equal', 200);
cy.findAllByRole('gridcell').invoke('outerHeight').should('equal', 100);
cy.findByTestId('headerRowHeight').typeIntoUi5Input('{selectall}{backspace}');
cy.findAllByRole('columnheader').invoke('outerHeight').should('equal', 100);
cy.findAllByRole('gridcell').invoke('outerHeight').should('equal', 100);
});
it('GroupBy selection', () => {
const GroupBySelectTable = (props: PropTypes) => {
const { onRowSelect } = props;
const [relevantPayload, setRelevantPayload] = useState<Record<string, any>>({});
const tableInstance = useRef<Record<string, any>>(null);
useEffect(() => {
if (tableInstance.current) {
tableInstance.current.setGroupBy(['name']);
setTimeout(() => {
tableInstance.current.toggleAllRowsExpanded();
}, 100);
}
}, []);
return (
<>
<AnalyticalTable
{...props}
groupable
columns={columns}
tableInstance={tableInstance}
onRowSelect={(e) => {
const { allRowsSelected, isSelected, row, rowsById, selectedRowIds } = e.detail;
const selectedRowIdsArrayMapped = Object.keys(selectedRowIds).reduce((acc, key) => {
if (selectedRowIds[key]) {
acc.push(rowsById[key]);
}
return acc;
}, []);
setRelevantPayload({
allRowsSelected,
isSelected,
row: row.id,
selectedFlatRows: selectedRowIdsArrayMapped.map((item) => ({
id: item?.id
})),
selectedRowIds
});
onRowSelect(e);
}}
data={groupableData}
selectionMode="Multiple"
/>
<div data-testid="selectedFlatRowsLength">
{JSON.stringify(relevantPayload?.selectedFlatRows?.filter(Boolean).length)}
</div>
<div data-testid="selectedRowIds">{JSON.stringify(relevantPayload?.selectedRowIds)}</div>
<div data-testid="isSelected">{`${relevantPayload.isSelected}`}</div>
</>
);
};
const select = cy.spy().as('onRowSelectSpy');
cy.mount(<GroupBySelectTable onRowSelect={select} />);
cy.findByText('QWE').click();
cy.get('@onRowSelectSpy').should('have.callCount', 1);
cy.findByTestId('selectedFlatRowsLength').should('have.text', '1');
cy.findByTestId('selectedRowIds').should('have.text', '{"2":true}');
cy.findByTestId('isSelected').should('have.text', 'true');
cy.findByText('Friend Name').click();
cy.findByText('Group').realClick();
cy.get('[aria-rowindex="7"] > [aria-colindex="3"] > [title="Expand Node"] > [ui5-icon]').click();
cy.findByText('25').click();
cy.get('@onRowSelectSpy').should('have.callCount', 2);
cy.findByTestId('selectedFlatRowsLength').should('have.text', '2');
cy.findByTestId('selectedRowIds').should('have.text', '{"2":true,"4":true}');
cy.findByTestId('isSelected').should('have.text', 'true');
cy.findByText('25').click();
cy.get('@onRowSelectSpy').should('have.callCount', 3);
cy.findByTestId('selectedFlatRowsLength').should('have.text', '1');
cy.findByTestId('selectedRowIds').should('have.text', '{"2":true}');
cy.findByTestId('isSelected').should('have.text', 'false');
});
it('useIndeterminateRowSelection - select subRows', () => {
const indeterminateChange = cy.spy().as('onIndeterminateChangeSpy');
const TestComp = (props) => {
const [selectedRowIds, setSelectedRowIds] = useState({});
return (
<>
<AnalyticalTable
selectionMode={AnalyticalTableSelectionMode.Multiple}
data={dataTree}
columns={columns}
isTreeTable
tableHooks={[AnalyticalTableHooks.useIndeterminateRowSelection(indeterminateChange)]}
reactTableOptions={{ selectSubRows: true }}
onRowSelect={(e) => {
setSelectedRowIds(e.detail.selectedRowIds);
}}
{...props}
/>
<p data-testid="selectedRows">{JSON.stringify(selectedRowIds)}</p>
</>
);
};
cy.mount(<TestComp />);
// select all
cy.get('[data-column-id="__ui5wcr__internal_selection_column"]').click();
cy.findByTestId('selectedRows').should(
'have.text',
'{"0":true,"1":true,"0.0":true,"0.0.0":true,"0.0.0.0":true,"0.0.0.1":true,"0.0.0.2":true,"0.0.0.3":true,"0.0.1":true,"0.0.1.0":true,"0.0.1.1":true,"0.0.1.2":true,"0.0.1.3":true,"0.0.2":true,"0.0.2.0":true,"0.0.2.1":true,"0.0.2.2":true,"0.0.2.3":true,"0.0.3":true,"0.0.3.0":true,"0.0.3.1":true,"0.0.3.2":true,"0.0.3.3":true,"0.1":true,"0.1.0":true,"0.1.0.0":true,"0.1.0.1":true,"0.1.0.2":true,"0.1.0.3":true,"0.1.1":true,"0.1.1.0":true,"0.1.1.1":true,"0.1.1.2":true,"0.1.1.3":true,"0.1.2":true,"0.1.2.0":true,"0.1.2.1":true,"0.1.2.2":true,"0.1.2.3":true,"0.1.3":true,"0.1.3.0":true,"0.1.3.1":true,"0.1.3.2":true,"0.1.3.3":true,"0.2":true,"0.2.0":true,"0.2.0.0":true,"0.2.0.1":true,"0.2.0.2":true,"0.2.0.3":true,"0.2.1":true,"0.2.1.0":true,"0.2.1.1":true,"0.2.1.2":true,"0.2.1.3":true,"0.2.2":true,"0.2.2.0":true,"0.2.2.1":true,"0.2.2.2":true,"0.2.2.3":true,"0.2.3":true,"0.2.3.0":true,"0.2.3.1":true,"0.2.3.2":true,"0.2.3.3":true,"0.3":true,"0.3.0":true,"0.3.0.0":true,"0.3.0.1":true,"0.3.0.2":true,"0.3.0.3":true,"0.3.1":true,"0.3.1.0":true,"0.3.1.1":true,"0.3.1.2":true,"0.3.1.3":true,"0.3.2":true,"0.3.2.0":true,"0.3.2.1":true,"0.3.2.2":true,"0.3.2.3":true,"0.3.3":true,"0.3.3.0":true,"0.3.3.1":true,"0.3.3.2":true,"0.3.3.3":true,"1.0":true,"1.0.0":true,"1.0.0.0":true,"1.0.0.1":true,"1.0.0.2":true,"1.0.0.3":true,"1.0.1":true,"1.0.1.0":true,"1.0.1.1":true,"1.0.1.2":true,"1.0.1.3":true,"1.0.2":true,"1.0.2.0":true,"1.0.2.1":true,"1.0.2.2":true,"1.0.2.3":true,"1.0.3":true,"1.0.3.0":true,"1.0.3.1":true,"1.0.3.2":true,"1.0.3.3":true,"1.1":true,"1.1.0":true,"1.1.0.0":true,"1.1.0.1":true,"1.1.0.2":true,"1.1.0.3":true,"1.1.1":true,"1.1.1.0":true,"1.1.1.1":true,"1.1.1.2":true,"1.1.1.3":true,"1.1.2":true,"1.1.2.0":true,"1.1.2.1":true,"1.1.2.2":true,"1.1.2.3":true,"1.1.3":true,"1.1.3.0":true,"1.1.3.1":true,"1.1.3.2":true,"1.1.3.3":true,"1.2":true,"1.2.0":true,"1.2.0.0":true,"1.2.0.1":true,"1.2.0.2":true,"1.2.0.3":true,"1.2.1":true,"1.2.1.0":true,"1.2.1.1":true,"1.2.1.2":true,"1.2.1.3":true,"1.2.2":true,"1.2.2.0":true,"1.2.2.1":true,"1.2.2.2":true,"1.2.2.3":true,"1.2.3":true,"1.2.3.0":true,"1.2.3.1":true,"1.2.3.2":true,"1.2.3.3":true,"1.3":true,"1.3.0":true,"1.3.0.0":true,"1.3.0.1":true,"1.3.0.2":true,"1.3.0.3":true,"1.3.1":true,"1.3.1.0":true,"1.3.1.1":true,"1.3.1.2":true,"1.3.1.3":true,"1.3.2":true,"1.3.2.0":true,"1.3.2.1":true,"1.3.2.2":true,"1.3.2.3":true,"1.3.3":true,"1.3.3.0":true,"1.3.3.1":true,"1.3.3.2":true,"1.3.3.3":true}'
);
// expand
cy.get('[aria-rowindex="2"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-button]').click();
cy.get('[aria-rowindex="3"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-button]').click();
cy.get('[aria-rowindex="4"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-button]').click();
// deselect row
cy.findByText('Wiggins Cotton').click();
cy.get('@onIndeterminateChangeSpy').should('have.callCount', 1);
cy.findByTestId('selectedRows').should(
'have.text',
'{"0":true,"1":true,"0.0":true,"0.0.0":true,"0.0.0.0":true,"0.0.0.1":true,"0.0.0.2":true,"0.0.0.3":true,"0.0.1":true,"0.0.1.0":true,"0.0.1.1":true,"0.0.1.2":true,"0.0.1.3":true,"0.0.2":true,"0.0.2.0":true,"0.0.2.1":true,"0.0.2.2":true,"0.0.2.3":true,"0.0.3":true,"0.0.3.0":true,"0.0.3.1":true,"0.0.3.2":true,"0.0.3.3":true,"0.1":true,"0.1.0":true,"0.1.0.0":true,"0.1.0.1":true,"0.1.0.2":true,"0.1.0.3":true,"0.1.1":true,"0.1.1.0":true,"0.1.1.1":true,"0.1.1.2":true,"0.1.1.3":true,"0.1.2":true,"0.1.2.0":true,"0.1.2.1":true,"0.1.2.2":true,"0.1.2.3":true,"0.1.3":true,"0.1.3.0":true,"0.1.3.1":true,"0.1.3.2":true,"0.1.3.3":true,"0.2":true,"0.2.0":true,"0.2.0.0":true,"0.2.0.1":true,"0.2.0.2":true,"0.2.0.3":true,"0.2.1":true,"0.2.1.0":true,"0.2.1.1":true,"0.2.1.2":true,"0.2.1.3":true,"0.2.2":true,"0.2.2.0":true,"0.2.2.1":true,"0.2.2.2":true,"0.2.2.3":true,"0.2.3":true,"0.2.3.0":true,"0.2.3.1":true,"0.2.3.2":true,"0.2.3.3":true,"0.3":true,"0.3.0":true,"0.3.0.0":true,"0.3.0.1":true,"0.3.0.2":true,"0.3.0.3":true,"0.3.1":true,"0.3.1.0":true,"0.3.1.1":true,"0.3.1.2":true,"0.3.1.3":true,"0.3.2":true,"0.3.2.0":true,"0.3.2.1":true,"0.3.2.2":true,"0.3.2.3":true,"0.3.3":true,"0.3.3.0":true,"0.3.3.1":true,"0.3.3.2":true,"0.3.3.3":true,"1.0":true,"1.0.0":true,"1.0.0.1":true,"1.0.0.2":true,"1.0.0.3":true,"1.0.1":true,"1.0.1.0":true,"1.0.1.1":true,"1.0.1.2":true,"1.0.1.3":true,"1.0.2":true,"1.0.2.0":true,"1.0.2.1":true,"1.0.2.2":true,"1.0.2.3":true,"1.0.3":true,"1.0.3.0":true,"1.0.3.1":true,"1.0.3.2":true,"1.0.3.3":true,"1.1":true,"1.1.0":true,"1.1.0.0":true,"1.1.0.1":true,"1.1.0.2":true,"1.1.0.3":true,"1.1.1":true,"1.1.1.0":true,"1.1.1.1":true,"1.1.1.2":true,"1.1.1.3":true,"1.1.2":true,"1.1.2.0":true,"1.1.2.1":true,"1.1.2.2":true,"1.1.2.3":true,"1.1.3":true,"1.1.3.0":true,"1.1.3.1":true,"1.1.3.2":true,"1.1.3.3":true,"1.2":true,"1.2.0":true,"1.2.0.0":true,"1.2.0.1":true,"1.2.0.2":true,"1.2.0.3":true,"1.2.1":true,"1.2.1.0":true,"1.2.1.1":true,"1.2.1.2":true,"1.2.1.3":true,"1.2.2":true,"1.2.2.0":true,"1.2.2.1":true,"1.2.2.2":true,"1.2.2.3":true,"1.2.3":true,"1.2.3.0":true,"1.2.3.1":true,"1.2.3.2":true,"1.2.3.3":true,"1.3":true,"1.3.0":true,"1.3.0.0":true,"1.3.0.1":true,"1.3.0.2":true,"1.3.0.3":true,"1.3.1":true,"1.3.1.0":true,"1.3.1.1":true,"1.3.1.2":true,"1.3.1.3":true,"1.3.2":true,"1.3.2.0":true,"1.3.2.1":true,"1.3.2.2":true,"1.3.2.3":true,"1.3.3":true,"1.3.3.0":true,"1.3.3.1":true,"1.3.3.2":true,"1.3.3.3":true}'
);
cy.get('[aria-rowindex="4"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate');
cy.get('[aria-rowindex="3"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate');
cy.get('[aria-rowindex="2"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate');
cy.get('[data-column-id="__ui5wcr__internal_selection_column"] [ui5-checkbox]').should(
'have.attr',
'indeterminate'
);
// deselect all
cy.get('[data-column-id="__ui5wcr__internal_selection_column"]').click();
cy.get('[data-column-id="__ui5wcr__internal_selection_column"]').click();
cy.get('@onIndeterminateChangeSpy').should('have.callCount', 2);
// select leaf row
cy.findByText('Wiggins Cotton').click();
cy.get('@onIndeterminateChangeSpy').should('have.callCount', 3);
cy.findByTestId('selectedRows').should('have.text', '{"1.0.0.0":true}');
cy.get('[aria-rowindex="4"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate');
cy.get('[aria-rowindex="3"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate');
cy.get('[aria-rowindex="2"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate');
cy.get('[data-column-id="__ui5wcr__internal_selection_column"] [ui5-checkbox]').should(
'have.attr',
'indeterminate'
);
// deselect all
cy.get('[data-column-id="__ui5wcr__internal_selection_column"]').click();
cy.get('[data-column-id="__ui5wcr__internal_selection_column"]').click();
cy.get('@onIndeterminateChangeSpy').should('have.callCount', 4);
// select row with subRows
cy.findByText('Diann Alvarado').click();
cy.get('@onIndeterminateChangeSpy').should('have.callCount', 5);
cy.get('[aria-rowindex="4"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true');
cy.get('[aria-rowindex="5"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true');
cy.get('[aria-rowindex="6"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true');
cy.get('[aria-rowindex="7"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true');
cy.get('[aria-rowindex="8"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true');
cy.get('[aria-rowindex="3"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate');
cy.get('[aria-rowindex="2"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate');
cy.get('[data-column-id="__ui5wcr__internal_selection_column"] [ui5-checkbox]').should(
'have.attr',
'indeterminate'
);
// deselect all
cy.get('[data-column-id="__ui5wcr__internal_selection_column"]').click();
cy.get('[data-column-id="__ui5wcr__internal_selection_column"]').click();
// select parent row by selecting sub rows
cy.findByText('Wiggins Cotton').click();
cy.findByText('Herring Flores').click();
cy.findByText('Allen Kidd').click();
cy.findByTestId('selectedRows').should('have.text', '{"1.0.0.0":true,"1.0.0.1":true,"1.0.0.2":true}');
cy.findByText('Selma Kaufman').click();
if (reactVersion.startsWith('19')) {
// ToDo: the parent row isn't included in the `setSelectedRowIds` anymore - check if it's feasible to include it again, otherwise add a note to the hook
cy.findByTestId('selectedRows').should(
'have.text',
// '{"1.0.0.0":true,"1.0.0.1":true,"1.0.0.2":true,"1.0.0.3":true,"1.0.0":true}'
'{"1.0.0.0":true,"1.0.0.1":true,"1.0.0.2":true,"1.0.0.3":true}'
);
} else {
cy.findByTestId('selectedRows').should(
'have.text',
'{"1.0.0.0":true,"1.0.0.1":true,"1.0.0.2":true,"1.0.0.3":true,"1.0.0":true}'
);
}
});
it('useIndeterminateRowSelection', () => {
const indeterminateChange = cy.spy().as('onIndeterminateChangeSpy');
cy.mount(
<AnalyticalTable
selectionMode={AnalyticalTableSelectionMode.Multiple}
data={dataTree}
columns={columns}
isTreeTable