diff --git a/packages/main/src/components/AnalyticalTable/AnalyticalTable.cy.tsx b/packages/main/src/components/AnalyticalTable/AnalyticalTable.cy.tsx index 4e549ed872f..b99d6d7ecad 100644 --- a/packages/main/src/components/AnalyticalTable/AnalyticalTable.cy.tsx +++ b/packages/main/src/components/AnalyticalTable/AnalyticalTable.cy.tsx @@ -1,11 +1,37 @@ import ValueState from '@ui5/webcomponents-base/dist/types/ValueState.js'; +import paperPlaneIcon from '@ui5/webcomponents-icons/paper-plane.js'; import { ThemingParameters } from '@ui5/webcomponents-react-base'; import { useCallback, useEffect, useMemo, useRef, useState, version as reactVersion } from 'react'; import type { + AnalyticalTableCellInstance, AnalyticalTableColumnDefinition, AnalyticalTableDomRef, AnalyticalTablePropTypes, + InputDomRef, PopoverDomRef, + ButtonDomRef, + CheckBoxDomRef, + ComboBoxDomRef, + DatePickerDomRef, + DateRangePickerDomRef, + DateTimePickerDomRef, + DynamicDateRangeDomRef, + FileUploaderDomRef, + MessageViewButtonDomRef, + MultiComboBoxDomRef, + MultiInputDomRef, + RadioButtonDomRef, + RatingIndicatorDomRef, + SearchDomRef, + SegmentedButtonDomRef, + SelectDomRef, + SliderDomRef, + SplitButtonDomRef, + StepInputDomRef, + SwitchDomRef, + TextAreaDomRef, + TimePickerDomRef, + ToggleButtonDomRef, } from '../..'; import { AnalyticalTable, @@ -17,11 +43,36 @@ import { AnalyticalTableSubComponentsBehavior, AnalyticalTableVisibleRowCountMode, Button, + CheckBox, + ComboBox, + DatePicker, + DateRangePicker, + DateTimePicker, + DynamicDateRange, + FileUploader, IndicationColor, Input, + MessageViewButton, + MultiComboBox, + MultiInput, Popover, + RadioButton, + RatingIndicator, + Search, + SegmentedButton, + SegmentedButtonItem, + Select, + Slider, + SplitButton, + StepInput, + Switch, + Tag, Text, + TextArea, + TimePicker, + ToggleButton, } from '../..'; +import { useF2CellEdit } from './pluginHooks/useF2CellEdit.js'; import { useManualRowSelect } from './pluginHooks/useManualRowSelect'; import { useRowDisableSelection } from './pluginHooks/useRowDisableSelection'; import { cssVarToRgb, cypressPassThroughTestsFactory } from '@/cypress/support/utils'; @@ -3933,6 +3984,141 @@ describe('AnalyticalTable', () => { }); }); + it('plugin hook: useF2CellEdit - navigation', () => { + const tableHooks = [useF2CellEdit]; + cy.mount( + <> + + {' '} + + , + ); + + cy.findByText('Before').click(); + + cy.realPress('Tab'); + cy.log('Cell 0-0'); + cy.focused().should('have.attr', 'data-row-index', '0'); + cy.focused().should('have.attr', 'data-column-index', '0'); + + cy.realPress('Tab'); + cy.focused().should('have.text', 'After'); + + cy.realPress(['Shift', 'Tab']); + cy.log('Cell 0-0'); + cy.focused().should('have.attr', 'data-row-index', '0'); + cy.focused().should('have.attr', 'data-column-index', '0'); + + cy.log('Cell 1-0'); + cy.realPress('ArrowDown'); + cy.focused().should('have.attr', 'data-row-index', '1'); + cy.focused().should('have.attr', 'data-column-index', '0'); + + cy.realPress('Tab'); + cy.focused().should('have.text', 'After'); + + cy.realPress(['Shift', 'Tab']); + cy.log('Cell 1-0'); + cy.focused().should('have.attr', 'data-row-index', '1'); + cy.focused().should('have.attr', 'data-column-index', '0'); + + cy.realPress('F2'); + cy.log('Input 1-0'); + cy.focused().should('have.attr', 'type', 'text'); + + cy.realPress('Tab'); + cy.log('Input 1-1'); + cy.focused().should('have.attr', 'type', 'text'); + + cy.realPress('Tab'); + cy.log('Button 1-1'); + cy.focused().should('have.attr', 'type', 'button'); + + cy.realPress('Tab'); + cy.log('Button 1-3'); + cy.focused().should('have.attr', 'type', 'button'); + + cy.realPress('Tab'); + cy.log('Switch 1-5'); + cy.focused().should('have.attr', 'role', 'switch'); + + for (let i = 0; i < 5; i++) { + cy.realPress('Tab'); + } + cy.log('CheckBox 2-5'); + cy.focused().should('have.attr', 'role', 'checkbox'); + + cy.realPress('F2'); + cy.log('Cell 2-5'); + cy.focused().should('have.attr', 'data-row-index', '2'); + cy.focused().should('have.attr', 'data-column-index', '5'); + + cy.realPress('Tab'); + cy.focused().should('have.text', 'After'); + cy.realPress(['Shift', 'Tab']); + cy.focused().should('have.attr', 'data-row-index', '2'); + cy.focused().should('have.attr', 'data-column-index', '5'); + + cy.realPress('PageDown'); + cy.log('Cell 7-5'); + cy.focused().should('have.attr', 'data-row-index', '7'); + cy.focused().should('have.attr', 'data-column-index', '5'); + + cy.realPress('F2'); + cy.get('[data-component-name="AnalyticalTableBody"]').then(($el) => { + const scrollTop = $el[0].scrollTop; + cy.realPress('PageUp'); + cy.wrap($el).should(($elAfter) => { + expect($elAfter[0].scrollTop).to.eq(scrollTop); + }); + }); + }); + + it('plugin hook: useF2CellEdit - all ui5wc inputs', () => { + const tableHooks = [useF2CellEdit]; + const dummyData = new Array(1).fill({}); + cy.mount( + <> + + + + , + ); + + cy.findByText('Before').click(); + cy.realPress('Tab'); + cy.log('Cell 0-0'); + cy.focused().should('have.attr', 'data-row-index', '0'); + cy.focused().should('have.attr', 'data-column-index', '0'); + cy.realPress('Tab'); + cy.focused().should('have.text', 'After'); + cy.realPress(['Shift', 'Tab']); + cy.realPress('ArrowDown'); + + cy.realPress('F2'); + allRelevantInputCompontentsForF2.forEach((_) => { + cy.realPress('Tab'); + }); + // SegmentedButton has two tab stops + cy.realPress('Tab'); + cy.focused().should('have.text', 'After'); + + cy.realPress('F2'); + allRelevantInputCompontentsForF2.forEach((_) => { + cy.realPress(['Shift', 'Tab']); + }); + // SegmentedButton has two tab stops + cy.realPress(['Shift', 'Tab']); + cy.focused().should('have.text', 'Before'); + }); + cypressPassThroughTestsFactory(AnalyticalTable, { data, columns }); }); @@ -4019,6 +4205,69 @@ const mockNames = [ 'Zara', ]; +const inputCols: AnalyticalTableColumnDefinition[] = [ + { + Header: 'Input', + id: 'input', + Cell: (props: AnalyticalTableCellInstance) => { + const callbackRef = useF2CellEdit.useCallbackRef(props); + return ; + }, + interactiveElementName: 'Input', + }, + { + Header: 'Input & Button', + id: 'input_btn', + Cell: (props: AnalyticalTableCellInstance) => { + const callbackRef = useF2CellEdit.useCallbackRef(props); + return ( + <> + + ; + }, + interactiveElementName: () => 'Button', + }, + { + Header: 'Non-interactive custom content', + accessor: 'friend.name', + Cell: (props: AnalyticalTableCellInstance) => { + return {props.value}; + }, + }, + { + Header: 'Switch or CheckBox', + id: 'switch_checkbox', + Cell: (props: AnalyticalTableCellInstance) => { + const callbackRef = useF2CellEdit.useCallbackRef(props); + if (props.row.index % 2) { + return ; + } + return ; + }, + interactiveElementName: (props: AnalyticalTableCellInstance) => { + if (props.row.index % 2) { + return 'CheckBox'; + } + return 'Switch'; + }, + }, +]; + const columnsWithPopIn = [ { Header: 'Name', @@ -5665,3 +5914,311 @@ const dataTree = [ ], }, ]; + +const allRelevantInputCompontentsForF2 = [ + { + Header: 'Button', + id: 'button', + Cell: (props: AnalyticalTableCellInstance) => { + const callbackRef = useF2CellEdit.useCallbackRef(props); + return