|
1 | 1 | import { useEffect, useRef, useState } from 'react';
|
2 |
| -import { AnalyticalTable, Button, Input } from '../..'; |
| 2 | +import { AnalyticalTable, AnalyticalTableHooks, Button, Input } from '../..'; |
3 | 3 | import { TableSelectionMode, TableVisibleRowCountMode, ValueState } from '../../enums';
|
4 | 4 |
|
5 | 5 | const generateMoreData = (count) => {
|
@@ -431,6 +431,130 @@ describe('AnalyticalTable', () => {
|
431 | 431 | cy.findByTestId('selectedFlatRowsLength').should('have.text', '1');
|
432 | 432 | cy.findByTestId('isSelected').should('have.text', 'false');
|
433 | 433 | });
|
| 434 | + |
| 435 | + it('useIndeterminateRowSelection - select subRows', () => { |
| 436 | + const indeterminateChange = cy.spy().as('onIndeterminateChangeSpy'); |
| 437 | + cy.mount( |
| 438 | + <AnalyticalTable |
| 439 | + selectionMode={TableSelectionMode.MultiSelect} |
| 440 | + data={dataTree} |
| 441 | + columns={columns} |
| 442 | + isTreeTable |
| 443 | + tableHooks={[AnalyticalTableHooks.useIndeterminateRowSelection(indeterminateChange)]} |
| 444 | + reactTableOptions={{ selectSubRows: true }} |
| 445 | + /> |
| 446 | + ); |
| 447 | + |
| 448 | + // select all |
| 449 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 450 | + |
| 451 | + // expand |
| 452 | + cy.get('[aria-rowindex="2"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-icon]').click(); |
| 453 | + cy.get('[aria-rowindex="3"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-icon]').click(); |
| 454 | + cy.get('[aria-rowindex="4"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-icon]').click(); |
| 455 | + |
| 456 | + // deselect row |
| 457 | + cy.findByText('Wiggins Cotton').click(); |
| 458 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 1); |
| 459 | + |
| 460 | + cy.get('[aria-rowindex="4"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 461 | + cy.get('[aria-rowindex="3"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 462 | + cy.get('[aria-rowindex="2"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 463 | + cy.get('#__ui5wcr__internal_selection_column [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 464 | + |
| 465 | + // deselect all |
| 466 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 467 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 468 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 2); |
| 469 | + |
| 470 | + // select leaf row |
| 471 | + cy.findByText('Wiggins Cotton').click(); |
| 472 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 3); |
| 473 | + |
| 474 | + cy.get('[aria-rowindex="4"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 475 | + cy.get('[aria-rowindex="3"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 476 | + cy.get('[aria-rowindex="2"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 477 | + cy.get('#__ui5wcr__internal_selection_column [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 478 | + |
| 479 | + // deselect all |
| 480 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 481 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 482 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 4); |
| 483 | + |
| 484 | + // select row with subRows |
| 485 | + cy.findByText('Diann Alvarado').click(); |
| 486 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 5); |
| 487 | + |
| 488 | + cy.get('[aria-rowindex="4"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true'); |
| 489 | + cy.get('[aria-rowindex="5"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true'); |
| 490 | + cy.get('[aria-rowindex="6"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true'); |
| 491 | + cy.get('[aria-rowindex="7"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true'); |
| 492 | + cy.get('[aria-rowindex="8"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true'); |
| 493 | + cy.get('[aria-rowindex="3"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 494 | + cy.get('[aria-rowindex="2"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 495 | + cy.get('#__ui5wcr__internal_selection_column [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 496 | + }); |
| 497 | + |
| 498 | + it('useIndeterminateRowSelection', () => { |
| 499 | + const indeterminateChange = cy.spy().as('onIndeterminateChangeSpy'); |
| 500 | + cy.mount( |
| 501 | + <AnalyticalTable |
| 502 | + selectionMode={TableSelectionMode.MultiSelect} |
| 503 | + data={dataTree} |
| 504 | + columns={columns} |
| 505 | + isTreeTable |
| 506 | + tableHooks={[AnalyticalTableHooks.useIndeterminateRowSelection(indeterminateChange)]} |
| 507 | + /> |
| 508 | + ); |
| 509 | + // select all |
| 510 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 511 | + |
| 512 | + // expand |
| 513 | + cy.get('[aria-rowindex="2"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-icon]').click(); |
| 514 | + cy.get('[aria-rowindex="3"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-icon]').click(); |
| 515 | + cy.get('[aria-rowindex="4"] > [aria-colindex="2"] > [title="Expand Node"] > [ui5-icon]').click(); |
| 516 | + |
| 517 | + // deselect row |
| 518 | + cy.findByText('Wiggins Cotton').click(); |
| 519 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 1); |
| 520 | + |
| 521 | + cy.get('[aria-rowindex="4"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 522 | + cy.get('[aria-rowindex="3"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 523 | + cy.get('[aria-rowindex="2"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 524 | + cy.get('#__ui5wcr__internal_selection_column [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 525 | + |
| 526 | + // deselect all |
| 527 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 528 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 529 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 2); |
| 530 | + |
| 531 | + // select leaf row |
| 532 | + cy.findByText('Wiggins Cotton').click(); |
| 533 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 3); |
| 534 | + |
| 535 | + cy.get('[aria-rowindex="4"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 536 | + cy.get('[aria-rowindex="3"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 537 | + cy.get('[aria-rowindex="2"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 538 | + cy.get('#__ui5wcr__internal_selection_column [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 539 | + |
| 540 | + // deselect all |
| 541 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 542 | + cy.get('#__ui5wcr__internal_selection_column').click(); |
| 543 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 4); |
| 544 | + |
| 545 | + // select row with subRows |
| 546 | + cy.findByText('Diann Alvarado').click(); |
| 547 | + cy.get('@onIndeterminateChangeSpy').should('have.callCount', 5); |
| 548 | + |
| 549 | + cy.get('[aria-rowindex="4"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'true'); |
| 550 | + cy.get('[aria-rowindex="5"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'false'); |
| 551 | + cy.get('[aria-rowindex="6"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'false'); |
| 552 | + cy.get('[aria-rowindex="7"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'false'); |
| 553 | + cy.get('[aria-rowindex="8"] > [aria-colindex="1"]').should('have.attr', 'aria-selected', 'false'); |
| 554 | + cy.get('[aria-rowindex="3"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 555 | + cy.get('[aria-rowindex="2"] > [aria-colindex="1"] [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 556 | + cy.get('#__ui5wcr__internal_selection_column [ui5-checkbox]').should('have.attr', 'indeterminate', 'true'); |
| 557 | + }); |
434 | 558 | });
|
435 | 559 |
|
436 | 560 | const columns = [
|
|
0 commit comments