|
1 |
| -import React from 'react'; |
2 |
| -import { Input, MultiComboBox, Option, Select, Switch } from '../../webComponents/index.js'; |
| 1 | +import { cypressPassThroughTestsFactory, mountWithCustomTagName } from '@/cypress/support/utils'; |
| 2 | +import React, { useId, useState } from 'react'; |
| 3 | +import { |
| 4 | + Input, |
| 5 | + MultiComboBox, |
| 6 | + MultiInput, |
| 7 | + Option, |
| 8 | + RatingIndicator, |
| 9 | + Select, |
| 10 | + StepInput, |
| 11 | + Switch, |
| 12 | + Token |
| 13 | +} from '../../webComponents/index.js'; |
3 | 14 | import { FilterGroupItem } from '../FilterGroupItem';
|
4 | 15 | import { VariantManagement } from '../VariantManagement';
|
5 | 16 | import { VariantItem } from '../VariantManagement/VariantItem';
|
| 17 | +import type { FilterBarPropTypes } from './index.js'; |
6 | 18 | import { FilterBar } from './index.js';
|
7 |
| -import { cypressPassThroughTestsFactory, mountWithCustomTagName } from '@/cypress/support/utils'; |
8 | 19 |
|
9 | 20 | const variants = (
|
10 | 21 | <VariantManagement data-testid="variantManagement">
|
@@ -181,9 +192,11 @@ describe('FilterBar.cy.tsx', () => {
|
181 | 192 | cy.get('@restoreSpy').should('have.callCount', 0);
|
182 | 193 | cy.findByText(action).click();
|
183 | 194 | cy.closeUi5PopupWithEsc();
|
| 195 | + cy.focused().should('have.attr', 'data-component-name', 'FilterBarDialogSaveBtn'); |
184 | 196 | cy.get('@restoreSpy').should('have.callCount', 0);
|
185 | 197 | cy.findByText(action).click();
|
186 | 198 | cy.get('[data-component-name="FilterBarDialogResetMessageBox"]').contains('OK').click();
|
| 199 | + cy.focused().should('have.attr', 'data-component-name', 'FilterBarDialogSaveBtn'); |
187 | 200 | cy.findByText('OK').click();
|
188 | 201 | cy.get('@saveSpy').should('have.callCount', saveCallCount);
|
189 | 202 | saveCallCount++;
|
@@ -231,15 +244,13 @@ describe('FilterBar.cy.tsx', () => {
|
231 | 244 | cy.findAllByText('SWITCH').should('have.length', 2);
|
232 | 245 | cy.findAllByText('SELECT').should('have.length', 2);
|
233 | 246 |
|
234 |
| - cy.findByPlaceholderText('Search for filters').typeIntoUi5Input('S'); |
235 |
| - cy.findByPlaceholderText('Search for filters').trigger('input'); |
| 247 | + cy.findByPlaceholderText('Search for filters').typeIntoUi5Input('S{enter}'); |
236 | 248 |
|
237 | 249 | cy.findAllByText('INPUT').should('have.length', 1);
|
238 | 250 | cy.findAllByText('SWITCH').should('have.length', 2);
|
239 | 251 | cy.findAllByText('SELECT').should('have.length', 2);
|
240 | 252 |
|
241 |
| - cy.findByPlaceholderText('Search for filters').typeIntoUi5Input('W', { force: true }); |
242 |
| - cy.findByPlaceholderText('Search for filters').trigger('input'); |
| 253 | + cy.findByPlaceholderText('Search for filters').typeIntoUi5Input('W{enter}', { force: true }); |
243 | 254 |
|
244 | 255 | cy.findAllByText('INPUT').should('have.length', 1);
|
245 | 256 | cy.findAllByText('SWITCH').should('have.length', 2);
|
@@ -493,7 +504,192 @@ describe('FilterBar.cy.tsx', () => {
|
493 | 504 | cy.get('[ui5-multi-combobox]').should('have.length', 2);
|
494 | 505 | });
|
495 | 506 |
|
| 507 | + it('reorder', () => { |
| 508 | + const save = cy.spy().as('saveSpy'); |
| 509 | + cy.mount(<FilterBarWithReordering onFiltersDialogSave={save} />); |
| 510 | + |
| 511 | + cy.get('div[data-order-id]').eq(0).find('[ui5-label]').should('have.text', 'StepInput'); |
| 512 | + cy.get('div[data-order-id]').eq(1).find('[ui5-label]').should('have.text', 'RatingIndicator'); |
| 513 | + cy.get('div[data-order-id]').eq(2).find('[ui5-label]').should('have.text', 'MultiInput'); |
| 514 | + cy.get('div[data-order-id]').eq(4).find('[ui5-label]').should('have.text', 'Switch'); |
| 515 | + |
| 516 | + cy.findByText('Filters').realClick(); |
| 517 | + cy.get('[ui5-dialog]').should('have.attr', 'open'); |
| 518 | + cy.wait(200); |
| 519 | + cy.get('[data-text="SELECT w/ initial selected"]').as('notSelected'); |
| 520 | + cy.get('[data-text="MultiInput"]').as('multiInputRow'); |
| 521 | + cy.get('[data-text="StepInput"]').as('stepInputRow'); |
| 522 | + // active icon should be displayed if not hovered or focused |
| 523 | + cy.get('@multiInputRow').find('[name="circle-task-2"]').should('be.visible'); |
| 524 | + // if no row was focused before, show reorder buttons on hover, but only for visible filters (selected rows) |
| 525 | + cy.get('@multiInputRow').shadow().find('tr').realHover(); |
| 526 | + cy.get('@multiInputRow').find('[data-component-name="FilterBarDialogTableCellReorderBtns"]').should('be.visible'); |
| 527 | + cy.get('@multiInputRow').find('[name="circle-task-2"]').should('not.be.visible'); |
| 528 | + cy.get('@notSelected').shadow().find('tr').realHover(); |
| 529 | + cy.get('@notSelected').find('[data-component-name="FilterBarDialogTableCellReorderBtns"]').should('not.be.visible'); |
| 530 | + cy.get('@notSelected').find('[name="circle-task-2"]').should('not.exist'); |
| 531 | + cy.realPress('Tab'); |
| 532 | + cy.get('@multiInputRow').shadow().find('tr').realHover(); |
| 533 | + // don't show reorder buttons if a row was focused before |
| 534 | + cy.get('@multiInputRow').find('[name="circle-task-2"]').should('be.visible'); |
| 535 | + cy.get('@multiInputRow') |
| 536 | + .find('[data-component-name="FilterBarDialogTableCellReorderBtns"]') |
| 537 | + .should('not.be.visible'); |
| 538 | + cy.focused().should('have.attr', 'data-text', 'StepInput'); |
| 539 | + cy.focused().find('[data-component-name="FilterBarDialogTableCellReorderBtns"]').should('be.visible'); |
| 540 | + |
| 541 | + // reorder via keyboard |
| 542 | + cy.get('[ui5-table-row]').eq(0).should('have.attr', 'data-text', 'StepInput'); |
| 543 | + cy.realPress(['Meta', 'ArrowDown']); |
| 544 | + cy.get('[ui5-table-row]').eq(0).should('have.attr', 'data-text', 'RatingIndicator'); |
| 545 | + cy.get('[ui5-table-row]').eq(1).should('have.attr', 'data-text', 'StepInput'); |
| 546 | + // for some reason, the focus is not set after moving a row in cypress |
| 547 | + cy.get('@stepInputRow').invoke('focus'); |
| 548 | + cy.realPress(['Meta', 'End']); |
| 549 | + cy.get('[ui5-table-row]').eq(0).should('have.attr', 'data-text', 'RatingIndicator'); |
| 550 | + cy.get('[ui5-table-row]').eq(1).should('have.attr', 'data-text', 'MultiInput'); |
| 551 | + cy.get('[ui5-table-row]').eq(5).should('have.attr', 'data-text', 'StepInput'); |
| 552 | + cy.realPress(['Meta', 'ArrowUp']); |
| 553 | + cy.get('[ui5-table-row]').eq(5).should('have.attr', 'data-text', 'SELECT w/ initial selected'); |
| 554 | + cy.get('[ui5-table-row]').eq(4).should('have.attr', 'data-text', 'StepInput'); |
| 555 | + cy.get('@stepInputRow').invoke('focus'); |
| 556 | + cy.realPress(['Meta', 'Home']); |
| 557 | + cy.get('[ui5-table-row]').eq(0).should('have.attr', 'data-text', 'StepInput'); |
| 558 | + cy.get('[ui5-table-row]').eq(1).should('have.attr', 'data-text', 'RatingIndicator'); |
| 559 | + |
| 560 | + // reorder via button click |
| 561 | + cy.get('[ui5-table-row]').eq(0).should('have.attr', 'data-text', 'StepInput'); |
| 562 | + cy.get('@stepInputRow').find('[data-component-name="FilterBarDialogReorderBtnTop"]').as('topBtn'); |
| 563 | + cy.get('@topBtn').should('have.attr', 'disabled', 'disabled'); |
| 564 | + cy.get('@stepInputRow').find('[data-component-name="FilterBarDialogReorderBtnUp"]').as('upBtn'); |
| 565 | + cy.get('@upBtn').should('have.attr', 'disabled', 'disabled'); |
| 566 | + cy.get('@stepInputRow').find('[data-component-name="FilterBarDialogReorderBtnDown"]').as('downBtn'); |
| 567 | + cy.get('@downBtn').should('not.have.attr', 'disabled'); |
| 568 | + cy.get('@stepInputRow').find('[data-component-name="FilterBarDialogReorderBtnBottom"]').as('bottomBtn'); |
| 569 | + cy.get('@bottomBtn').should('not.have.attr', 'disabled'); |
| 570 | + |
| 571 | + cy.get('@downBtn').realClick(); |
| 572 | + cy.get('[ui5-table-row]').eq(0).should('have.attr', 'data-text', 'RatingIndicator'); |
| 573 | + cy.get('[ui5-table-row]').eq(1).should('have.attr', 'data-text', 'StepInput'); |
| 574 | + cy.get('@stepInputRow').realClick(); |
| 575 | + cy.get('@bottomBtn').realClick(); |
| 576 | + cy.get('[ui5-table-row]').eq(0).should('have.attr', 'data-text', 'RatingIndicator'); |
| 577 | + cy.get('[ui5-table-row]').eq(1).should('have.attr', 'data-text', 'MultiInput'); |
| 578 | + cy.get('[ui5-table-row]').eq(5).should('have.attr', 'data-text', 'StepInput'); |
| 579 | + |
| 580 | + cy.get('@stepInputRow').find('[data-component-name="FilterBarDialogReorderBtnTop"]').as('topBtn'); |
| 581 | + cy.get('@topBtn').should('not.have.attr', 'disabled'); |
| 582 | + cy.get('@stepInputRow').find('[data-component-name="FilterBarDialogReorderBtnUp"]').as('upBtn'); |
| 583 | + cy.get('@upBtn').should('not.have.attr', 'disabled'); |
| 584 | + cy.get('@stepInputRow').find('[data-component-name="FilterBarDialogReorderBtnDown"]').as('downBtn'); |
| 585 | + cy.get('@downBtn').should('have.attr', 'disabled', 'disabled'); |
| 586 | + cy.get('@stepInputRow').find('[data-component-name="FilterBarDialogReorderBtnBottom"]').as('bottomBtn'); |
| 587 | + cy.get('@bottomBtn').should('have.attr', 'disabled', 'disabled'); |
| 588 | + |
| 589 | + cy.get('@stepInputRow').realClick(); |
| 590 | + cy.get('@upBtn').realClick(); |
| 591 | + cy.get('[ui5-table-row]').eq(5).should('have.attr', 'data-text', 'SELECT w/ initial selected'); |
| 592 | + cy.get('[ui5-table-row]').eq(4).should('have.attr', 'data-text', 'StepInput'); |
| 593 | + cy.get('@stepInputRow').realClick(); |
| 594 | + cy.get('@topBtn').realClick(); |
| 595 | + cy.get('[ui5-table-row]').eq(0).should('have.attr', 'data-text', 'StepInput'); |
| 596 | + cy.get('[ui5-table-row]').eq(1).should('have.attr', 'data-text', 'RatingIndicator'); |
| 597 | + |
| 598 | + // check if keyboard nav still works |
| 599 | + cy.wait(100); |
| 600 | + cy.realPress('End'); |
| 601 | + cy.focused().should('have.attr', 'data-text', 'SELECT w/ initial selected'); |
| 602 | + cy.realPress('ArrowUp'); |
| 603 | + cy.focused().should('have.attr', 'data-text', 'Switch'); |
| 604 | + cy.realPress('Home'); |
| 605 | + cy.focused().should('have.attr', 'data-text', 'StepInput'); |
| 606 | + cy.realPress('ArrowDown'); |
| 607 | + cy.focused().should('have.attr', 'data-text', 'RatingIndicator'); |
| 608 | + |
| 609 | + // reset behavior |
| 610 | + cy.realPress(['Meta', 'End']); |
| 611 | + cy.get('[ui5-table-row]').eq(5).should('have.attr', 'data-text', 'RatingIndicator'); |
| 612 | + cy.findByText('Reset').realClick(); |
| 613 | + cy.realPress('Enter'); |
| 614 | + cy.wait(100); |
| 615 | + cy.get('[ui5-table-row]').eq(1).should('have.attr', 'data-text', 'RatingIndicator'); |
| 616 | + |
| 617 | + // event |
| 618 | + cy.focused().should('have.attr', 'data-component-name', 'FilterBarDialogSaveBtn'); |
| 619 | + cy.realPress(['Shift', 'Tab']); |
| 620 | + cy.focused().should('have.attr', 'data-text', 'RatingIndicator'); |
| 621 | + cy.realPress(['Meta', 'End']); |
| 622 | + cy.get('[ui5-table-row]').eq(5).should('have.attr', 'data-text', 'RatingIndicator'); |
| 623 | + cy.findByText('OK').realClick(); |
| 624 | + cy.get('@saveSpy').should('have.been.calledOnce'); |
| 625 | + |
| 626 | + cy.get('div[data-order-id]').eq(0).find('[ui5-label]').should('have.text', 'StepInput'); |
| 627 | + cy.get('div[data-order-id]').eq(1).find('[ui5-label]').should('have.text', 'MultiInput'); |
| 628 | + cy.get('div[data-order-id]').eq(2).find('[ui5-label]').should('have.text', 'Input'); |
| 629 | + cy.get('div[data-order-id]').eq(4).find('[ui5-label]').should('have.text', 'RatingIndicator'); |
| 630 | + }); |
| 631 | + |
496 | 632 | mountWithCustomTagName(FilterBar);
|
497 | 633 |
|
498 | 634 | cypressPassThroughTestsFactory(FilterBar);
|
499 | 635 | });
|
| 636 | + |
| 637 | +function FilterBarWithReordering(props: Partial<FilterBarPropTypes>) { |
| 638 | + { |
| 639 | + const uniqueId = useId(); |
| 640 | + const [orderedChildren, setOrderedChildren] = useState([ |
| 641 | + <FilterGroupItem key={`${uniqueId}-0`} label="StepInput" required orderId={`${uniqueId}-0`}> |
| 642 | + <StepInput required /> |
| 643 | + </FilterGroupItem>, |
| 644 | + <FilterGroupItem key={`${uniqueId}-1`} label="RatingIndicator" orderId={`${uniqueId}-1`}> |
| 645 | + <RatingIndicator /> |
| 646 | + </FilterGroupItem>, |
| 647 | + <FilterGroupItem key={`${uniqueId}-2`} label="MultiInput" active orderId={`${uniqueId}-2`}> |
| 648 | + <MultiInput |
| 649 | + tokens={ |
| 650 | + <> |
| 651 | + <Token text="Argentina" selected /> |
| 652 | + <Token text="Bulgaria" /> |
| 653 | + <Token text="England" /> |
| 654 | + <Token text="Finland" /> |
| 655 | + </> |
| 656 | + } |
| 657 | + /> |
| 658 | + </FilterGroupItem>, |
| 659 | + <FilterGroupItem key={`${uniqueId}-3`} label="Input" orderId={`${uniqueId}-3`}> |
| 660 | + <Input placeholder="Placeholder" /> |
| 661 | + </FilterGroupItem>, |
| 662 | + <FilterGroupItem key={`${uniqueId}-4`} label="Switch" orderId={`${uniqueId}-4`}> |
| 663 | + <Switch /> |
| 664 | + </FilterGroupItem>, |
| 665 | + <FilterGroupItem |
| 666 | + key={`${uniqueId}-5`} |
| 667 | + label="SELECT w/ initial selected" |
| 668 | + visibleInFilterBar={false} |
| 669 | + orderId={`${uniqueId}-5`} |
| 670 | + > |
| 671 | + <Select> |
| 672 | + <Option>Option 1</Option> |
| 673 | + <Option selected>Option 2</Option> |
| 674 | + <Option>Option 3</Option> |
| 675 | + <Option>Option 4</Option> |
| 676 | + </Select> |
| 677 | + </FilterGroupItem> |
| 678 | + ]); |
| 679 | + |
| 680 | + const handleFiltersDialogSave = (e) => { |
| 681 | + props.onFiltersDialogSave?.(e); |
| 682 | + setOrderedChildren((prev) => { |
| 683 | + return e.detail.orderIds.map((orderId) => { |
| 684 | + const obj = prev.find((item) => item.props.orderId === orderId); |
| 685 | + return { ...obj }; |
| 686 | + }); |
| 687 | + }); |
| 688 | + }; |
| 689 | + return ( |
| 690 | + <FilterBar {...props} onFiltersDialogSave={handleFiltersDialogSave} enableReordering showResetButton> |
| 691 | + {orderedChildren} |
| 692 | + </FilterBar> |
| 693 | + ); |
| 694 | + } |
| 695 | +} |
0 commit comments