From c1e3c210ce9f70c0d8a7a592f1fd5308e01c14a4 Mon Sep 17 00:00:00 2001 From: "anna.shakhova" <68295572+anna-shakhova@users.noreply.github.com> Date: Tue, 24 Nov 2026 09:06:20 +0100 Subject: [PATCH 1/2] Grids: prepare the e2e migration to Playwright --- .github/CODEOWNERS | 23 ++++++++++++++++------- e2e/playwright/eslint.config.mjs | 12 ++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 794ad3f0365e..ee4b7ec5a02d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -49,6 +49,7 @@ /packages/devextreme/js/ui/shared/** @DevExpress/devextreme-grids /packages/devextreme/js/__internal/ui/shared/** @DevExpress/devextreme-grids /packages/testcafe-models/gridCore/** @DevExpress/devextreme-grids +/e2e/playwright/models/gridCore/** @DevExpress/devextreme-grids /packages/devextreme-scss/scss/widgets/*/gridBase/** @DevExpress/devextreme-grids @@ -66,6 +67,8 @@ /packages/testcafe-models/dataGrid/** @DevExpress/devextreme-grids /e2e/testcafe-devextreme/tests/dataGrid/** @DevExpress/devextreme-grids /e2e/playwright/tests/accessibility/dataGrid/** @DevExpress/devextreme-grids +/e2e/playwright/tests/dataGrid/** @DevExpress/devextreme-grids +/e2e/playwright/models/dataGrid/** @DevExpress/devextreme-grids /apps/demos/Demos/DataGrid/** @DevExpress/devextreme-grids /apps/demos/testing/widgets/datagrid/** @DevExpress/devextreme-grids @@ -84,9 +87,11 @@ /packages/devextreme/testing/tests/*/treeList.* @DevExpress/devextreme-grids /packages/testcafe-models/treeList/** @DevExpress/devextreme-grids /e2e/testcafe-devextreme/tests/common/treeList/** @DevExpress/devextreme-grids -/e2e/playwright/tests/accessibility/treeList/** @DevExpress/devextreme-grids +/e2e/playwright/tests/accessibility/treeList/** @DevExpress/devextreme-grids +/e2e/playwright/tests/common/treeList/** @DevExpress/devextreme-grids +/e2e/playwright/models/treeList/** @DevExpress/devextreme-grids -/apps/demos/Demos/TreeList/** @DevExpress/devextreme-grids +/apps/demos/Demos/TreeList/** @DevExpress/devextreme-grids ## filter_builder /packages/devextreme/js/ui/filter_builder_types.d.ts @DevExpress/devextreme-grids @@ -99,11 +104,13 @@ /packages/devextreme/testing/tests/*/filterBuilder.* @DevExpress/devextreme-grids /packages/devextreme/testing/tests/DevExpress.ui.widgets/filterBuilderParts/** @DevExpress/devextreme-grids -/e2e/testcafe-devextreme/tests/common/filterBuilder/** @DevExpress/devextreme-grids -/e2e/playwright/tests/accessibility/filterBuilder.spec.ts @DevExpress/devextreme-grids -/packages/testcafe-models/filterBuilder/** @DevExpress/devextreme-grids +/e2e/testcafe-devextreme/tests/common/filterBuilder/** @DevExpress/devextreme-grids +/e2e/playwright/tests/accessibility/filterBuilder.spec.ts @DevExpress/devextreme-grids +/packages/testcafe-models/filterBuilder/** @DevExpress/devextreme-grids +/e2e/playwright/tests/common/filterBuilder/** @DevExpress/devextreme-grids +/e2e/playwright/models/filterBuilder/** @DevExpress/devextreme-grids -/apps/demos/Demos/FilterBuilder/** @DevExpress/devextreme-grids +/apps/demos/Demos/FilterBuilder/** @DevExpress/devextreme-grids ## sortable /packages/devextreme/js/ui/sortable_types.d.ts @DevExpress/devextreme-grids @@ -144,7 +151,9 @@ /apps/demos/Demos/CardView/** @DevExpress/devextreme-grids /packages/testcafe-models/cardView/** @DevExpress/devextreme-grids /e2e/testcafe-devextreme/tests/cardView/** @DevExpress/devextreme-grids -/e2e/playwright/tests/accessibility/cardView/** @DevExpress/devextreme-grids +/e2e/playwright/tests/accessibility/cardView/** @DevExpress/devextreme-grids +/e2e/playwright/tests/cardView/** @DevExpress/devextreme-grids +/e2e/playwright/models/cardView/** @DevExpress/devextreme-grids # Scheduler diff --git a/e2e/playwright/eslint.config.mjs b/e2e/playwright/eslint.config.mjs index 21a44c5744cc..a60650f22184 100644 --- a/e2e/playwright/eslint.config.mjs +++ b/e2e/playwright/eslint.config.mjs @@ -69,14 +69,10 @@ export default [ }, }, { - files: [ - 'helpers/**/*.ts', - 'models/**/*.ts', - 'tests/editors/**/*.ts', - 'tests/navigation/**/*.ts', - 'tests/common/*.ts', - 'tests/common/gantt/**/*.ts', - 'tests/common/pagination/**/*.ts', + files: ['**/*.ts'], + ignores: [ + 'playwright.config.ts', + 'tests/scheduler/**/*.ts', ], rules: { 'no-restricted-syntax': ['error', { From 38c9776a76063d0f875561966229d9b17407a165 Mon Sep 17 00:00:00 2001 From: "anna.shakhova" <68295572+anna-shakhova@users.noreply.github.com> Date: Tue, 24 Nov 2026 11:07:51 +0100 Subject: [PATCH 2/2] Grids: align the Playwright grid models with the product --- e2e/playwright/README.md | 8 +- e2e/playwright/models/cardView/headerItem.ts | 4 +- .../models/cardView/headers/headers.ts | 16 - .../models/cardView/headers/item.ts | 3 - e2e/playwright/models/cardView/index.ts | 8 - e2e/playwright/models/cardView/toolbar.ts | 10 +- .../models/dataGrid/adaptiveDetailRow.ts | 4 +- e2e/playwright/models/dataGrid/commandCell.ts | 33 + e2e/playwright/models/dataGrid/data/cell.ts | 30 +- .../models/dataGrid/data/cellEditor.ts | 26 + e2e/playwright/models/dataGrid/data/row.ts | 32 +- e2e/playwright/models/dataGrid/editForm.ts | 10 +- e2e/playwright/models/dataGrid/filter/cell.ts | 4 +- e2e/playwright/models/dataGrid/filter/row.ts | 10 +- e2e/playwright/models/dataGrid/gridBase.ts | 155 +++++ .../models/dataGrid/headers/cell.ts | 4 +- .../models/dataGrid/headers/headerFilter.ts | 7 +- .../models/dataGrid/headers/index.ts | 1 - .../models/dataGrid/headers/panel.ts | 10 + e2e/playwright/models/dataGrid/headers/row.ts | 4 +- e2e/playwright/models/dataGrid/index.ts | 141 +--- .../{dataGrid => gridCore}/columnChooser.ts | 15 +- e2e/playwright/models/gridCore/element.ts | 9 + .../models/gridCore/filter/panel.ts | 10 +- e2e/playwright/models/gridCore/focusable.ts | 17 + e2e/playwright/models/gridCore/index.ts | 7 +- e2e/playwright/models/gridCore/module.ts | 4 +- e2e/playwright/models/internal/focusable.ts | 16 +- e2e/playwright/models/treeList/index.ts | 4 +- .../cardView/columnSortable.spec.ts | 2 +- .../dataGrid/fixedColumns.spec.ts | 6 +- .../tests/cardView/columnSortable/utils.ts | 4 +- .../editing/T1154721_editingCellFocus.spec.ts | 102 +++ .../T1323684_readonlyEditorNewRow.spec.ts | 166 +++++ .../editing/editing.functional_matrix.spec.ts | 615 ++++++++++++++++++ .../editingNewRow.functional_matrix.spec.ts | 231 +++++++ .../common/editing/initNewRow.spec.ts | 33 + .../common/editing/undefinedValues.spec.ts | 40 ++ .../tests/dataGrid/helpers/clickWithOffset.ts | 46 ++ .../tests/dataGrid/helpers/getFirstDataRow.ts | 7 + .../tests/dataGrid/helpers/typeText.ts | 23 + .../editing/T1154721_editingCellFocus.ts | 115 ---- .../editing/T1323684_readonlyEditorNewRow.ts | 170 ----- .../editing/editing.functional_matrix.ts | 607 ----------------- .../editingNewRow.functional_matrix.ts | 234 ------- .../dataGrid/common/editing/initNewRow.ts | 43 -- .../common/editing/undefinedValues.ts | 40 -- 47 files changed, 1610 insertions(+), 1476 deletions(-) delete mode 100644 e2e/playwright/models/cardView/headers/headers.ts delete mode 100644 e2e/playwright/models/cardView/headers/item.ts create mode 100644 e2e/playwright/models/dataGrid/commandCell.ts create mode 100644 e2e/playwright/models/dataGrid/data/cellEditor.ts create mode 100644 e2e/playwright/models/dataGrid/gridBase.ts rename e2e/playwright/models/{dataGrid => gridCore}/columnChooser.ts (67%) create mode 100644 e2e/playwright/models/gridCore/element.ts create mode 100644 e2e/playwright/models/gridCore/focusable.ts create mode 100644 e2e/playwright/tests/dataGrid/common/editing/T1154721_editingCellFocus.spec.ts create mode 100644 e2e/playwright/tests/dataGrid/common/editing/T1323684_readonlyEditorNewRow.spec.ts create mode 100644 e2e/playwright/tests/dataGrid/common/editing/editing.functional_matrix.spec.ts create mode 100644 e2e/playwright/tests/dataGrid/common/editing/editingNewRow.functional_matrix.spec.ts create mode 100644 e2e/playwright/tests/dataGrid/common/editing/initNewRow.spec.ts create mode 100644 e2e/playwright/tests/dataGrid/common/editing/undefinedValues.spec.ts create mode 100644 e2e/playwright/tests/dataGrid/helpers/clickWithOffset.ts create mode 100644 e2e/playwright/tests/dataGrid/helpers/getFirstDataRow.ts create mode 100644 e2e/playwright/tests/dataGrid/helpers/typeText.ts delete mode 100644 e2e/testcafe-devextreme/tests/dataGrid/common/editing/T1154721_editingCellFocus.ts delete mode 100644 e2e/testcafe-devextreme/tests/dataGrid/common/editing/T1323684_readonlyEditorNewRow.ts delete mode 100644 e2e/testcafe-devextreme/tests/dataGrid/common/editing/editing.functional_matrix.ts delete mode 100644 e2e/testcafe-devextreme/tests/dataGrid/common/editing/editingNewRow.functional_matrix.ts delete mode 100644 e2e/testcafe-devextreme/tests/dataGrid/common/editing/initNewRow.ts delete mode 100644 e2e/testcafe-devextreme/tests/dataGrid/common/editing/undefinedValues.ts diff --git a/e2e/playwright/README.md b/e2e/playwright/README.md index b30a09c6a444..35283c79f7bf 100644 --- a/e2e/playwright/README.md +++ b/e2e/playwright/README.md @@ -244,7 +244,7 @@ viewport is 1200×800 and the widgets of the previous test are disposed. | `RequestMock` | `mockApi` on top of `page.route` | | `mockdate` | `mockDate` on top of `page.clock` | | machine timezone on the agent | `TIMEZONE` → the browser context | -| `t.typeText` | `locator.pressSequentially` | +| `t.typeText` | a click, then `pressSequentially` (Typing) | | `t.pressKey('ctrl+a')` | `page.keyboard.press('Control+a')` | | `t.expect(selector.value)` | `expect(locator).toHaveValue` | | `t.expect(widget.option('x'))` | `expect.poll(() => widget.option('x'))` | @@ -269,6 +269,12 @@ test would run once more in the tagged job. editors do not react to it. Type with `pressSequentially`, and press keys under their Playwright names: `Enter`, `Escape`, `ArrowLeft`, `Control+a`. +`t.typeText` did more than type. It clicked the element unless the element already had the focus, +put the caret at the end of the value (`replace: true` selected the whole value instead), and only +then sent the keys. `pressSequentially` alone focuses the element without a click, so a widget that +reacts to the pointer (a grid moving its focused cell) never sees it, and the caret stays where the +browser puts it, which can be the start of the value. Port it as all three steps. + **Checks.** TestCafe retried `t.expect(selector.value)`; here only `expect(locator)` and `expect.poll` retry. `expect(await locator.inputValue()).toBe(x)` reads the value once and fails whenever the page is a moment late. diff --git a/e2e/playwright/models/cardView/headerItem.ts b/e2e/playwright/models/cardView/headerItem.ts index e00c85853103..14a9ebf3c842 100644 --- a/e2e/playwright/models/cardView/headerItem.ts +++ b/e2e/playwright/models/cardView/headerItem.ts @@ -1,11 +1,11 @@ import type { Locator } from '@playwright/test'; -import FocusableElement from '../internal/focusable'; +import GridElement from '../gridCore/element'; const CLASS = { filterIcon: 'dx-header-filter-icon', }; -export default class HeaderItem extends FocusableElement { +export default class HeaderItem extends GridElement { public getFilterIcon(): Locator { return this.element.locator(`.${CLASS.filterIcon}`); } diff --git a/e2e/playwright/models/cardView/headers/headers.ts b/e2e/playwright/models/cardView/headers/headers.ts deleted file mode 100644 index e229410735e5..000000000000 --- a/e2e/playwright/models/cardView/headers/headers.ts +++ /dev/null @@ -1,16 +0,0 @@ -import GridModule from '../../gridCore/module'; -import HeaderItem from './item'; - -const CLASS = { - headerItem: 'header-item', -}; - -export default class HeadersElement extends GridModule { - public getHeaderItemNth(nth: number): HeaderItem { - const selector = this.element - .locator(`.${this.addWidgetPrefix(CLASS.headerItem)}`) - .nth(nth); - - return new HeaderItem(selector, this.widgetName); - } -} diff --git a/e2e/playwright/models/cardView/headers/item.ts b/e2e/playwright/models/cardView/headers/item.ts deleted file mode 100644 index bc3826e6a38d..000000000000 --- a/e2e/playwright/models/cardView/headers/item.ts +++ /dev/null @@ -1,3 +0,0 @@ -import GridModule from '../../gridCore/module'; - -export default class HeaderItem extends GridModule {} diff --git a/e2e/playwright/models/cardView/index.ts b/e2e/playwright/models/cardView/index.ts index cf4f00cfa733..bd78c7bb98c6 100644 --- a/e2e/playwright/models/cardView/index.ts +++ b/e2e/playwright/models/cardView/index.ts @@ -2,7 +2,6 @@ import type { Locator } from '@playwright/test'; import type { WidgetName } from '../types'; import GridCore, { CLASS as CLASS_BASE } from '../gridCore'; import Card from './card'; -import HeadersElement from './headers/headers'; import HeaderPanel from './headerPanel'; import Toolbar from './toolbar'; @@ -27,13 +26,6 @@ export default class CardView extends GridCore { return new Card(this.getCards().nth(nth), this.getName()); } - public getHeaders(): HeadersElement { - return new HeadersElement( - this.element.locator(`.${this.addWidgetPrefix(CLASS.headers)}`), - this.getName(), - ); - } - public getHeaderPanel(): HeaderPanel { return new HeaderPanel( this.element.locator(`.${this.addWidgetPrefix(CLASS.headers)}`), diff --git a/e2e/playwright/models/cardView/toolbar.ts b/e2e/playwright/models/cardView/toolbar.ts index 68b1eae997eb..917921e4ec8f 100644 --- a/e2e/playwright/models/cardView/toolbar.ts +++ b/e2e/playwright/models/cardView/toolbar.ts @@ -1,13 +1,7 @@ -import type { Locator } from '@playwright/test'; import Button from '../button'; +import GridElement from '../gridCore/element'; -export default class Toolbar { - public readonly element: Locator; - - constructor(element: Locator) { - this.element = element; - } - +export default class Toolbar extends GridElement { public getAddButton(): Button { return new Button(this.element.page(), this.element.locator('[aria-label=\'add\']')); } diff --git a/e2e/playwright/models/dataGrid/adaptiveDetailRow.ts b/e2e/playwright/models/dataGrid/adaptiveDetailRow.ts index c0b3c8270e17..2db11a91485f 100644 --- a/e2e/playwright/models/dataGrid/adaptiveDetailRow.ts +++ b/e2e/playwright/models/dataGrid/adaptiveDetailRow.ts @@ -1,3 +1,3 @@ -import FocusableElement from '../internal/focusable'; +import GridElement from '../gridCore/element'; -export default class AdaptiveDetailRow extends FocusableElement {} +export default class AdaptiveDetailRow extends GridElement {} diff --git a/e2e/playwright/models/dataGrid/commandCell.ts b/e2e/playwright/models/dataGrid/commandCell.ts new file mode 100644 index 000000000000..e99457638041 --- /dev/null +++ b/e2e/playwright/models/dataGrid/commandCell.ts @@ -0,0 +1,33 @@ +import type { Locator } from '@playwright/test'; +import GridFocusableElement from '../gridCore/focusable'; + +const CLASS = { + commandEdit: 'dx-command-edit', + commandExpand: 'dx-command-expand', + commandSelect: 'dx-command-select', + commandAdaptive: 'dx-command-adaptive', + commandAI: 'dx-command-ai', + editButton: 'dx-link-edit', +}; + +const commandSelector = [ + `.${CLASS.commandEdit}`, + `.${CLASS.commandExpand}`, + `.${CLASS.commandSelect}`, + `.${CLASS.commandAdaptive}`, + `.${CLASS.commandAI}`, +].join(', '); + +export default class CommandCell extends GridFocusableElement { + constructor(dataRow: Locator, index: number) { + super(dataRow.locator(`:scope > td[aria-colindex='${index + 1}']:is(${commandSelector})`)); + } + + public getButton(index: number): Locator { + return this.element.locator(':scope > *').nth(index); + } + + public getEditButton(): Locator { + return this.element.locator(`.${CLASS.editButton}`); + } +} diff --git a/e2e/playwright/models/dataGrid/data/cell.ts b/e2e/playwright/models/dataGrid/data/cell.ts index d126c687e7a6..8457fdaa5c95 100644 --- a/e2e/playwright/models/dataGrid/data/cell.ts +++ b/e2e/playwright/models/dataGrid/data/cell.ts @@ -1,35 +1,33 @@ import type { Locator } from '@playwright/test'; -import { expect } from '@playwright/test'; -import FocusableElement from '../../internal/focusable'; -import { classMatcher } from '../../internal/classMatcher'; +import GridFocusableElement from '../../gridCore/focusable'; +import { expectClass } from '../../internal/classMatcher'; +import { CellEditor } from './cellEditor'; const CLASS = { editCell: 'dx-editor-cell', - focused: 'dx-focused', + editorInput: 'dx-texteditor-input', cellModified: 'dx-cell-modified', + checkbox: 'dx-checkbox', }; -export default class DataCell extends FocusableElement { +export default class DataCell extends GridFocusableElement { constructor(dataRow: Locator, index: number) { super(dataRow.locator(`td[aria-colindex='${index + 1}']`)); } - private async expectClass(className: string, present: boolean): Promise { - // TestCafe reads the state of the first match; legacy fixed columns render every row twice. - const assertion = expect(this.element.first()); - - await (present ? assertion : assertion.not).toHaveClass(classMatcher(className)); + public expectEditCell(present = true): Promise { + return expectClass(this.element, CLASS.editCell, present); } - public expectEditCell(present = true): Promise { - return this.expectClass(CLASS.editCell, present); + public expectModified(present = true): Promise { + return expectClass(this.element, CLASS.cellModified, present); } - public expectFocused(present = true): Promise { - return this.expectClass(CLASS.focused, present); + public getEditor(): CellEditor { + return new CellEditor(this.element.locator(`.${CLASS.editorInput}, .${CLASS.checkbox}`)); } - public expectModified(present = true): Promise { - return this.expectClass(CLASS.cellModified, present); + public getCheckbox(): Locator { + return this.element.locator(`.${CLASS.checkbox}`); } } diff --git a/e2e/playwright/models/dataGrid/data/cellEditor.ts b/e2e/playwright/models/dataGrid/data/cellEditor.ts new file mode 100644 index 000000000000..f347b1c847b9 --- /dev/null +++ b/e2e/playwright/models/dataGrid/data/cellEditor.ts @@ -0,0 +1,26 @@ +import type { Locator } from '@playwright/test'; +import GridElement from '../../gridCore/element'; +import { expectClass } from '../../internal/classMatcher'; + +const CLASS = { + checkboxChecked: 'dx-checkbox-checked', + dropDownEditorButton: 'dx-dropdowneditor-button', + editFormItem: 'dx-datagrid-edit-form-item', + fieldItemLabel: 'dx-field-item-label', +}; + +export class CellEditor extends GridElement { + public getItemLabel(): Locator { + return this.element + .locator(`xpath=ancestor::*[contains(concat(' ', normalize-space(@class), ' '), ' ${CLASS.editFormItem} ')]`) + .locator(`.${CLASS.fieldItemLabel}`); + } + + public getDropDownButton(): Locator { + return this.element.locator('xpath=../..').locator(`.${CLASS.dropDownEditorButton}`); + } + + public expectChecked(present = true): Promise { + return expectClass(this.element, CLASS.checkboxChecked, present); + } +} diff --git a/e2e/playwright/models/dataGrid/data/row.ts b/e2e/playwright/models/dataGrid/data/row.ts index 1624a2e5efeb..0aac245ae9a2 100644 --- a/e2e/playwright/models/dataGrid/data/row.ts +++ b/e2e/playwright/models/dataGrid/data/row.ts @@ -1,40 +1,42 @@ -import { expect } from '@playwright/test'; -import GridModule from '../../gridCore/module'; -import { classMatcher } from '../../internal/classMatcher'; +import GridFocusableElement from '../../gridCore/focusable'; +import { expectClass } from '../../internal/classMatcher'; +import CommandCell from '../commandCell'; import DataCell from './cell'; const CLASS = { focusedRow: 'dx-row-focused', rowRemoved: 'dx-row-removed', selection: 'dx-selection', + insertedRow: 'dx-row-inserted', editedRow: 'dx-edit-row', }; -export default class DataRow extends GridModule { - private async expectClass(className: string, present: boolean): Promise { - // TestCafe reads the state of the first match; legacy fixed columns render every row twice. - const assertion = expect(this.element.first()); - - await (present ? assertion : assertion.not).toHaveClass(classMatcher(className)); - } - +export default class DataRow extends GridFocusableElement { public expectRemoved(present = true): Promise { - return this.expectClass(CLASS.rowRemoved, present); + return expectClass(this.element, CLASS.rowRemoved, present); } public expectFocusedRow(present = true): Promise { - return this.expectClass(CLASS.focusedRow, present); + return expectClass(this.element, CLASS.focusedRow, present); } public expectSelected(present = true): Promise { - return this.expectClass(CLASS.selection, present); + return expectClass(this.element, CLASS.selection, present); + } + + public expectInserted(present = true): Promise { + return expectClass(this.element, CLASS.insertedRow, present); } public expectEdited(present = true): Promise { - return this.expectClass(CLASS.editedRow, present); + return expectClass(this.element, CLASS.editedRow, present); } public getDataCell(index: number): DataCell { return new DataCell(this.element, index); } + + public getCommandCell(index: number): CommandCell { + return new CommandCell(this.element, index); + } } diff --git a/e2e/playwright/models/dataGrid/editForm.ts b/e2e/playwright/models/dataGrid/editForm.ts index 005793fb831d..214281517ceb 100644 --- a/e2e/playwright/models/dataGrid/editForm.ts +++ b/e2e/playwright/models/dataGrid/editForm.ts @@ -1,11 +1,13 @@ import type { Locator } from '@playwright/test'; -import FocusableElement from '../internal/focusable'; +import GridElement from '../gridCore/element'; const CLASS = { form: 'dx-form', + textEditorInput: 'dx-texteditor-input', + checkbox: 'dx-checkbox', }; -export default class EditForm extends FocusableElement { +export default class EditForm extends GridElement { public readonly form: Locator; public readonly saveButton: Locator; @@ -18,4 +20,8 @@ export default class EditForm extends FocusableElement { this.saveButton = buttons.nth(0); this.cancelButton = buttons.nth(1); } + + public getItem(id: string): Locator { + return this.form.locator(`.${CLASS.textEditorInput}[id*=_${id}], .${CLASS.checkbox}[id*=_${id}]`); + } } diff --git a/e2e/playwright/models/dataGrid/filter/cell.ts b/e2e/playwright/models/dataGrid/filter/cell.ts index f9fad8c0917c..8a83daa2a986 100644 --- a/e2e/playwright/models/dataGrid/filter/cell.ts +++ b/e2e/playwright/models/dataGrid/filter/cell.ts @@ -1,5 +1,5 @@ import type { Locator, Page } from '@playwright/test'; -import FocusableElement from '../../internal/focusable'; +import GridElement from '../../gridCore/element'; const CLASS = { filterEditor: 'dx-widget', @@ -7,7 +7,7 @@ const CLASS = { menuButton: 'dx-menu-item', }; -export default class FilterCell extends FocusableElement { +export default class FilterCell extends GridElement { public readonly menuButton: Locator; constructor(element: Locator) { diff --git a/e2e/playwright/models/dataGrid/filter/row.ts b/e2e/playwright/models/dataGrid/filter/row.ts index 6b224e9f3757..ac9a1e928071 100644 --- a/e2e/playwright/models/dataGrid/filter/row.ts +++ b/e2e/playwright/models/dataGrid/filter/row.ts @@ -1,12 +1,8 @@ -import FocusableElement from '../../internal/focusable'; +import GridElement from '../../gridCore/element'; import FilterCell from './cell'; -const CLASS = { - editCell: 'dx-editor-cell', -}; - -export default class FilterRow extends FocusableElement { +export default class FilterRow extends GridElement { public getFilterCell(index: number): FilterCell { - return new FilterCell(this.element.locator(`.${CLASS.editCell}:nth-child(${index + 1})`)); + return new FilterCell(this.element.locator(`td[aria-colindex='${index + 1}']`)); } } diff --git a/e2e/playwright/models/dataGrid/gridBase.ts b/e2e/playwright/models/dataGrid/gridBase.ts new file mode 100644 index 000000000000..7827f9fdc531 --- /dev/null +++ b/e2e/playwright/models/dataGrid/gridBase.ts @@ -0,0 +1,155 @@ +import type { Locator, Page } from '@playwright/test'; +import GridCore, { CLASS as CLASS_BASE } from '../gridCore'; +import DataRow from './data/row'; +import DataCell from './data/cell'; +import FilterCell from './filter/cell'; +import EditForm from './editForm'; +import Headers from './headers'; +import HeaderPanel from './headers/panel'; +import AdaptiveDetailRow from './adaptiveDetailRow'; + +const CLASS = { + ...CLASS_BASE, + headers: 'headers', + headerPanel: 'header-panel', + dataRow: 'dx-data-row', + gridView: 'content', + fixedGridView: 'content-fixed', + cellModified: 'dx-cell-modified', + masterDetailRow: 'dx-master-detail-row', + editFormRow: 'edit-form', + button: 'dx-button', + formButtonsContainer: 'form-buttons-container', + popupEdit: 'edit-popup', + adaptiveDetailRow: 'dx-adaptive-detail-row', + errorRow: 'dx-error-row', + overlayContent: 'dx-overlay-content', + revertTooltip: 'revert-tooltip', + invalidMessage: 'invalid-message', + toolbar: 'dx-toolbar', + dialogWrapper: 'dx-dialog-wrapper', +}; + +const E2E_ATTRIBUTES = { + a11yStatusContainer: 'e2e-a11y-general-status-container', +}; + +export default abstract class GridBase extends GridCore { + // A grid nested in a master-detail row has its own rows and headers: skip them. + private ownElement(selector: string): Locator { + return this.element.locator(`${selector}:not(:scope .${CLASS.masterDetailRow} *)`); + } + + public getHeaders(): Headers { + return new Headers(this.ownElement(`.${this.addWidgetPrefix(CLASS.headers)}`), this.getName()); + } + + public getDataRow(index: number): DataRow { + const gridView = this.addWidgetPrefix(CLASS.gridView); + const fixedGridView = this.addWidgetPrefix(CLASS.fixedGridView); + + return new DataRow( + this.ownElement(`.${gridView}:not(.${fixedGridView}) .${CLASS.dataRow}[aria-rowindex='${index + 1}']`), + ); + } + + public getFixedDataRow(index: number): DataRow { + const fixedGridView = this.addWidgetPrefix(CLASS.fixedGridView); + + return new DataRow( + this.ownElement(`.${fixedGridView} .${CLASS.dataRow}[aria-rowindex='${index + 1}']`), + ); + } + + public getDataCell(rowIndex: number, columnIndex: number): DataCell { + return this.getDataRow(rowIndex).getDataCell(columnIndex); + } + + public getFixedDataCell(rowIndex: number, columnIndex: number): DataCell { + return this.getFixedDataRow(rowIndex).getDataCell(columnIndex); + } + + public getAdaptiveRow(index: number): AdaptiveDetailRow { + return new AdaptiveDetailRow(this.element.locator(`.${CLASS.adaptiveDetailRow}`).nth(index)); + } + + public getModifiedCells(): Locator { + return this.element.locator(`.${CLASS.cellModified}`); + } + + public getErrorRow(): Locator { + return this.element.locator(`.${CLASS.errorRow}`); + } + + public getFilterCell(columnIndex: number): FilterCell { + return this.getHeaders().getFilterRow().getFilterCell(columnIndex); + } + + public getFilterEditor( + columnIndex: number, + EditorType: new (page: Page, element: Locator) => T, + ): T { + return this.getFilterCell(columnIndex).getEditor(EditorType); + } + + public getDialog(): Locator { + return this.body.locator(`.${CLASS.dialogWrapper}`); + } + + public getRevertTooltip(): Locator { + return this.body.locator(`.${this.addWidgetPrefix(CLASS.revertTooltip)}`); + } + + public getInvalidMessageTooltip(): Locator { + return this.body.locator(`.dx-${CLASS.invalidMessage}.dx-${CLASS.invalidMessage}-always.${this.addWidgetPrefix(CLASS.invalidMessage)}`); + } + + public getEditForm(): EditForm { + const element = this.element.locator(`.${this.addWidgetPrefix(CLASS.editFormRow)}`); + const buttons = element.locator(`.${this.addWidgetPrefix(CLASS.formButtonsContainer)} .${CLASS.button}`); + + return new EditForm(element, buttons); + } + + public getPopupEditForm(): EditForm { + const element = this.page.locator(`.${this.addWidgetPrefix(CLASS.popupEdit)} .${CLASS.overlayContent}`); + const buttons = element.locator(`.${CLASS.toolbar} .${CLASS.button}`); + + return new EditForm(element, buttons); + } + + public getHeaderPanel(): HeaderPanel { + return new HeaderPanel( + this.element.locator(`.${this.addWidgetPrefix(CLASS.headerPanel)}`), + this.getName(), + ); + } + + public getGeneralStatusContainer(): Locator { + return this.element.locator(`[${E2E_ATTRIBUTES.a11yStatusContainer}="true"]`); + } + + public async apiEditRow(rowIndex: number): Promise { + await this.invoke('editRow', rowIndex); + } + + public async apiDeleteRow(rowIndex: number): Promise { + await this.invoke('deleteRow', rowIndex); + } + + public async apiExpandAdaptiveDetailRow(key: unknown): Promise { + await this.invoke('expandAdaptiveDetailRow', key); + } + + public async apiSaveEditData(): Promise { + await this.invoke('saveEditData'); + } + + public async apiEditCell(rowIndex: number, columnIndex: number): Promise { + await this.invoke('editCell', rowIndex, columnIndex); + } + + public async apiCellValue(rowIndex: number, columnIndex: number, value: T): Promise { + await this.invoke('cellValue', rowIndex, columnIndex, value); + } +} diff --git a/e2e/playwright/models/dataGrid/headers/cell.ts b/e2e/playwright/models/dataGrid/headers/cell.ts index 12815e239c92..847f04671461 100644 --- a/e2e/playwright/models/dataGrid/headers/cell.ts +++ b/e2e/playwright/models/dataGrid/headers/cell.ts @@ -1,8 +1,8 @@ import type { Locator } from '@playwright/test'; import { expect } from '@playwright/test'; -import FocusableElement from '../../internal/focusable'; +import GridFocusableElement from '../../gridCore/focusable'; -export default class HeaderCell extends FocusableElement { +export default class HeaderCell extends GridFocusableElement { constructor(headerRow: Locator, index: number) { super(headerRow.locator(`td[aria-colindex='${index + 1}']`)); } diff --git a/e2e/playwright/models/dataGrid/headers/headerFilter.ts b/e2e/playwright/models/dataGrid/headers/headerFilter.ts index d06f26c5fb83..6af8ad93c203 100644 --- a/e2e/playwright/models/dataGrid/headers/headerFilter.ts +++ b/e2e/playwright/models/dataGrid/headers/headerFilter.ts @@ -1,4 +1,5 @@ import type { Locator, Page } from '@playwright/test'; +import GridElement from '../../gridCore/element'; const CLASS = { filterMenu: 'dx-header-filter-menu', @@ -6,14 +7,12 @@ const CLASS = { button: 'dx-button', }; -export default class HeaderFilter { +export default class HeaderFilter extends GridElement { public readonly body: Locator; - public readonly element: Locator; - constructor(page: Page) { + super(page.locator('body').locator(`.${CLASS.filterMenu}`)); this.body = page.locator('body'); - this.element = this.body.locator(`.${CLASS.filterMenu}`); } public getButtons(): Locator { diff --git a/e2e/playwright/models/dataGrid/headers/index.ts b/e2e/playwright/models/dataGrid/headers/index.ts index f020609b21fe..f0bfa19a3fe7 100644 --- a/e2e/playwright/models/dataGrid/headers/index.ts +++ b/e2e/playwright/models/dataGrid/headers/index.ts @@ -19,7 +19,6 @@ export default class Headers extends GridModule { return new HeaderRow( this.element.locator(`${headersContainerSelector} .${CLASS.headerRow}:nth-child(${index + 1})`), - this.widgetName, ); } diff --git a/e2e/playwright/models/dataGrid/headers/panel.ts b/e2e/playwright/models/dataGrid/headers/panel.ts index f064e29072c2..d5be6931264a 100644 --- a/e2e/playwright/models/dataGrid/headers/panel.ts +++ b/e2e/playwright/models/dataGrid/headers/panel.ts @@ -3,10 +3,20 @@ import GridModule from '../../gridCore/module'; import ExportButton from './panelButtons/exportButton'; const CLASS = { + addRowButton: 'addrow-button', + saveButton: 'save-button', applyFilterButton: 'dx-apply-button', }; export default class HeaderPanel extends GridModule { + public getAddRowButton(): Locator { + return this.element.locator(`.${this.addWidgetPrefix(CLASS.addRowButton)}`); + } + + public getSaveButton(): Locator { + return this.element.locator(`.${this.addWidgetPrefix(CLASS.saveButton)}`); + } + public getExportButton(): ExportButton { return new ExportButton(this.element, this.widgetName); } diff --git a/e2e/playwright/models/dataGrid/headers/row.ts b/e2e/playwright/models/dataGrid/headers/row.ts index c20549e3aff5..4df72e4211c1 100644 --- a/e2e/playwright/models/dataGrid/headers/row.ts +++ b/e2e/playwright/models/dataGrid/headers/row.ts @@ -1,7 +1,7 @@ -import GridModule from '../../gridCore/module'; +import GridElement from '../../gridCore/element'; import HeaderCell from './cell'; -export default class HeaderRow extends GridModule { +export default class HeaderRow extends GridElement { public getHeaderCell(index: number): HeaderCell { return new HeaderCell(this.element, index); } diff --git a/e2e/playwright/models/dataGrid/index.ts b/e2e/playwright/models/dataGrid/index.ts index 6d2d07f64ed7..0d00f5f31b77 100644 --- a/e2e/playwright/models/dataGrid/index.ts +++ b/e2e/playwright/models/dataGrid/index.ts @@ -1,145 +1,8 @@ -import type { Locator, Page } from '@playwright/test'; import type { WidgetName } from '../types'; -import GridCore, { CLASS as CLASS_BASE } from '../gridCore'; -import DataRow from './data/row'; -import DataCell from './data/cell'; -import FilterCell from './filter/cell'; -import EditForm from './editForm'; -import Headers from './headers'; -import HeaderPanel from './headers/panel'; -import AdaptiveDetailRow from './adaptiveDetailRow'; +import GridBase from './gridBase'; -export const CLASS = { - ...CLASS_BASE, - headers: 'headers', - headerPanel: 'header-panel', - dataRow: 'dx-data-row', - fixedGridView: 'content-fixed', - editFormRow: 'edit-form', - button: 'dx-button', - formButtonsContainer: 'form-buttons-container', - popupEdit: 'edit-popup', - adaptiveDetailRow: 'dx-adaptive-detail-row', - errorRow: 'dx-error-row', - overlayContent: 'dx-overlay-content', - revertTooltip: 'revert-tooltip', - invalidMessage: 'invalid-message', - toolbar: 'dx-toolbar', - dialogWrapper: 'dx-dialog-wrapper', -}; - -const E2E_ATTRIBUTES = { - a11yStatusContainer: 'e2e-a11y-general-status-container', -}; - -export default class DataGrid extends GridCore { +export default class DataGrid extends GridBase { name: WidgetName = 'dxDataGrid'; compatibilityName: WidgetName = 'dxDataGrid'; - - public getHeaders(): Headers { - return new Headers(this.element.locator(`.${this.addWidgetPrefix(CLASS.headers)}`), this.getName()); - } - - public getDataRow(index: number): DataRow { - return new DataRow( - this.element.locator(`.${CLASS.dataRow}[aria-rowindex='${index + 1}']`), - this.getName(), - ); - } - - public getFixedDataRow(index: number): DataRow { - return new DataRow( - this.element.locator(`.${this.addWidgetPrefix(CLASS.fixedGridView)} .${CLASS.dataRow}[aria-rowindex='${index + 1}']`), - this.getName(), - ); - } - - public getDataCell(rowIndex: number, columnIndex: number): DataCell { - return this.getDataRow(rowIndex).getDataCell(columnIndex); - } - - public getFixedDataCell(rowIndex: number, columnIndex: number): DataCell { - return this.getFixedDataRow(rowIndex).getDataCell(columnIndex); - } - - public getAdaptiveRow(index: number): AdaptiveDetailRow { - return new AdaptiveDetailRow(this.element.locator(`.${CLASS.adaptiveDetailRow}`).nth(index)); - } - - public getErrorRow(): Locator { - return this.element.locator(`.${CLASS.errorRow}`); - } - - public getFilterCell(columnIndex: number): FilterCell { - return this.getHeaders().getFilterRow().getFilterCell(columnIndex); - } - - public getFilterEditor( - columnIndex: number, - EditorType: new (page: Page, element: Locator) => T, - ): T { - return this.getFilterCell(columnIndex).getEditor(EditorType); - } - - public getDialog(): Locator { - return this.body.locator(`.${CLASS.dialogWrapper}`); - } - - public getRevertTooltip(): Locator { - return this.body.locator(`.${this.addWidgetPrefix(CLASS.revertTooltip)}`); - } - - public getInvalidMessageTooltip(): Locator { - return this.body.locator(`.dx-${CLASS.invalidMessage}.dx-${CLASS.invalidMessage}-always.${this.addWidgetPrefix(CLASS.invalidMessage)}`); - } - - public getEditForm(): EditForm { - const element = this.element.locator(`.${this.addWidgetPrefix(CLASS.editFormRow)}`); - const buttons = element.locator(`.${this.addWidgetPrefix(CLASS.formButtonsContainer)} .${CLASS.button}`); - - return new EditForm(element, buttons); - } - - public getPopupEditForm(): EditForm { - const element = this.page.locator(`.${this.addWidgetPrefix(CLASS.popupEdit)} .${CLASS.overlayContent}`); - const buttons = element.locator(`.${CLASS.toolbar} .${CLASS.button}`); - - return new EditForm(element, buttons); - } - - public getHeaderPanel(): HeaderPanel { - return new HeaderPanel( - this.element.locator(`.${this.addWidgetPrefix(CLASS.headerPanel)}`), - this.getName(), - ); - } - - public getGeneralStatusContainer(): Locator { - return this.element.locator(`[${E2E_ATTRIBUTES.a11yStatusContainer}="true"]`); - } - - public async apiEditRow(rowIndex: number): Promise { - await this.invoke('editRow', rowIndex); - } - - public async apiDeleteRow(rowIndex: number): Promise { - await this.invoke('deleteRow', rowIndex); - } - - public async apiExpandAdaptiveDetailRow(key: unknown): Promise { - await this.invoke('expandAdaptiveDetailRow', key); - } - - public async apiSaveEditData(): Promise { - await this.invoke('saveEditData'); - } - - public async apiEditCell(rowIndex: number, columnIndex: number): Promise { - await this.invoke('editCell', rowIndex, columnIndex); - } - - public async apiCellValue(rowIndex: number, columnIndex: number, value: T): Promise { - await this.invoke('cellValue', rowIndex, columnIndex, value); - } } diff --git a/e2e/playwright/models/dataGrid/columnChooser.ts b/e2e/playwright/models/gridCore/columnChooser.ts similarity index 67% rename from e2e/playwright/models/dataGrid/columnChooser.ts rename to e2e/playwright/models/gridCore/columnChooser.ts index b576a893187e..8d0d6d697944 100644 --- a/e2e/playwright/models/dataGrid/columnChooser.ts +++ b/e2e/playwright/models/gridCore/columnChooser.ts @@ -1,29 +1,32 @@ import type { Locator } from '@playwright/test'; import { expect } from '@playwright/test'; -import FocusableElement from '../internal/focusable'; +import type { WidgetName } from '../types'; +import GridModule from './module'; const CLASS = { overlayContent: 'dx-overlay-content', overlayWrapper: 'dx-overlay-wrapper', - columnChooser: 'dx-datagrid-column-chooser', + columnChooser: 'column-chooser', checkbox: 'dx-checkbox', treeViewItem: 'dx-treeview-item', }; -export default class ColumnChooser extends FocusableElement { +export default class ColumnChooser extends GridModule { public readonly body: Locator; public readonly content: Locator; - constructor(element: Locator) { - super(element); + constructor(element: Locator, widgetName: WidgetName) { + super(element, widgetName); this.body = element.page().locator('body'); this.content = this.element.locator(`.${CLASS.overlayContent}`); } public async expectOpened(present = true): Promise { - const wrapper = this.body.locator(`.${CLASS.overlayWrapper}.${CLASS.columnChooser}`).first(); + const wrapper = this.body + .locator(`.${CLASS.overlayWrapper}.${this.addWidgetPrefix(CLASS.columnChooser)}`) + .first(); await (present ? expect(wrapper) : expect(wrapper).not).toBeAttached(); } diff --git a/e2e/playwright/models/gridCore/element.ts b/e2e/playwright/models/gridCore/element.ts new file mode 100644 index 000000000000..3271141b83ae --- /dev/null +++ b/e2e/playwright/models/gridCore/element.ts @@ -0,0 +1,9 @@ +import type { Locator } from '@playwright/test'; + +export default class GridElement { + public readonly element: Locator; + + constructor(element: Locator) { + this.element = element; + } +} diff --git a/e2e/playwright/models/gridCore/filter/panel.ts b/e2e/playwright/models/gridCore/filter/panel.ts index b91078b0ccb3..c49946969268 100644 --- a/e2e/playwright/models/gridCore/filter/panel.ts +++ b/e2e/playwright/models/gridCore/filter/panel.ts @@ -1,7 +1,7 @@ import type { Locator } from '@playwright/test'; import { expect } from '@playwright/test'; import type { WidgetName } from '../../types'; -import FocusableElement from '../../internal/focusable'; +import GridElement from '../element'; import GridModule from '../module'; const CLASS = { @@ -26,12 +26,12 @@ export default class FilterPanel extends GridModule { await (present ? expect(filterBuilder) : expect(filterBuilder).not).toBeAttached(); } - public getIconFilter(): FocusableElement { - return new FocusableElement(this.element.locator(`.${CLASS.filterPanelIcon}`)); + public getIconFilter(): GridElement { + return new GridElement(this.element.locator(`.${CLASS.filterPanelIcon}`)); } - public getFilterText(): FocusableElement { - return new FocusableElement( + public getFilterText(): GridElement { + return new GridElement( this.element.locator(`.${this.addWidgetPrefix(CLASS.filterPanelText)}`), ); } diff --git a/e2e/playwright/models/gridCore/focusable.ts b/e2e/playwright/models/gridCore/focusable.ts new file mode 100644 index 000000000000..d5be3be7f5c6 --- /dev/null +++ b/e2e/playwright/models/gridCore/focusable.ts @@ -0,0 +1,17 @@ +import { expectClass } from '../internal/classMatcher'; +import GridElement from './element'; + +const CLASS = { + focusVisible: 'dx-focused', + focusHidden: 'dx-cell-focus-disabled', +}; + +export default class GridFocusableElement extends GridElement { + public expectFocusVisible(present = true): Promise { + return expectClass(this.element, CLASS.focusVisible, present); + } + + public expectFocusHidden(present = true): Promise { + return expectClass(this.element, CLASS.focusHidden, present); + } +} diff --git a/e2e/playwright/models/gridCore/index.ts b/e2e/playwright/models/gridCore/index.ts index c31bbb7c1e6a..79cc736cd383 100644 --- a/e2e/playwright/models/gridCore/index.ts +++ b/e2e/playwright/models/gridCore/index.ts @@ -2,7 +2,7 @@ import type { Locator, Page } from '@playwright/test'; import type { WidgetName } from '../types'; import Widget from '../internal/widget'; import TextBox from '../textBox'; -import ColumnChooser from '../dataGrid/columnChooser'; +import ColumnChooser from './columnChooser'; import FilterPanel from './filter/panel'; export const CLASS = { @@ -34,7 +34,10 @@ export default abstract class GridCore extends Widget { } public getColumnChooser(): ColumnChooser { - return new ColumnChooser(this.body.locator(`.${this.addWidgetPrefix(CLASS.columnChooser)}`)); + return new ColumnChooser( + this.body.locator(`.${this.addWidgetPrefix(CLASS.columnChooser)}`), + this.getName(), + ); } public getColumnChooserButton(): Locator { diff --git a/e2e/playwright/models/gridCore/module.ts b/e2e/playwright/models/gridCore/module.ts index 492c06dadd16..699666852362 100644 --- a/e2e/playwright/models/gridCore/module.ts +++ b/e2e/playwright/models/gridCore/module.ts @@ -1,9 +1,9 @@ import type { Locator } from '@playwright/test'; import type { WidgetName } from '../types'; -import FocusableElement from '../internal/focusable'; import Widget from '../internal/widget'; +import GridElement from './element'; -export default class GridModule extends FocusableElement { +export default class GridModule extends GridElement { public readonly widgetName: WidgetName; constructor(element: Locator, widgetName: WidgetName) { diff --git a/e2e/playwright/models/internal/focusable.ts b/e2e/playwright/models/internal/focusable.ts index a3f5771f10e3..824e2adc62e0 100644 --- a/e2e/playwright/models/internal/focusable.ts +++ b/e2e/playwright/models/internal/focusable.ts @@ -1,10 +1,8 @@ import type { Locator } from '@playwright/test'; -import { expect } from '@playwright/test'; -import { classMatcher } from './classMatcher'; +import { expectClass } from './classMatcher'; const CLASS = { focusedState: 'dx-state-focused', - hiddenFocusedState: 'dx-cell-focus-disabled', }; export default class FocusableElement { @@ -14,15 +12,7 @@ export default class FocusableElement { this.element = element; } - public async expectFocusedState(present = true): Promise { - const assertion = expect(this.element); - - await (present ? assertion : assertion.not).toHaveClass(classMatcher(CLASS.focusedState)); - } - - public async expectHiddenFocusState(present = true): Promise { - const assertion = expect(this.element); - - await (present ? assertion : assertion.not).toHaveClass(classMatcher(CLASS.hiddenFocusedState)); + public expectFocusedState(present = true): Promise { + return expectClass(this.element, CLASS.focusedState, present); } } diff --git a/e2e/playwright/models/treeList/index.ts b/e2e/playwright/models/treeList/index.ts index ee2709b33b64..71c38c0711ba 100644 --- a/e2e/playwright/models/treeList/index.ts +++ b/e2e/playwright/models/treeList/index.ts @@ -1,12 +1,12 @@ import type { Locator } from '@playwright/test'; import type { WidgetName } from '../types'; -import DataGrid from '../dataGrid'; +import GridBase from '../dataGrid/gridBase'; const CLASS = { treeList: 'dx-treelist-container', }; -export default class TreeList extends DataGrid { +export default class TreeList extends GridBase { name: WidgetName = 'dxTreeList'; compatibilityName: WidgetName = 'dxTreeList'; diff --git a/e2e/playwright/tests/accessibility/cardView/columnSortable.spec.ts b/e2e/playwright/tests/accessibility/cardView/columnSortable.spec.ts index b082027b4e5f..8b1890c2d5e4 100644 --- a/e2e/playwright/tests/accessibility/cardView/columnSortable.spec.ts +++ b/e2e/playwright/tests/accessibility/cardView/columnSortable.spec.ts @@ -25,7 +25,7 @@ test('headerPanel dragging column when it has sorting and headerFilter', async ( }); const cardView = new CardView(page, CARD_VIEW_SELECTOR); - const columnElement = cardView.getHeaders().getHeaderItemNth(0).element; + const columnElement = cardView.getHeaderPanel().getHeaderItem(0).element; await triggerDragStart(columnElement); diff --git a/e2e/playwright/tests/accessibility/dataGrid/fixedColumns.spec.ts b/e2e/playwright/tests/accessibility/dataGrid/fixedColumns.spec.ts index fbf200e66efa..22d6ae7f112a 100644 --- a/e2e/playwright/tests/accessibility/dataGrid/fixedColumns.spec.ts +++ b/e2e/playwright/tests/accessibility/dataGrid/fixedColumns.spec.ts @@ -76,7 +76,7 @@ test('Accessibility: Scrollable should have focusable element when navigate thro ? dataGrid.getFixedDataCell(0, columnIndex) : dataGrid.getDataCell(0, columnIndex); - await cell.expectFocused(); + await cell.expectFocusVisible(); // it makes sense to check accessibility only if fixed column is focused const needCheckA11y = columnsByFixing[columnIndex]; @@ -124,7 +124,7 @@ test('Accessibility: Scrollable should have focusable element when click out of // focus through data row to last cell await pressKey(page, 'Tab', COLUMNS_LENGTH - 1); - await dataGrid.getFixedDataCell(0, COLUMNS_LENGTH - 1).expectFocused(); + await dataGrid.getFixedDataCell(0, COLUMNS_LENGTH - 1).expectFocusVisible(); // focus out rows view by outside click const dataGridOffsetBottom = await dataGrid.element.evaluate( @@ -173,7 +173,7 @@ test('Accessibility: Scrollable should have focusable when fixed on the right si // focus through data row till last cell (which is fixed) await pressKey(page, 'Tab', COLUMNS_LENGTH); - await dataGrid.getFixedDataCell(0, COLUMNS_LENGTH - 1).expectFocused(); + await dataGrid.getFixedDataCell(0, COLUMNS_LENGTH - 1).expectFocusVisible(); await a11yCheck(page); }); diff --git a/e2e/playwright/tests/cardView/columnSortable/utils.ts b/e2e/playwright/tests/cardView/columnSortable/utils.ts index 328c8421e090..c2ed18998cfa 100644 --- a/e2e/playwright/tests/cardView/columnSortable/utils.ts +++ b/e2e/playwright/tests/cardView/columnSortable/utils.ts @@ -52,10 +52,8 @@ export const getColumnItem = ( index: number, source: 'headerPanel' | 'columnChooser' = 'headerPanel', ): Locator => { - const headers = cardView.getHeaders(); - if (source === 'headerPanel') { - return headers.getHeaderItemNth(index).element; + return cardView.getHeaderPanel().getHeaderItem(index).element; } // A Playwright locator does not match a scope that is itself the first part of the selector, diff --git a/e2e/playwright/tests/dataGrid/common/editing/T1154721_editingCellFocus.spec.ts b/e2e/playwright/tests/dataGrid/common/editing/T1154721_editingCellFocus.spec.ts new file mode 100644 index 000000000000..b82f06b30566 --- /dev/null +++ b/e2e/playwright/tests/dataGrid/common/editing/T1154721_editingCellFocus.spec.ts @@ -0,0 +1,102 @@ +import { expect, test } from '../../../../fixtures'; +import { mockApi } from '../../../../helpers/apiMock'; +import { createWidget } from '../../../../helpers/createWidget'; +import DataGrid from '../../../../models/dataGrid'; +import { typeText } from '../../helpers/typeText'; + +const apiRequestMock = [{ + url: /\/api\/data/, + body: { + data: [ + { + id: 0, + data: 'A', + }, { + id: 1, + data: 'B', + }, { + id: 2, + data: 'C', + }, + ], + }, +}, { + url: /\/api\/update/, + body: {}, +}]; + +test.describe('Editing - cell focus', () => { + // T1154721 + test('Should allow focus next editor in the same column after save changes with local data source', async ({ page }) => { + await createWidget(page, 'dxDataGrid', { + keyExpr: 'id', + dataSource: [{ + id: 0, + data: 'A', + }, { + id: 1, + data: 'B', + }, { + id: 2, + data: 'C', + }], + editing: { + allowUpdating: true, + refreshMode: 'repaint', + mode: 'cell', + }, + columns: [{ + dataField: 'data', + showEditorAlways: true, + }], + repaintChangesOnly: true, + }); + + const dataGrid = new DataGrid(page, '#container'); + const firstCell = dataGrid.getDataCell(0, 0); + const middleCell = dataGrid.getDataCell(1, 0); + const secondCell = dataGrid.getDataCell(2, 0); + + await typeText(firstCell.getEditor().element, ' AAA'); + await typeText(secondCell.getEditor().element, ' CCC'); + await middleCell.element.click(); + + await expect(firstCell.getEditor().element).toHaveValue('A AAA'); + await expect(secondCell.getEditor().element).toHaveValue('C CCC'); + }); + + // T1037019 + test('Should allow focus next editor in the same column after save changes with remote data source', async ({ page }) => { + await mockApi(page, apiRequestMock); + await createWidget(page, 'dxDataGrid', () => ({ + keyExpr: 'id', + dataSource: (window as any).DevExpress.data.AspNet.createStore({ + key: 'id', + loadUrl: 'https://api/data', + updateUrl: 'https://api/update', + }), + editing: { + allowUpdating: true, + refreshMode: 'repaint', + mode: 'cell', + }, + columns: [{ + dataField: 'data', + showEditorAlways: true, + }], + repaintChangesOnly: true, + })); + + const dataGrid = new DataGrid(page, '#container'); + const firstCell = dataGrid.getDataCell(0, 0); + const middleCell = dataGrid.getDataCell(1, 0); + const secondCell = dataGrid.getDataCell(2, 0); + + await typeText(firstCell.getEditor().element, ' AAA'); + await typeText(secondCell.getEditor().element, ' CCC'); + await middleCell.element.click(); + + await expect(firstCell.getEditor().element).toHaveValue('A AAA'); + await expect(secondCell.getEditor().element).toHaveValue('C CCC'); + }); +}); diff --git a/e2e/playwright/tests/dataGrid/common/editing/T1323684_readonlyEditorNewRow.spec.ts b/e2e/playwright/tests/dataGrid/common/editing/T1323684_readonlyEditorNewRow.spec.ts new file mode 100644 index 000000000000..54b0e1b3c3b3 --- /dev/null +++ b/e2e/playwright/tests/dataGrid/common/editing/T1323684_readonlyEditorNewRow.spec.ts @@ -0,0 +1,166 @@ +import type { GridsEditMode } from 'devextreme/ui/data_grid'; +import { expect, test } from '../../../../fixtures'; +import { createWidget } from '../../../../helpers/createWidget'; +import DataGrid from '../../../../models/dataGrid'; +import { classMatcher } from '../../../../models/internal/classMatcher'; +import { getFirstDataRow } from '../../helpers/getFirstDataRow'; +import { typeText } from '../../helpers/typeText'; + +const READONLY_CLASS = 'dx-datagrid-readonly'; +const CELL_FOCUS_DISABLED_CLASS = 'dx-cell-focus-disabled'; + +test.describe('Editing - showEditorAlways cell in new row should be editable (T1323684)', () => { + (['cell', 'batch'] as GridsEditMode[]).forEach((mode) => { + test(`showEditorAlways editor should be editable in a new row when allowUpdating is false, ${mode} mode`, async ({ page }) => { + await createWidget(page, 'dxDataGrid', { + keyExpr: 'ID', + dataSource: [ + { ID: 1, FirstName: 'John', LastName: 'Heart' }, + { ID: 2, FirstName: 'Olivia', LastName: 'Peyton' }, + ], + showBorders: true, + editing: { + mode, + allowUpdating: false, + allowAdding: true, + }, + columns: [ + 'LastName', + { dataField: 'FirstName', showEditorAlways: true }, + ], + }); + + const dataGrid = new DataGrid(page, '#container'); + const addRowButton = dataGrid.getHeaderPanel().getAddRowButton(); + + await addRowButton.click(); + + const newRow = getFirstDataRow(dataGrid); + await newRow.expectInserted(); + + const cell = newRow.getDataCell(1); + const editor = cell.getEditor(); + + await expect(cell.element, 'showEditorAlways cell in new row should not have readonly class') + .not.toHaveClass(classMatcher(READONLY_CLASS)); + await expect(cell.element, 'showEditorAlways cell in new row should not have cell-focus-disabled class') + .not.toHaveClass(classMatcher(CELL_FOCUS_DISABLED_CLASS)); + + await editor.element.click(); + await cell.expectFocusVisible(); + await expect(editor.element, 'editor should be focused after click').toBeFocused(); + await typeText(editor.element, 'test value', { replace: true }); + await expect(editor.element).toHaveValue('test value'); + }); + + test(`Boolean editor should be editable in a new row when allowUpdating is false, ${mode} mode`, async ({ page }) => { + await createWidget(page, 'dxDataGrid', { + keyExpr: 'ID', + dataSource: [ + { ID: 1, Name: 'John', Active: false }, + { ID: 2, Name: 'Olivia', Active: true }, + ], + showBorders: true, + editing: { + mode, + allowUpdating: false, + allowAdding: true, + }, + columns: [ + 'Name', + { dataField: 'Active', dataType: 'boolean' }, + ], + }); + + const dataGrid = new DataGrid(page, '#container'); + const addRowButton = dataGrid.getHeaderPanel().getAddRowButton(); + + await addRowButton.click(); + + const newRow = getFirstDataRow(dataGrid); + await newRow.expectInserted(); + + const booleanCell = newRow.getDataCell(1); + + await expect(booleanCell.element, 'boolean cell in new row should not have readonly class') + .not.toHaveClass(classMatcher(READONLY_CLASS)); + + // The checkbox sits at the center of the cell: click beside it to focus the cell only. + await booleanCell.element.click({ position: { x: 5, y: 5 } }); + await booleanCell.getCheckbox().click(); + await booleanCell.getEditor().expectChecked(); + }); + + test(`showEditorAlways editor in existing rows should remain readonly when allowUpdating is false, ${mode} mode`, async ({ page }) => { + await createWidget(page, 'dxDataGrid', { + keyExpr: 'ID', + dataSource: [ + { ID: 1, FirstName: 'John', LastName: 'Heart' }, + { ID: 2, FirstName: 'Olivia', LastName: 'Peyton' }, + ], + showBorders: true, + editing: { + mode, + allowUpdating: false, + allowAdding: true, + }, + columns: [ + 'LastName', + { dataField: 'FirstName', showEditorAlways: true }, + ], + }); + + const dataGrid = new DataGrid(page, '#container'); + const existingCell = dataGrid.getDataCell(0, 1); + + await expect(existingCell.element, 'showEditorAlways cell in existing row should have readonly class when allowUpdating is false') + .toHaveClass(classMatcher(READONLY_CLASS)); + + await existingCell.getEditor().element.click(); + await expect(existingCell.element, 'showEditorAlways cell in existing row should remain readonly after click') + .toHaveClass(classMatcher(READONLY_CLASS)); + }); + }); + + test('showEditorAlways editor should be editable in a new row when allowUpdating is a function returning false, cell mode', async ({ page }) => { + await createWidget(page, 'dxDataGrid', () => ({ + keyExpr: 'ID', + dataSource: [ + { ID: 1, FirstName: 'John', LastName: 'Heart' }, + { ID: 2, FirstName: 'Olivia', LastName: 'Peyton' }, + ], + showBorders: true, + editing: { + mode: 'cell' as GridsEditMode, + allowUpdating: () => false, + allowAdding: true, + }, + columns: [ + 'LastName', + { dataField: 'FirstName', showEditorAlways: true }, + ], + })); + + const dataGrid = new DataGrid(page, '#container'); + const addRowButton = dataGrid.getHeaderPanel().getAddRowButton(); + + await addRowButton.click(); + + const newRow = getFirstDataRow(dataGrid); + await newRow.expectInserted(); + + const cell = newRow.getDataCell(1); + const editor = cell.getEditor(); + + await expect(cell.element, 'showEditorAlways cell in new row should not have readonly class') + .not.toHaveClass(classMatcher(READONLY_CLASS)); + await expect(cell.element, 'showEditorAlways cell in new row should not have cell-focus-disabled class') + .not.toHaveClass(classMatcher(CELL_FOCUS_DISABLED_CLASS)); + + await editor.element.click(); + await cell.expectFocusVisible(); + await expect(editor.element, 'editor should be focused after click').toBeFocused(); + await typeText(editor.element, 'test value', { replace: true }); + await expect(editor.element).toHaveValue('test value'); + }); +}); diff --git a/e2e/playwright/tests/dataGrid/common/editing/editing.functional_matrix.spec.ts b/e2e/playwright/tests/dataGrid/common/editing/editing.functional_matrix.spec.ts new file mode 100644 index 000000000000..0d8940c2a038 --- /dev/null +++ b/e2e/playwright/tests/dataGrid/common/editing/editing.functional_matrix.spec.ts @@ -0,0 +1,615 @@ +import type { Locator, Page } from '@playwright/test'; +import type { GridsEditMode } from 'devextreme/ui/data_grid'; +import { expect, test } from '../../../../fixtures'; +import { createWidget } from '../../../../helpers/createWidget'; +import Calendar from '../../../../models/calendar'; +import DataGrid from '../../../../models/dataGrid'; +import type DataCell from '../../../../models/dataGrid/data/cell'; +import { CellEditor } from '../../../../models/dataGrid/data/cellEditor'; +import type EditForm from '../../../../models/dataGrid/editForm'; +import List from '../../../../models/list'; +import { clickWithOffset } from '../../helpers/clickWithOffset'; +import { typeText } from '../../helpers/typeText'; + +interface ColumnInfo { + columnIndex: number; + dataField: string; + newValue: string; + newMaskValue?: string; +} + +const editingModes: GridsEditMode[] = ['cell', 'batch', 'row', 'form', 'popup']; + +const textColumnInfos: ColumnInfo[] = [ + { columnIndex: 0, dataField: 'text', newValue: 'xxxx' }, + { columnIndex: 5, dataField: 'calculated', newValue: '9' }, +]; + +const expectedTextColumnResult: ColumnInfo[] = [ + ...textColumnInfos, + { columnIndex: 1, dataField: 'number', newValue: '8' }, +]; + +const maskedColumnInfos: ColumnInfo[] = [ + { + columnIndex: 0, dataField: 'text', newValue: 'xxxx', newMaskValue: 'xxxxx', + }, + { + columnIndex: 1, dataField: 'number', newValue: '-9', newMaskValue: '9-', + }, + { + columnIndex: 2, dataField: 'date', newValue: '10/1/2020', newMaskValue: '101', + }, +]; + +const expectedMaskedColumnResult: ColumnInfo[] = [ + ...maskedColumnInfos, + { columnIndex: 5, dataField: 'calculated', newValue: '-8' }, +]; + +const basicColumnInfos: ColumnInfo[] = [ + { columnIndex: 0, dataField: 'text', newValue: 'xxxx' }, + { columnIndex: 1, dataField: 'number', newValue: '-9' }, + { columnIndex: 2, dataField: 'date', newValue: '10/1/2020' }, + { columnIndex: 3, dataField: 'lookup', newValue: 'lookup 2' }, + { columnIndex: 4, dataField: 'boolean', newValue: 'true' }, +]; + +const expectedBasicColumnResult: ColumnInfo[] = [ + ...basicColumnInfos, + { columnIndex: 5, dataField: 'calculated', newValue: '-8' }, +]; + +const createDataGrid = async (page: Page, { + mode, repaintChangesOnly = false, useMask = false, +}: { + mode: GridsEditMode; + repaintChangesOnly?: boolean; + useMask?: boolean; +}): Promise => createWidget(page, 'dxDataGrid', (arg) => ({ + keyExpr: 'id', + dataSource: [ + { + id: 1, text: 'text 1', number: 1, date: '2020-10-27', boolean: false, lookup: 1, + }, + { + id: 2, text: 'text 2', number: 2, date: '2020-10-28', boolean: true, lookup: 2, + }, + ], + repaintChangesOnly: arg.repaintChangesOnly, + editing: { + mode: arg.mode, + allowUpdating: true, + }, + columns: [ + { + dataField: 'text', + editorOptions: { + mask: arg.useMask ? 'cccc' : undefined, + }, + }, + { + dataField: 'number', + editorOptions: { + format: '#0', + useMaskBehavior: arg.useMask, + }, + }, + { + dataField: 'date', + dataType: 'date', + editorOptions: { + useMaskBehavior: arg.useMask, + pickerType: 'calendar', + }, + }, + { + dataField: 'lookup', + lookup: { + valueExpr: 'id', + displayExpr: 'text', + dataSource: [ + { id: 1, text: 'lookup 1' }, + { id: 2, text: 'lookup 2' }, + ], + }, + }, + { dataField: 'boolean' }, + { + dataField: 'calculated', + calculateCellValue: (data): number => (data as { number: number }).number + 1, + setCellValue: (newData, value): void => { + // eslint-disable-next-line no-param-reassign + newData.number = value - 1; + }, + }, + ], +}), '#container', { arg: { mode, repaintChangesOnly, useMask } }); + +const getEditForm = (dataGrid: DataGrid, mode: GridsEditMode): EditForm | null => { + if (mode === 'form') { + return dataGrid.getEditForm(); + } + if (mode === 'popup') { + return dataGrid.getPopupEditForm(); + } + return null; +}; + +const clickEditButtonIfExists = async ( + dataGrid: DataGrid, + form: EditForm | null, +): Promise => { + // The drop-down overlays of the lookup and date editors in the popup match the form selector too. + const formAlreadyOpened = await form?.element.first().isVisible(); + + if (formAlreadyOpened) { + return; + } + + const editButton = dataGrid.getDataRow(0).getCommandCell(6).getEditButton(); + + if (await editButton.count() > 0) { + await editButton.click(); + } +}; + +const checkCellFocused = async ( + mode: GridsEditMode, + { dataField }: ColumnInfo, + cell: DataCell | undefined, + editor: CellEditor | undefined, +): Promise => { + const isRowBasedMode = mode === 'row'; + const isFormBasedMode = mode === 'form' || mode === 'popup'; + + if (!isFormBasedMode) { + expect(cell).toBeDefined(); + await cell!.expectFocusVisible(); + } + + if ((isRowBasedMode || isFormBasedMode) && dataField === 'boolean') { + return; + } + + expect(editor).toBeDefined(); + await expect(editor!.element).toBeAttached(); + await expect(editor!.element).toBeFocused(); +}; + +const clickCellEditor = async ( + dataGrid: DataGrid, + mode: GridsEditMode, + columnInfo: ColumnInfo, + form: EditForm | null, + cell: DataCell, + editor: CellEditor, +): Promise => { + await clickEditButtonIfExists(dataGrid, form); + + const item = !form ? cell.element : editor.getItemLabel(); + await clickWithOffset(item, 25); + + await checkCellFocused(mode, columnInfo, cell, editor); +}; + +const moveToFirstCellEditor = async ( + page: Page, + dataGrid: DataGrid, + mode: GridsEditMode, +): Promise => { + await page.keyboard.press('Tab'); + await page.keyboard.press('Control+ArrowDown'); + await page.keyboard.press('Enter'); + + if (mode === 'popup') { + const columns: unknown[] = await dataGrid.apiOption('columns'); + + for (const key of columns.map(() => 'Tab')) { + await page.keyboard.press(key); + } + + await page.keyboard.press('Enter'); + } +}; + +const getLookupItem = (page: Page, text: string): Locator => new List(page, '.dx-list') + .items + .filter({ hasText: text }); + +const setEditorValue = async ( + page: Page, + mode: GridsEditMode, + { dataField, newMaskValue, newValue }: ColumnInfo, + editor: CellEditor, + useKeyboard = false, + useMask = false, +): Promise => { + if (dataField === 'boolean') { + if (useKeyboard) { + await page.keyboard.press('Space'); + } else { + await editor.element.click(); + } + + return; + } + + const value: string = useMask ? newMaskValue ?? '' : newValue; + + if (dataField === 'date' && !useKeyboard && !useMask) { + await editor.getDropDownButton().click(); + await new Calendar(page, '.dx-calendar').getView().getCellByDate(new Date(value)).click(); + + return; + } + + if (dataField === 'lookup' && !useKeyboard) { + if (mode === 'cell' || mode === 'batch') { + await editor.getDropDownButton().click(); + } + await getLookupItem(page, value).click(); + + return; + } + + await typeText(editor.element, value, { replace: true }); + + if (dataField === 'lookup' && useKeyboard) { + await getLookupItem(page, value).waitFor({ state: 'attached' }); + await page.keyboard.press('Enter'); + } +}; + +const focusNextCellEditor = async ( + page: Page, + dataGrid: DataGrid, + mode: GridsEditMode, + { columnIndex }: ColumnInfo, + useKeyboard = false, +): Promise<{ nextColumnIndex: number }> => { + const form = getEditForm(dataGrid, mode); + const nextColumnIndex = columnIndex === 0 ? 1 : columnIndex - 1; + const nextColumnInfo = basicColumnInfos[nextColumnIndex]; + + // eslint-disable-next-line @typescript-eslint/init-declarations + let nextEditor: CellEditor | undefined; + // eslint-disable-next-line @typescript-eslint/init-declarations + let nextCell: DataCell | undefined; + + if (form) { + if (nextColumnInfo) { + nextEditor = new CellEditor(form.getItem(nextColumnInfo.dataField)); + if (useKeyboard) { + await page.keyboard.press(columnIndex === 0 ? 'Tab' : 'Shift+Tab'); + } else { + await nextEditor.element.click(); + } + } + } else { + nextCell = dataGrid.getDataCell(0, nextColumnIndex); + nextEditor = nextCell.getEditor(); + + if (useKeyboard) { + await page.keyboard.press(columnIndex === 0 ? 'Tab' : 'Shift+Tab'); + } else { + const isCellRevertBug = mode === 'cell' && columnIndex < nextColumnIndex; + await clickWithOffset(nextCell.element, isCellRevertBug ? 50 : 5); + } + } + + await checkCellFocused(mode, nextColumnInfo, nextCell, nextEditor); + + return { nextColumnIndex }; +}; + +const getSaveButton = ( + page: Page, + dataGrid: DataGrid, + mode: string, + form: EditForm | null, +): Locator | undefined => { + switch (mode) { + case 'batch': + return dataGrid.getHeaderPanel().getSaveButton(); + case 'row': + return dataGrid.getDataRow(0).getCommandCell(6).getButton(0); + case 'cell': + return page.locator('body'); + default: + return form?.saveButton; + } +}; + +const expectCellText = async ( + { dataField, newValue }: ColumnInfo, + cell: DataCell, +): Promise => { + if (dataField === 'boolean') { + await cell.getEditor().expectChecked(newValue === 'true'); + } else { + await expect(cell.element).toHaveText(newValue); + } +}; + +const expectEditorValue = async ( + { dataField, newValue }: ColumnInfo, + editor: CellEditor, +): Promise => { + if (dataField === 'boolean') { + await editor.expectChecked(newValue === 'true'); + } else { + await expect(editor.element).toHaveValue(newValue); + } +}; + +const checkSavedCell = async ( + dataGrid: DataGrid, + columnInfo: ColumnInfo, + cell: DataCell, +): Promise => { + await expectCellText(columnInfo, cell); + await cell.expectEditCell(columnInfo.dataField === 'boolean'); + await cell.expectModified(false); + await expect(dataGrid.getModifiedCells()).toHaveCount(0); +}; + +const checkModifiedCell = async ( + dataGrid: DataGrid, + mode: string, + columnInfo: ColumnInfo, + cell: DataCell, + editor: CellEditor, + modifiedCellsCount: number, +): Promise => { + if (mode === 'batch' || mode === 'cell') { + await expectCellText(columnInfo, cell); + } else { + await expectEditorValue(columnInfo, editor); + } + + if (mode !== 'form' && mode !== 'popup') { + await cell.expectEditCell(mode === 'row' || columnInfo.dataField === 'boolean'); + await cell.expectModified(mode === 'batch'); + await expect(dataGrid.getModifiedCells()).toHaveCount(modifiedCellsCount); + } +}; + +test.describe('Editing.FunctionalMatrix', () => { + editingModes.forEach((mode) => { + const configurations = [ + { + repaintChangesOnly: true, + useMask: false, + columnInfos: textColumnInfos, + expectedResult: expectedTextColumnResult, + }, + { + repaintChangesOnly: false, + useMask: true, + columnInfos: maskedColumnInfos, + expectedResult: expectedMaskedColumnResult, + }, + { + repaintChangesOnly: false, + useMask: false, + columnInfos: basicColumnInfos, + expectedResult: expectedBasicColumnResult, + }, + ]; + + configurations.forEach(({ + repaintChangesOnly, useMask, columnInfos, expectedResult, + }) => { + test(`Update cell value, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}, useKeyboard: false, useMask: ${useMask}`, async ({ page }) => { + await createDataGrid(page, { mode, useMask, repaintChangesOnly }); + + const dataGrid = new DataGrid(page, '#container'); + const form = getEditForm(dataGrid, mode); + + if (mode === 'batch') { + await dataGrid.apiCellValue(0, 0, 'modified'); + } + + for (const columnInfo of columnInfos) { + const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); + const editor = form + ? new CellEditor(form.getItem(columnInfo.dataField)) + : cell.getEditor(); + + await clickCellEditor(dataGrid, mode, columnInfo, form, cell, editor); + await setEditorValue(page, mode, columnInfo, editor, false, useMask); + await expect.poll(() => dataGrid.isReady()).toBe(true); + } + + const saveButton = getSaveButton(page, dataGrid, mode, form); + + if (saveButton) { + await clickWithOffset(saveButton, 5, 5); + } + + for (const columnInfo of expectedResult) { + const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); + + await checkSavedCell(dataGrid, columnInfo, cell); + } + }); + }); + + [true, false].forEach((repaintChangesOnly) => { + test(`Update calculated cell value, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}, useKeyboard: false, useMask:false`, async ({ page }) => { + await createDataGrid(page, { mode, repaintChangesOnly }); + + const dataGrid = new DataGrid(page, '#container'); + const columnInfo = { columnIndex: 5, dataField: 'calculated', newValue: '9' }; + const form = getEditForm(dataGrid, mode); + const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); + const editor = form ? new CellEditor(form.getItem(columnInfo.dataField)) : cell.getEditor(); + + await expect.poll(() => dataGrid.isReady()).toBe(true); + + await clickCellEditor(dataGrid, mode, columnInfo, form, cell, editor); + await setEditorValue(page, mode, columnInfo, editor); + + const saveButton = getSaveButton(page, dataGrid, mode, form); + + if (saveButton) { + if (!repaintChangesOnly && (mode === 'row' || mode === 'form')) { + await page.locator('body').click(); + } + + await clickWithOffset(saveButton, 5, 5); + } + + const expectedColumnResult: ColumnInfo[] = [ + { columnIndex: 1, dataField: 'number', newValue: '8' }, + { columnIndex: 5, dataField: 'calculated', newValue: '9' }, + ]; + + for (const resultColumnInfo of expectedColumnResult) { + await checkSavedCell( + dataGrid, + resultColumnInfo, + dataGrid.getDataCell(0, resultColumnInfo.columnIndex), + ); + } + }); + }); + + const keyboardConfigurations = [ + { + useMask: true, + columnInfos: maskedColumnInfos, + expectedResult: expectedMaskedColumnResult, + }, + { + useMask: false, + columnInfos: basicColumnInfos, + expectedResult: expectedBasicColumnResult, + }, + ]; + + keyboardConfigurations.forEach(({ useMask, columnInfos, expectedResult }) => { + test(`Update cell value, mode: ${mode}, repaintChangesOnly: false, useKeyboard: true, useMask: ${useMask}`, async ({ page }) => { + await createDataGrid(page, { mode, useMask }); + + const dataGrid = new DataGrid(page, '#container'); + const form = getEditForm(dataGrid, mode); + + await expect.poll(() => dataGrid.isReady()).toBe(true); + await moveToFirstCellEditor(page, dataGrid, mode); + + for (const columnInfo of columnInfos) { + const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); + const editor = form + ? new CellEditor(form.getItem(columnInfo.dataField)) + : cell.getEditor(); + + if (columnInfo.columnIndex > 0) { + await page.keyboard.press('Tab'); + } + + await checkCellFocused(mode, columnInfo, cell, editor); + await setEditorValue(page, mode, columnInfo, editor, true, useMask); + } + + await page.keyboard.press('Enter'); + + if (mode === 'batch' || mode === 'popup') { + const saveButton = getSaveButton(page, dataGrid, mode, form); + + if (saveButton) { + await clickWithOffset(saveButton, 5, 5); + } + } + + for (const columnInfo of expectedResult) { + const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); + + await checkSavedCell(dataGrid, columnInfo, cell); + } + }); + }); + + test(`Update cell value and focus next cell, mode: ${mode}, repaintChangesOnly: false, useKeyboard: true`, async ({ page }) => { + await createDataGrid(page, { mode }); + + const dataGrid = new DataGrid(page, '#container'); + const form = getEditForm(dataGrid, mode); + let activeColumnIndex = 0; + let modifiedCellCount = mode === 'batch' ? 1 : 0; + + await expect.poll(() => dataGrid.isReady()).toBe(true); + await moveToFirstCellEditor(page, dataGrid, mode); + + for (const columnInfo of textColumnInfos) { + const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); + const editor = form ? new CellEditor(form.getItem(columnInfo.dataField)) : cell.getEditor(); + + for (let i = activeColumnIndex; i < columnInfo.columnIndex; i += 1) { + await page.keyboard.press('Tab'); + + // The grid moves the focus asynchronously and drops a Tab pressed before it is done. + const passedColumnInfo = basicColumnInfos[i + 1]; + + if (passedColumnInfo && i + 1 < columnInfo.columnIndex) { + const passedCell = dataGrid.getDataCell(0, i + 1); + const passedEditor = form + ? new CellEditor(form.getItem(passedColumnInfo.dataField)) + : passedCell.getEditor(); + + await checkCellFocused(mode, passedColumnInfo, passedCell, passedEditor); + } + } + + await checkCellFocused(mode, columnInfo, cell, editor); + await setEditorValue(page, mode, columnInfo, editor, true); + + const { nextColumnIndex } = await focusNextCellEditor( + page, + dataGrid, + mode, + columnInfo, + true, + ); + activeColumnIndex = nextColumnIndex; + + if (mode === 'batch') { + modifiedCellCount += 1; + } + + await checkModifiedCell(dataGrid, mode, columnInfo, cell, editor, modifiedCellCount); + } + }); + + [true, false].forEach((repaintChangesOnly) => { + test(`Update cell value and focus next cell, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}, useKeyboard: false`, async ({ page }) => { + await createDataGrid(page, { mode, repaintChangesOnly }); + + const dataGrid = new DataGrid(page, '#container'); + const form = getEditForm(dataGrid, mode); + let modifiedCellCount = mode === 'batch' ? 1 : 0; + + await expect.poll(() => dataGrid.isReady()).toBe(true); + + for (const columnInfo of textColumnInfos) { + const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); + const editor = form + ? new CellEditor(form.getItem(columnInfo.dataField)) + : cell.getEditor(); + + await clickCellEditor(dataGrid, mode, columnInfo, form, cell, editor); + await setEditorValue(page, mode, columnInfo, editor); + + await focusNextCellEditor(page, dataGrid, mode, columnInfo); + + if (mode === 'batch') { + modifiedCellCount += 1; + } + + await checkModifiedCell(dataGrid, mode, columnInfo, cell, editor, modifiedCellCount); + } + }); + }); + }); +}); diff --git a/e2e/playwright/tests/dataGrid/common/editing/editingNewRow.functional_matrix.spec.ts b/e2e/playwright/tests/dataGrid/common/editing/editingNewRow.functional_matrix.spec.ts new file mode 100644 index 000000000000..e324c669200d --- /dev/null +++ b/e2e/playwright/tests/dataGrid/common/editing/editingNewRow.functional_matrix.spec.ts @@ -0,0 +1,231 @@ +import type { Locator, Page } from '@playwright/test'; +import type { GridsEditMode } from 'devextreme/ui/data_grid'; +import { expect, test } from '../../../../fixtures'; +import { createWidget } from '../../../../helpers/createWidget'; +import DataGrid from '../../../../models/dataGrid'; +import type DataCell from '../../../../models/dataGrid/data/cell'; +import { CellEditor } from '../../../../models/dataGrid/data/cellEditor'; +import type EditForm from '../../../../models/dataGrid/editForm'; +import { clickWithOffset } from '../../helpers/clickWithOffset'; +import { getFirstDataRow } from '../../helpers/getFirstDataRow'; +import { typeText } from '../../helpers/typeText'; + +interface ColumnInfo { + columnIndex: number; + dataField: string; + newValue: string; +} + +const createDataGrid = async ( + page: Page, + mode: GridsEditMode, + repaintChangesOnly = false, +): Promise => createWidget(page, 'dxDataGrid', (arg) => ({ + keyExpr: 'id', + dataSource: [ + { + id: 1, text: 'text 1', number: 1, date: '2020-10-27', boolean: false, lookup: 1, + }, + { + id: 2, text: 'text 2', number: 2, date: '2020-10-28', boolean: true, lookup: 2, + }, + ], + repaintChangesOnly: arg.repaintChangesOnly, + editing: { + mode: arg.mode, + allowAdding: true, + allowUpdating: true, + }, + columns: [ + { dataField: 'text' }, + { + dataField: 'number', + editorOptions: { + format: '#0', + }, + }, + { + dataField: 'date', + dataType: 'date', + editorOptions: { + pickerType: 'calendar', + }, + }, + { + dataField: 'lookup', + lookup: { + valueExpr: 'id', + displayExpr: 'text', + dataSource: [ + { id: 1, text: 'lookup 1' }, + { id: 2, text: 'lookup 2' }, + ], + }, + }, + { dataField: 'boolean' }, + { + dataField: 'calculated', + calculateCellValue: (data): number => (data as { number: number }).number + 1, + setCellValue: (newData, value): void => { + // eslint-disable-next-line no-param-reassign + newData.number = value - 1; + }, + }, + ], +}), '#container', { arg: { mode, repaintChangesOnly } }); + +const expectedCalculatedColumnResult: ColumnInfo[] = [ + { columnIndex: 1, dataField: 'number', newValue: '8' }, + { columnIndex: 5, dataField: 'calculated', newValue: '9' }, +]; + +const getEditForm = (dataGrid: DataGrid, mode: GridsEditMode): EditForm | null => { + if (mode === 'form') { + return dataGrid.getEditForm(); + } + if (mode === 'popup') { + return dataGrid.getPopupEditForm(); + } + return null; +}; + +const addRow = async ( + dataGrid: DataGrid, + { columnIndex }: { columnIndex: number }, + form: EditForm | null, + cell: DataCell, + editor: CellEditor, +): Promise => { + const addRowButton = dataGrid.getHeaderPanel().getAddRowButton(); + await addRowButton.click(); + + if (columnIndex > 0) { + if (!form) { + // Until the inserted row renders, the first row is the existing one: the click lands there. + await getFirstDataRow(dataGrid).expectInserted(); + } + + const item = !form ? cell.element : editor.getItemLabel(); + await clickWithOffset(item, 5); + } +}; + +const checkCellFocused = async ( + mode: GridsEditMode, + { dataField }: ColumnInfo, + cell: DataCell, + editor: CellEditor, +): Promise => { + if (mode !== 'form' && mode !== 'popup') { + await cell.expectFocusVisible(); + } + + const isRowBasedMode = mode === 'row'; + const isFormBasedMode = mode === 'form' || mode === 'popup'; + + if ((isRowBasedMode || isFormBasedMode) && dataField === 'boolean') { + return; + } + + await expect(editor.element).toBeFocused(); +}; + +const getSaveButton = ( + page: Page, + dataGrid: DataGrid, + mode: string, + form: EditForm | null, +): Locator | undefined => { + switch (mode) { + case 'batch': + return dataGrid.getHeaderPanel().getSaveButton(); + case 'row': + return getFirstDataRow(dataGrid).getCommandCell(6).getButton(0); + case 'cell': + return page.locator('body'); + default: + return form?.saveButton; + } +}; + +const checkSavedCell = async ( + dataGrid: DataGrid, + { dataField, newValue }: ColumnInfo, + cell: DataCell, +): Promise => { + if (dataField === 'boolean') { + await cell.getEditor().expectChecked(newValue === 'true'); + } else { + await expect(cell.element).toHaveText(newValue); + } + + await cell.expectEditCell(dataField === 'boolean'); + await cell.expectModified(false); + await expect(dataGrid.getModifiedCells()).toHaveCount(0); +}; + +const modes: GridsEditMode[] = ['cell', 'batch', 'row', 'form', 'popup']; + +test.describe('Editing.NewRow', () => { + modes.forEach((mode) => { + [true, false].forEach((repaintChangesOnly) => { + test(`Update cell value in new row, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}`, async ({ page }) => { + await createDataGrid(page, mode, repaintChangesOnly); + + const dataGrid = new DataGrid(page, '#container'); + const columnInfo = { columnIndex: 0, dataField: 'text', newValue: 'xxxx' }; + const form = getEditForm(dataGrid, mode); + const cell = getFirstDataRow(dataGrid).getDataCell(columnInfo.columnIndex); + const editor = form ? new CellEditor(form.getItem(columnInfo.dataField)) : cell.getEditor(); + + await addRow(dataGrid, columnInfo, form, cell, editor); + + await checkCellFocused(mode, columnInfo, cell, editor); + + await typeText(editor.element, columnInfo.newValue, { replace: true }); + + const saveButton = getSaveButton(page, dataGrid, mode, form); + + if (saveButton) { + await clickWithOffset(saveButton, 5, 5); + } + + await checkSavedCell(dataGrid, columnInfo, dataGrid.getDataCell(2, columnInfo.columnIndex)); + }); + + test(`Update calculated cell value in new row, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}`, async ({ page }) => { + await createDataGrid(page, mode, repaintChangesOnly); + + const dataGrid = new DataGrid(page, '#container'); + const columnInfo = { columnIndex: 5, dataField: 'calculated', newValue: '9' }; + const form = getEditForm(dataGrid, mode); + const cell = getFirstDataRow(dataGrid).getDataCell(columnInfo.columnIndex); + const editor = form ? new CellEditor(form.getItem(columnInfo.dataField)) : cell.getEditor(); + + await addRow(dataGrid, columnInfo, form, cell, editor); + + await checkCellFocused(mode, columnInfo, cell, editor); + + await typeText(editor.element, columnInfo.newValue, { replace: true }); + + if (!repaintChangesOnly && (mode === 'row' || mode === 'form')) { + await page.locator('body').click(); + } + + const saveButton = getSaveButton(page, dataGrid, mode, form); + + if (saveButton) { + await clickWithOffset(saveButton, 5, 5); + } + + for (const resultColumnInfo of expectedCalculatedColumnResult) { + await checkSavedCell( + dataGrid, + resultColumnInfo, + dataGrid.getDataCell(2, resultColumnInfo.columnIndex), + ); + } + }); + }); + }); +}); diff --git a/e2e/playwright/tests/dataGrid/common/editing/initNewRow.spec.ts b/e2e/playwright/tests/dataGrid/common/editing/initNewRow.spec.ts new file mode 100644 index 000000000000..5cef4b53f38d --- /dev/null +++ b/e2e/playwright/tests/dataGrid/common/editing/initNewRow.spec.ts @@ -0,0 +1,33 @@ +import { expect, test } from '../../../../fixtures'; +import { createWidget } from '../../../../helpers/createWidget'; +import DataGrid from '../../../../models/dataGrid'; + +test.describe('initNewRow', () => { + // T1274123 + test('No errors should be thrown if inserting new row after cancelling insert on second page', async ({ page }) => { + await createWidget(page, 'dxDataGrid', () => ({ + dataSource: [...new Array(40)].map((_, index) => ({ id: index + 1, text: `item ${index + 1}` })), + keyExpr: 'id', + paging: { + pageIndex: 1, + }, + columns: ['id', 'text'], + showBorders: true, + editing: { mode: 'popup', allowAdding: true }, + onInitNewRow(e) { + e.data.id = 0; + e.data.text = 'test'; + }, + height: 300, + })); + + const dataGrid = new DataGrid(page, '#container'); + + await dataGrid.getHeaderPanel().getAddRowButton().click(); + await dataGrid.getPopupEditForm().cancelButton.click(); + + await dataGrid.getHeaderPanel().getAddRowButton().click(); + + await expect(dataGrid.getPopupEditForm().element).toBeAttached(); + }); +}); diff --git a/e2e/playwright/tests/dataGrid/common/editing/undefinedValues.spec.ts b/e2e/playwright/tests/dataGrid/common/editing/undefinedValues.spec.ts new file mode 100644 index 000000000000..27638566eb2b --- /dev/null +++ b/e2e/playwright/tests/dataGrid/common/editing/undefinedValues.spec.ts @@ -0,0 +1,40 @@ +import { expect, test } from '../../../../fixtures'; +import { createWidget } from '../../../../helpers/createWidget'; +import DataGrid from '../../../../models/dataGrid'; + +test.describe('Editing - undefined values', () => { + test('Should properly set nested undefined values (T1226946)', async ({ page }) => { + await createWidget(page, 'dxDataGrid', () => ({ + dataSource: [{ + id: 0, + value: { + data: 100, + }, + }, { + id: 1, + value: { + data: undefined, + }, + }], + keyExpr: 'id', + columns: [{ + dataField: 'value', + customizeText: (cellInfo) => String(cellInfo.value.data ?? 'undefined'), + }], + showBorders: true, + })); + + const dataGrid = new DataGrid(page, '#container'); + const firstCell = dataGrid.getDataCell(0, 0); + const secondCell = dataGrid.getDataCell(1, 0); + + await expect(firstCell.element).toHaveText('100'); + await expect(secondCell.element).toHaveText('undefined'); + + await dataGrid.apiCellValue(0, 0, { data: undefined }); + await dataGrid.apiSaveEditData(); + + await expect(firstCell.element).toHaveText('undefined'); + await expect(secondCell.element).toHaveText('undefined'); + }); +}); diff --git a/e2e/playwright/tests/dataGrid/helpers/clickWithOffset.ts b/e2e/playwright/tests/dataGrid/helpers/clickWithOffset.ts new file mode 100644 index 000000000000..5e09fcf61eeb --- /dev/null +++ b/e2e/playwright/tests/dataGrid/helpers/clickWithOffset.ts @@ -0,0 +1,46 @@ +import type { Locator } from '@playwright/test'; +import { expect } from '@playwright/test'; + +const getSize = async (target: Locator): Promise<{ width: number; height: number }> => { + const size = { width: 0, height: 0 }; + + // The box is null while the target is hidden, for example in the middle of a re-render. + await expect.poll(async () => { + const box = await target.boundingBox(); + + Object.assign(size, box); + + return box; + }).not.toBeNull(); + + return size; +}; + +// Offsets from the top-left corner: a negative one counts from the opposite edge, a missing one is +// the middle of the element. +export const clickWithOffset = async ( + target: Locator, + offsetX?: number, + offsetY?: number, +): Promise => { + const isAbsolute = (offset: number | undefined): offset is number => (offset ?? -1) >= 0; + + if (isAbsolute(offsetX) && isAbsolute(offsetY)) { + await target.click({ position: { x: offsetX, y: offsetY } }); + + return; + } + + const { width, height } = await getSize(target); + const getPosition = (offset: number | undefined, size: number): number => { + if (offset === undefined) { + return Math.round(size / 2); + } + + return offset < 0 ? size + offset : offset; + }; + + await target.click({ + position: { x: getPosition(offsetX, width), y: getPosition(offsetY, height) }, + }); +}; diff --git a/e2e/playwright/tests/dataGrid/helpers/getFirstDataRow.ts b/e2e/playwright/tests/dataGrid/helpers/getFirstDataRow.ts new file mode 100644 index 000000000000..d73bf3e54d37 --- /dev/null +++ b/e2e/playwright/tests/dataGrid/helpers/getFirstDataRow.ts @@ -0,0 +1,7 @@ +import type DataGrid from '../../../models/dataGrid'; +import DataRow from '../../../models/dataGrid/data/row'; + +// An inserted row shares aria-rowindex 1 with the first data row and precedes it in the DOM. +export const getFirstDataRow = (dataGrid: DataGrid): DataRow => new DataRow( + dataGrid.getDataRow(0).element.first(), +); diff --git a/e2e/playwright/tests/dataGrid/helpers/typeText.ts b/e2e/playwright/tests/dataGrid/helpers/typeText.ts new file mode 100644 index 000000000000..c4c3621f2abe --- /dev/null +++ b/e2e/playwright/tests/dataGrid/helpers/typeText.ts @@ -0,0 +1,23 @@ +import type { Locator } from '@playwright/test'; + +// A click only when the element is not focused yet, then the caret at the end of the value (or the +// whole value selected with "replace"), then a key event per character. +export const typeText = async ( + element: Locator, + text: string, + { replace = false }: { replace?: boolean } = {}, +): Promise => { + const isFocused = await element.evaluate((node) => node === document.activeElement); + + if (!isFocused) { + await element.click(); + } + + await element.evaluate((node: HTMLInputElement, selectAll) => { + const end = node.value.length; + + node.setSelectionRange(selectAll ? 0 : end, end); + }, replace); + + await element.pressSequentially(text); +}; diff --git a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/T1154721_editingCellFocus.ts b/e2e/testcafe-devextreme/tests/dataGrid/common/editing/T1154721_editingCellFocus.ts deleted file mode 100644 index 9abffbe6af7c..000000000000 --- a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/T1154721_editingCellFocus.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { RequestMock } from 'testcafe'; -import DataGrid from 'devextreme-testcafe-models/dataGrid'; -import { createWidget } from '../../../../helpers/createWidget'; -import url from '../../../../helpers/getPageUrl'; - -fixture.disablePageReloads`Editing - cell focus` - .page(url(__dirname, '../../../container.html')); - -const apiRequestMock = RequestMock() - .onRequestTo(/\/api\/data/) - .respond( - { - data: [ - { - id: 0, - data: 'A', - }, { - id: 1, - data: 'B', - }, { - id: 2, - data: 'C', - }, - ], - }, - 200, - { 'access-control-allow-origin': '*' }, - ) - .onRequestTo(/\/api\/update/) - .respond( - {}, - 200, - { - 'access-control-allow-origin': '*', - 'access-control-allow-methods': '*', - }, - ); - -// T1154721 -test('Should allow focus next editor in the same column after save changes with local data source', async (t) => { - const dataGrid = new DataGrid('#container'); - const firstCell = dataGrid.getDataCell(0, 0); - const middleCell = dataGrid.getDataCell(1, 0); - const secondCell = dataGrid.getDataCell(2, 0); - - await t.typeText(firstCell.getEditor().element, ' AAA'); - await t.typeText(secondCell.getEditor().element, ' CCC'); - await t.click(middleCell.element); - - const firstCellValue = await firstCell.getEditor().element().value; - const secondCellValue = await secondCell.getEditor().element().value; - - await t.expect(firstCellValue).eql('A AAA'); - await t.expect(secondCellValue).eql('C CCC'); -}).before(async () => createWidget('dxDataGrid', { - keyExpr: 'id', - dataSource: [{ - id: 0, - data: 'A', - }, { - id: 1, - data: 'B', - }, { - id: 2, - data: 'C', - }], - editing: { - allowUpdating: true, - refreshMode: 'repaint', - mode: 'cell', - }, - columns: [{ - dataField: 'data', - showEditorAlways: true, - }], - repaintChangesOnly: true, -})); - -// T1037019 -test('Should allow focus next editor in the same column after save changes with remote data source', async (t) => { - const dataGrid = new DataGrid('#container'); - const firstCell = dataGrid.getDataCell(0, 0); - const middleCell = dataGrid.getDataCell(1, 0); - const secondCell = dataGrid.getDataCell(2, 0); - - await t.typeText(firstCell.getEditor().element, ' AAA'); - await t.typeText(secondCell.getEditor().element, ' CCC'); - await t.click(middleCell.element); - - const firstCellValue = await firstCell.getEditor().element().value; - const secondCellValue = await secondCell.getEditor().element().value; - - await t.expect(firstCellValue).eql('A AAA'); - await t.expect(secondCellValue).eql('C CCC'); -}).before(async (t) => { - await t.addRequestHooks(apiRequestMock); - await createWidget('dxDataGrid', () => ({ - keyExpr: 'id', - dataSource: (window as any).DevExpress.data.AspNet.createStore({ - key: 'id', - loadUrl: 'https://api/data', - updateUrl: 'https://api/update', - }), - editing: { - allowUpdating: true, - refreshMode: 'repaint', - mode: 'cell', - }, - columns: [{ - dataField: 'data', - showEditorAlways: true, - }], - repaintChangesOnly: true, - })); -}).after(async (t) => { await t.removeRequestHooks(apiRequestMock); }); diff --git a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/T1323684_readonlyEditorNewRow.ts b/e2e/testcafe-devextreme/tests/dataGrid/common/editing/T1323684_readonlyEditorNewRow.ts deleted file mode 100644 index 13cc125fe620..000000000000 --- a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/T1323684_readonlyEditorNewRow.ts +++ /dev/null @@ -1,170 +0,0 @@ -import DataGrid from 'devextreme-testcafe-models/dataGrid'; -import { GridsEditMode } from 'devextreme/ui/data_grid'; -import { createWidget } from '../../../../helpers/createWidget'; -import url from '../../../../helpers/getPageUrl'; - -fixture.disablePageReloads`Editing - showEditorAlways cell in new row should be editable (T1323684)` - .page(url(__dirname, '../../../container.html')); - -const READONLY_CLASS = 'dx-datagrid-readonly'; -const CELL_FOCUS_DISABLED_CLASS = 'dx-cell-focus-disabled'; - -(['cell', 'batch'] as GridsEditMode[]).forEach((mode) => { - test(`showEditorAlways editor should be editable in a new row when allowUpdating is false, ${mode} mode`, async (t) => { - const dataGrid = new DataGrid('#container'); - const addRowButton = dataGrid.getHeaderPanel().getAddRowButton(); - - await t.click(addRowButton); - - const newRow = dataGrid.getDataRow(0); - await t.expect(newRow.isInserted).ok(); - - const cell = dataGrid.getDataCell(0, 1); - const editor = cell.getEditor(); - - await t - .expect(cell.element.hasClass(READONLY_CLASS)) - .notOk('showEditorAlways cell in new row should not have readonly class') - .expect(cell.element.hasClass(CELL_FOCUS_DISABLED_CLASS)) - .notOk('showEditorAlways cell in new row should not have cell-focus-disabled class'); - - await t - .click(editor.element) - .expect(cell.isFocused) - .ok('showEditorAlways cell should be focused after click') - .expect(editor.element.focused) - .ok('editor should be focused after click') - .typeText(editor.element, 'test value', { replace: true }) - .expect(editor.element.value) - .eql('test value'); - }).before(async () => createWidget('dxDataGrid', { - keyExpr: 'ID', - dataSource: [ - { ID: 1, FirstName: 'John', LastName: 'Heart' }, - { ID: 2, FirstName: 'Olivia', LastName: 'Peyton' }, - ], - showBorders: true, - editing: { - mode, - allowUpdating: false, - allowAdding: true, - }, - columns: [ - 'LastName', - { dataField: 'FirstName', showEditorAlways: true }, - ], - })); - - test(`Boolean editor should be editable in a new row when allowUpdating is false, ${mode} mode`, async (t) => { - const dataGrid = new DataGrid('#container'); - const addRowButton = dataGrid.getHeaderPanel().getAddRowButton(); - - await t.click(addRowButton); - - const newRow = dataGrid.getDataRow(0); - await t.expect(newRow.isInserted).ok(); - - const booleanCell = dataGrid.getDataCell(0, 1); - - await t - .expect(booleanCell.element.hasClass(READONLY_CLASS)) - .notOk('boolean cell in new row should not have readonly class'); - - await t - .click(booleanCell.element) - .click(booleanCell.getCheckbox()) - .expect(booleanCell.getEditor().isChecked()) - .ok('checkbox in new row should be checked after click in it'); - }).before(async () => createWidget('dxDataGrid', { - keyExpr: 'ID', - dataSource: [ - { ID: 1, Name: 'John', Active: false }, - { ID: 2, Name: 'Olivia', Active: true }, - ], - showBorders: true, - editing: { - mode, - allowUpdating: false, - allowAdding: true, - }, - columns: [ - 'Name', - { dataField: 'Active', dataType: 'boolean' }, - ], - })); - - test(`showEditorAlways editor in existing rows should remain readonly when allowUpdating is false, ${mode} mode`, async (t) => { - const dataGrid = new DataGrid('#container'); - const existingCell = dataGrid.getDataCell(0, 1); - - await t - .expect(existingCell.element.hasClass(READONLY_CLASS)) - .ok('showEditorAlways cell in existing row should have readonly class when allowUpdating is false'); - - await t - .click(existingCell.getEditor().element) - .expect(existingCell.element.hasClass(READONLY_CLASS)) - .ok('showEditorAlways cell in existing row should remain readonly after click'); - }).before(async () => createWidget('dxDataGrid', { - keyExpr: 'ID', - dataSource: [ - { ID: 1, FirstName: 'John', LastName: 'Heart' }, - { ID: 2, FirstName: 'Olivia', LastName: 'Peyton' }, - ], - showBorders: true, - editing: { - mode, - allowUpdating: false, - allowAdding: true, - }, - columns: [ - 'LastName', - { dataField: 'FirstName', showEditorAlways: true }, - ], - })); -}); - -test('showEditorAlways editor should be editable in a new row when allowUpdating is a function returning false, cell mode', async (t) => { - const dataGrid = new DataGrid('#container'); - const addRowButton = dataGrid.getHeaderPanel().getAddRowButton(); - - await t.click(addRowButton); - - const newRow = dataGrid.getDataRow(0); - await t.expect(newRow.isInserted).ok(); - - const cell = dataGrid.getDataCell(0, 1); - const editor = cell.getEditor(); - - await t - .expect(cell.element.hasClass(READONLY_CLASS)) - .notOk('showEditorAlways cell in new row should not have readonly class') - .expect(cell.element.hasClass(CELL_FOCUS_DISABLED_CLASS)) - .notOk('showEditorAlways cell in new row should not have cell-focus-disabled class'); - - await t - .click(editor.element) - .expect(cell.isFocused) - .ok('showEditorAlways cell should be focused after click') - .expect(editor.element.focused) - .ok('editor should be focused after click') - .typeText(editor.element, 'test value', { replace: true }) - .expect(editor.element.value) - .eql('test value'); -}).before(async () => createWidget('dxDataGrid', { - keyExpr: 'ID', - dataSource: [ - { ID: 1, FirstName: 'John', LastName: 'Heart' }, - { ID: 2, FirstName: 'Olivia', LastName: 'Peyton' }, - ], - showBorders: true, - editing: { - mode: 'cell' as GridsEditMode, - allowUpdating: () => false, - allowAdding: true, - }, - columns: [ - 'LastName', - { dataField: 'FirstName', showEditorAlways: true }, - ], -})); diff --git a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/editing.functional_matrix.ts b/e2e/testcafe-devextreme/tests/dataGrid/common/editing/editing.functional_matrix.ts deleted file mode 100644 index aadf94bcebb0..000000000000 --- a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/editing.functional_matrix.ts +++ /dev/null @@ -1,607 +0,0 @@ -/* eslint-disable @typescript-eslint/init-declarations */ -import { Selector } from 'testcafe'; -import { CellEditor } from 'devextreme-testcafe-models/dataGrid/data/cellEditor'; -import DataGrid from 'devextreme-testcafe-models/dataGrid'; -import DataCell from 'devextreme-testcafe-models/dataGrid/data/cell'; -import EditForm from 'devextreme-testcafe-models/dataGrid/editForm'; -import { GridsEditMode } from 'devextreme/ui/data_grid'; -import { ClassNames as CLASS } from 'devextreme-testcafe-models/dataGrid/classNames'; -import { createWidget } from '../../../../helpers/createWidget'; -import url from '../../../../helpers/getPageUrl'; - -fixture.disablePageReloads`Editing.FunctionalMatrix` - .page(url(__dirname, '../../../container.html')); - -interface ColumnInfo { - columnIndex: number; - dataField: string; - newValue: string; - newMaskValue?: string; -} - -const editingModes: GridsEditMode[] = ['cell', 'batch', 'row', 'form', 'popup']; - -const textColumnInfos: ColumnInfo[] = [ - { columnIndex: 0, dataField: 'text', newValue: 'xxxx' }, - { columnIndex: 5, dataField: 'calculated', newValue: '9' }, -]; - -const expectedTextColumnResult: ColumnInfo[] = [ - ...textColumnInfos, - { columnIndex: 1, dataField: 'number', newValue: '8' }, -]; - -const maskedColumnInfos: ColumnInfo[] = [ - { - columnIndex: 0, dataField: 'text', newValue: 'xxxx', newMaskValue: 'xxxxx', - }, - { - columnIndex: 1, dataField: 'number', newValue: '-9', newMaskValue: '9-', - }, - { - columnIndex: 2, dataField: 'date', newValue: '10/1/2020', newMaskValue: '101', - }, -]; - -const expectedMaskedColumnResult: ColumnInfo[] = [ - ...maskedColumnInfos, - { columnIndex: 5, dataField: 'calculated', newValue: '-8' }, -]; - -const basicColumnInfos: ColumnInfo[] = [ - { columnIndex: 0, dataField: 'text', newValue: 'xxxx' }, - { columnIndex: 1, dataField: 'number', newValue: '-9' }, - { columnIndex: 2, dataField: 'date', newValue: '10/1/2020' }, - { columnIndex: 3, dataField: 'lookup', newValue: 'lookup 2' }, - { columnIndex: 4, dataField: 'boolean', newValue: 'true' }, -]; - -const expectedBasicColumnResult: ColumnInfo[] = [ - ...basicColumnInfos, - { columnIndex: 5, dataField: 'calculated', newValue: '-8' }, -]; - -const dataGrid = new DataGrid('#container'); - -const createDataGrid = ({ - mode, repaintChangesOnly = false, useMask = false, -}) => async (): Promise => createWidget('dxDataGrid', { - keyExpr: 'id', - dataSource: [ - { - id: 1, text: 'text 1', number: 1, date: '2020-10-27', boolean: false, lookup: 1, - }, - { - id: 2, text: 'text 2', number: 2, date: '2020-10-28', boolean: true, lookup: 2, - }, - ], - repaintChangesOnly, - editing: { - mode, - allowUpdating: true, - }, - columns: [ - { - dataField: 'text', - editorOptions: { - mask: useMask ? 'cccc' : undefined, - }, - }, - { - dataField: 'number', - editorOptions: { - format: '#0', - useMaskBehavior: useMask, - }, - }, - { - dataField: 'date', - dataType: 'date', - editorOptions: { - useMaskBehavior: useMask, - pickerType: 'calendar', - }, - }, - { - dataField: 'lookup', - lookup: { - valueExpr: 'id', - displayExpr: 'text', - dataSource: [ - { id: 1, text: 'lookup 1' }, - { id: 2, text: 'lookup 2' }, - ], - }, - }, - { dataField: 'boolean' }, - { - dataField: 'calculated', - calculateCellValue: (data): number => (data as { number: number }).number + 1, - setCellValue: (newData, value): void => { - newData.number = value - 1; - }, - }, - ], -}); - -const getEditForm = (mode: GridsEditMode): EditForm | null => { - if (mode === 'form') { - return dataGrid.getEditForm(); - } - if (mode === 'popup') { - return dataGrid.getPopupEditForm(); - } - return null; -}; - -const clickEditButtonIfExists = async (t: TestController, form: EditForm | null): Promise => { - const formAlreadyOpened = await form?.element.exists && await form?.element.visible; - - if (formAlreadyOpened) { - return; - } - - const editButton = dataGrid.getDataRow(0).getCommandCell(6).getEditButton(); - - if (await editButton.exists) { - await t.click(editButton); - } -}; - -const checkCellFocused = async ( - t: TestController, - mode: GridsEditMode, - { dataField }: ColumnInfo, - cell: DataCell | undefined, - editor: CellEditor | undefined, -): Promise => { - const isRowBasedMode = mode === 'row'; - const isFormBasedMode = mode === 'form' || mode === 'popup'; - - if (!isFormBasedMode) { - await t.expect(cell?.isFocused).ok(); - } - - if ((isRowBasedMode || isFormBasedMode) && dataField === 'boolean') { - return; - } - - await t - .expect(editor?.element.exists) - .ok() - .expect(editor?.element.focused) - .eql(true); -}; - -const clickCellEditor = async ( - t: TestController, - mode: GridsEditMode, - columnInfo: ColumnInfo, - form: EditForm | null, - cell: DataCell, - editor: CellEditor, -): Promise => { - await clickEditButtonIfExists(t, form); - - const item = !form ? cell.element : editor.getItemLabel(); - await t.click(item, { offsetX: 25 }); - - await checkCellFocused(t, mode, columnInfo, cell, editor); -}; - -const moveToFirstCellEditor = async (t: TestController, mode: GridsEditMode): Promise => { - await t - .pressKey('tab') - .pressKey('ctrl+down') - .pressKey('enter'); - - if (mode === 'popup') { - const columns = await dataGrid.apiOption('columns'); - await t - .pressKey(columns.map(() => 'tab').join(' ')) - .pressKey('enter') - .wait(500); - } -}; - -const setEditorValue = async ( - t: TestController, - mode: GridsEditMode, - { dataField, newMaskValue, newValue }: ColumnInfo, - editor: CellEditor, - useKeyboard = false, - useMask = false, -): Promise => { - if (dataField === 'boolean') { - if (useKeyboard) { - await t.pressKey('space'); - } else { - await t.click(editor.element); - } - - return; - } - - const value: string = useMask ? newMaskValue ?? '' : newValue; - - if (dataField === 'date' && !useKeyboard && !useMask) { - await t.click(editor.getDropDownButton()); - await t.click(Selector(`.${CLASS.calendarCell}`).withText(value.split('/')[1])); - - return; - } - - if (dataField === 'lookup' && !useKeyboard) { - if (mode === 'cell' || mode === 'batch') { - await t.click(editor.getDropDownButton()); - } - await t.click(Selector(`.${CLASS.listItemContent}`).withText(value)); - - return; - } - - await t.typeText(editor.element, value, { replace: true }); - - if (dataField === 'lookup' && useKeyboard) { - await Selector(`.${CLASS.listItemContent}`).withText(value)(); - await t.pressKey('enter'); - } -}; - -const focusNextCellEditor = async ( - t: TestController, - mode: GridsEditMode, - { columnIndex }: ColumnInfo, - useKeyboard = false, -): Promise<{ nextColumnIndex: number }> => { - const form = getEditForm(mode); - const nextColumnIndex = columnIndex === 0 ? 1 : columnIndex - 1; - const nextColumnInfo = basicColumnInfos[nextColumnIndex]; - - let nextEditor: CellEditor | undefined; - let nextCell: DataCell | undefined; - - if (form) { - if (nextColumnInfo) { - nextEditor = new CellEditor(form.getItem(nextColumnInfo.dataField)); - if (useKeyboard) { - await t.pressKey(columnIndex === 0 ? 'tab' : 'shift+tab'); - } else { - await t.click(nextEditor.element); - } - } - } else { - nextCell = dataGrid.getDataCell(0, nextColumnIndex); - nextEditor = nextCell.getEditor(); - - if (useKeyboard) { - await t.pressKey(columnIndex === 0 ? 'tab' : 'shift+tab'); - } else { - const isCellRevertBug = mode === 'cell' && columnIndex < nextColumnIndex; - await t.click(nextCell.element, { offsetX: isCellRevertBug ? 50 : 5 }); - } - } - - await checkCellFocused(t, mode, nextColumnInfo, nextCell, nextEditor); - - return { nextColumnIndex }; -}; - -const getSaveButton = ( - mode: string, - form: EditForm | null, -): Selector | undefined => { - switch (mode) { - case 'batch': - return dataGrid.getHeaderPanel().getSaveButton(); - case 'row': - return dataGrid.getDataRow(0).getCommandCell(6).getButton(0); - case 'cell': - return Selector('body'); - default: - return form?.saveButton; - } -}; - -const getCellText = async ( - dataField: string, - cell: DataCell, -): Promise => { - if (dataField === 'boolean') { - return await cell.getEditor().isChecked() ? 'true' : 'false'; - } - - return cell.element.textContent; -}; - -const checkSavedCell = async ( - t: TestController, - { dataField, newValue }: ColumnInfo, - cell: DataCell, -): Promise => { - await t - .expect(await getCellText(dataField, cell)) - .eql(newValue) - .expect(cell.isEditCell) - .eql(dataField === 'boolean') - .expect(cell.isModified) - .notOk() - .expect(DataCell.getModifiedCells().count) - .eql(0); -}; - -const getEditorValue = async ( - dataField: string, - editor: CellEditor, -): Promise => { - if (dataField === 'boolean') { - return await editor.isChecked() ? 'true' : 'false'; - } - - return editor.element.value; -}; - -const checkModifiedCell = async ( - t: TestController, - mode: string, - { dataField, newValue }: ColumnInfo, - cell: DataCell, - editor: CellEditor, - modifiedCellsCount: number, -): Promise => { - const editorText = mode === 'batch' || mode === 'cell' - ? await getCellText(dataField, cell) - : await getEditorValue(dataField, editor); - - await t - .expect(editorText) - .eql(newValue); - - if (mode !== 'form' && mode !== 'popup') { - await t - .expect(cell.isEditCell) - .eql(mode === 'row' || dataField === 'boolean') - .expect(cell.isModified) - .eql(mode === 'batch') - .expect(DataCell.getModifiedCells().count) - .eql(modifiedCellsCount); - } -}; - -editingModes.forEach((mode) => { - const configurations = [ - { - repaintChangesOnly: true, - useMask: false, - columnInfos: textColumnInfos, - expectedResult: expectedTextColumnResult, - }, - { - repaintChangesOnly: false, - useMask: true, - columnInfos: maskedColumnInfos, - expectedResult: expectedMaskedColumnResult, - }, - { - repaintChangesOnly: false, - useMask: false, - columnInfos: basicColumnInfos, - expectedResult: expectedBasicColumnResult, - }, - ]; - - configurations.forEach(({ - repaintChangesOnly, useMask, columnInfos, expectedResult, - }) => { - test( - `Update cell value, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}, useKeyboard: false, useMask: ${useMask}`, - async (t) => { - const form = getEditForm(mode); - - if (mode === 'batch') { - await dataGrid.apiCellValue(0, 0, 'modified'); - } - - for (const columnInfo of columnInfos) { - const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); - const editor = form - ? new CellEditor(form.getItem(columnInfo.dataField)) - : cell.getEditor(); - - await clickCellEditor(t, mode, columnInfo, form, cell, editor); - await setEditorValue(t, mode, columnInfo, editor, false, useMask); - await t.expect(dataGrid.isReady()).ok(); - } - - const saveButton = getSaveButton(mode, form); - - if (saveButton) { - await t.click(saveButton, { offsetX: 5, offsetY: 5 }); - } - - for (const columnInfo of expectedResult) { - await checkSavedCell( - t, - columnInfo, - dataGrid.getDataCell(0, columnInfo.columnIndex), - ); - } - }, - ).before(createDataGrid({ - mode, - useMask, - repaintChangesOnly, - })); - }); - - [true, false].forEach((repaintChangesOnly) => { - test( - `Update calculated cell value, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}, useKeyboard: false, useMask:false`, - async (t) => { - const columnInfo = { columnIndex: 5, dataField: 'calculated', newValue: '9' }; - const form = getEditForm(mode); - const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); - const editor = form ? new CellEditor(form.getItem(columnInfo.dataField)) : cell.getEditor(); - - await t.expect(dataGrid.isReady()).ok(); - - await clickCellEditor(t, mode, columnInfo, form, cell, editor); - await setEditorValue(t, mode, columnInfo, editor); - - const saveButton = getSaveButton(mode, form); - - if (saveButton) { - if (!repaintChangesOnly && (mode === 'row' || mode === 'form')) { - await t.click('body'); - } - - await t.click(saveButton, { offsetX: 5, offsetY: 5 }); - } - - const expectedColumnResult: ColumnInfo[] = [ - { columnIndex: 1, dataField: 'number', newValue: '8' }, - { columnIndex: 5, dataField: 'calculated', newValue: '9' }, - ]; - - for (const resultColumnInfo of expectedColumnResult) { - await checkSavedCell( - t, - resultColumnInfo, - dataGrid.getDataCell(0, resultColumnInfo.columnIndex), - ); - } - }, - ).before(createDataGrid({ - mode, - repaintChangesOnly, - })); - }); - - const keyboardConfigurations = [ - { - useMask: true, - columnInfos: maskedColumnInfos, - expectedResult: expectedMaskedColumnResult, - }, - { - useMask: false, - columnInfos: basicColumnInfos, - expectedResult: expectedBasicColumnResult, - }, - ]; - - keyboardConfigurations.forEach(({ useMask, columnInfos, expectedResult }) => { - test( - `Update cell value, mode: ${mode}, repaintChangesOnly: false, useKeyboard: true, useMask: ${useMask}`, - async (t) => { - const form = getEditForm(mode); - - await t.expect(dataGrid.isReady()).ok(); - await moveToFirstCellEditor(t, mode); - - for (const columnInfo of columnInfos) { - const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); - const editor = form - ? new CellEditor(form.getItem(columnInfo.dataField)) - : cell.getEditor(); - - if (columnInfo.columnIndex > 0) { - await t.pressKey('tab'); - } - - await checkCellFocused(t, mode, columnInfo, cell, editor); - await setEditorValue(t, mode, columnInfo, editor, true, useMask); - } - - await t.pressKey('enter'); - - if (mode === 'batch' || mode === 'popup') { - const saveButton = getSaveButton(mode, form); - - if (saveButton) { - await t.click(saveButton, { offsetX: 5, offsetY: 5 }); - } - } - - for (const columnInfo of expectedResult) { - await checkSavedCell( - t, - columnInfo, - dataGrid.getDataCell(0, columnInfo.columnIndex), - ); - } - }, - ).before(createDataGrid({ - mode, - useMask, - })); - }); - - test( - `Update cell value and focus next cell, mode: ${mode}, repaintChangesOnly: false, useKeyboard: true`, - async (t) => { - const form = getEditForm(mode); - let activeColumnIndex = 0; - let modifiedCellCount = mode === 'batch' ? 1 : 0; - - await t.expect(dataGrid.isReady()).ok(); - await moveToFirstCellEditor(t, mode); - - for (const columnInfo of textColumnInfos) { - const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); - const editor = form ? new CellEditor(form.getItem(columnInfo.dataField)) : cell.getEditor(); - - for (let i = activeColumnIndex; i < columnInfo.columnIndex; i += 1) { - await t.pressKey('tab'); - } - - await checkCellFocused(t, mode, columnInfo, cell, editor); - await setEditorValue(t, mode, columnInfo, editor, true); - - const { nextColumnIndex } = await focusNextCellEditor(t, mode, columnInfo, true); - activeColumnIndex = nextColumnIndex; - - if (mode === 'batch') { - modifiedCellCount += 1; - } - - await checkModifiedCell(t, mode, columnInfo, cell, editor, modifiedCellCount); - } - }, - ).before(createDataGrid({ - mode, - })); - - [true, false].forEach((repaintChangesOnly) => { - test( - `Update cell value and focus next cell, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}, useKeyboard: false`, - async (t) => { - const form = getEditForm(mode); - let modifiedCellCount = mode === 'batch' ? 1 : 0; - - await t.expect(dataGrid.isReady()).ok(); - - for (const columnInfo of textColumnInfos) { - const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); - const editor = form - ? new CellEditor(form.getItem(columnInfo.dataField)) - : cell.getEditor(); - - await clickCellEditor(t, mode, columnInfo, form, cell, editor); - await setEditorValue(t, mode, columnInfo, editor); - - await focusNextCellEditor(t, mode, columnInfo); - - if (mode === 'batch') { - modifiedCellCount += 1; - } - - await checkModifiedCell(t, mode, columnInfo, cell, editor, modifiedCellCount); - } - }, - ).before(createDataGrid({ - mode, - repaintChangesOnly, - })); - }); -}); diff --git a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/editingNewRow.functional_matrix.ts b/e2e/testcafe-devextreme/tests/dataGrid/common/editing/editingNewRow.functional_matrix.ts deleted file mode 100644 index fb0ef59d8ff9..000000000000 --- a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/editingNewRow.functional_matrix.ts +++ /dev/null @@ -1,234 +0,0 @@ -import { Selector } from 'testcafe'; -import { CellEditor } from 'devextreme-testcafe-models/dataGrid/data/cellEditor'; -import DataGrid from 'devextreme-testcafe-models/dataGrid'; -import DataCell from 'devextreme-testcafe-models/dataGrid/data/cell'; -import EditForm from 'devextreme-testcafe-models/dataGrid/editForm'; -import { GridsEditMode } from 'devextreme/ui/data_grid'; -import { createWidget } from '../../../../helpers/createWidget'; -import url from '../../../../helpers/getPageUrl'; - -fixture.disablePageReloads`Editing.NewRow` - .page(url(__dirname, '../../../container.html')); - -interface ColumnInfo { - columnIndex: number; - dataField: string; - newValue: string; -} - -const createDataGrid = (mode: GridsEditMode, repaintChangesOnly = false) => async (): Promise => createWidget('dxDataGrid', { - keyExpr: 'id', - dataSource: [ - { - id: 1, text: 'text 1', number: 1, date: '2020-10-27', boolean: false, lookup: 1, - }, - { - id: 2, text: 'text 2', number: 2, date: '2020-10-28', boolean: true, lookup: 2, - }, - ], - repaintChangesOnly, - editing: { - mode, - allowAdding: true, - allowUpdating: true, - }, - columns: [ - { dataField: 'text' }, - { - dataField: 'number', - editorOptions: { - format: '#0', - }, - }, - { - dataField: 'date', - dataType: 'date', - editorOptions: { - pickerType: 'calendar', - }, - }, - { - dataField: 'lookup', - lookup: { - valueExpr: 'id', - displayExpr: 'text', - dataSource: [ - { id: 1, text: 'lookup 1' }, - { id: 2, text: 'lookup 2' }, - ], - }, - }, - { dataField: 'boolean' }, - { - dataField: 'calculated', - calculateCellValue: (data): number => (data as { number: number }).number + 1, - setCellValue: (newData, value): void => { - newData.number = value - 1; - }, - }, - ], -}); - -const expectedCalculatedColumnResult: ColumnInfo[] = [ - { columnIndex: 1, dataField: 'number', newValue: '8' }, - { columnIndex: 5, dataField: 'calculated', newValue: '9' }, -]; - -const dataGrid = new DataGrid('#container'); - -const getEditForm = (mode: GridsEditMode): EditForm | null => { - if (mode === 'form') { - return dataGrid.getEditForm(); - } - if (mode === 'popup') { - return dataGrid.getPopupEditForm(); - } - return null; -}; - -const addRow = async ( - t: TestController, - { columnIndex }: { columnIndex: number }, - form: EditForm | null, - cell: DataCell, - editor: CellEditor, -): Promise => { - const addRowButton = dataGrid.getHeaderPanel().getAddRowButton(); - await t.click(addRowButton); - - if (columnIndex > 0) { - const item = !form ? cell.element : editor.getItemLabel(); - await t.click(item, { offsetX: 5 }); - } -}; - -const checkCellFocused = async ( - t: TestController, - mode: GridsEditMode, - { dataField }: ColumnInfo, - cell: DataCell | undefined, - editor: CellEditor | undefined, -): Promise => { - if (mode !== 'form' && mode !== 'popup') { - await t.expect(cell?.isFocused).ok(); - } - - const isRowBasedMode = mode === 'row'; - const isFormBasedMode = mode === 'form' || mode === 'popup'; - - if ((isRowBasedMode || isFormBasedMode) && dataField === 'boolean') { - return; - } - - await t - .expect(editor?.element.focused) - .eql(true); -}; - -const getSaveButton = ( - mode: string, - form: EditForm | null, -): Selector | undefined => { - switch (mode) { - case 'batch': - return dataGrid.getHeaderPanel().getSaveButton(); - case 'row': - return dataGrid.getDataRow(0).getCommandCell(6).getButton(0); - case 'cell': - return Selector('body'); - default: - return form?.saveButton; - } -}; - -const getCellText = async ( - dataField: string, - cell: DataCell, -): Promise => { - if (dataField === 'boolean') { - return await cell.getEditor().isChecked() ? 'true' : 'false'; - } - - return cell.element.textContent; -}; - -const checkSavedCell = async ( - t: TestController, - { dataField, newValue }: ColumnInfo, - cell: DataCell, -): Promise => { - await t - .expect(await getCellText(dataField, cell)) - .eql(newValue) - .expect(cell.isEditCell) - .eql(dataField === 'boolean') - .expect(cell.isModified) - .notOk() - .expect(DataCell.getModifiedCells().count) - .eql(0); -}; - -const modes: GridsEditMode[] = ['cell', 'batch', 'row', 'form', 'popup']; - -modes.forEach((mode) => { - [true, false].forEach((repaintChangesOnly) => { - test( - `Update cell value in new row, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}`, - async (t) => { - const columnInfo = { columnIndex: 0, dataField: 'text', newValue: 'xxxx' }; - const form = getEditForm(mode); - const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); - const editor = form ? new CellEditor(form.getItem(columnInfo.dataField)) : cell.getEditor(); - - await addRow(t, columnInfo, form, cell, editor); - - await checkCellFocused(t, mode, columnInfo, cell, editor); - - await t.typeText(editor.element, columnInfo.newValue, { replace: true }); - - const saveButton = getSaveButton(mode, form); - - if (saveButton) { - await t.click(saveButton, { offsetX: 5, offsetY: 5 }); - } - - await checkSavedCell(t, columnInfo, dataGrid.getDataCell(2, columnInfo.columnIndex)); - }, - ).before(createDataGrid(mode, repaintChangesOnly)); - - test( - `Update calculated cell value in new row, mode: ${mode}, repaintChangesOnly: ${repaintChangesOnly}`, - async (t) => { - const columnInfo = { columnIndex: 5, dataField: 'calculated', newValue: '9' }; - const form = getEditForm(mode); - const cell = dataGrid.getDataCell(0, columnInfo.columnIndex); - const editor = form ? new CellEditor(form.getItem(columnInfo.dataField)) : cell.getEditor(); - - await addRow(t, columnInfo, form, cell, editor); - - await checkCellFocused(t, mode, columnInfo, cell, editor); - - await t.typeText(editor.element, columnInfo.newValue, { replace: true }); - - if (!repaintChangesOnly && (mode === 'row' || mode === 'form')) { - await t.click('body'); - } - - const saveButton = getSaveButton(mode, form); - - if (saveButton) { - await t.click(saveButton, { offsetX: 5, offsetY: 5 }); - } - - // eslint-disable-next-line no-restricted-syntax - for (const resultColumnInfo of expectedCalculatedColumnResult) { - await checkSavedCell( - t, - resultColumnInfo, - dataGrid.getDataCell(2, resultColumnInfo.columnIndex), - ); - } - }, - ).before(createDataGrid(mode, repaintChangesOnly)); - }); -}); diff --git a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/initNewRow.ts b/e2e/testcafe-devextreme/tests/dataGrid/common/editing/initNewRow.ts deleted file mode 100644 index 27deee1a5595..000000000000 --- a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/initNewRow.ts +++ /dev/null @@ -1,43 +0,0 @@ -import DataGrid from 'devextreme-testcafe-models/dataGrid'; -import { createWidget } from '../../../../helpers/createWidget'; -import url from '../../../../helpers/getPageUrl'; - -fixture.disablePageReloads`initNewRow` - .page(url(__dirname, '../../../container.html')); - -// T1274123 -test('No errors should be thrown if inserting new row after cancelling insert on second page', async (t) => { - const dataGrid = new DataGrid('#container'); - - await t - .click( - dataGrid.getHeaderPanel().getAddRowButton(), - ) - .click( - dataGrid.getPopupEditForm().cancelButton, - ); - - await t.click( - dataGrid.getHeaderPanel().getAddRowButton(), - ); - - await t.expect( - dataGrid.getPopupEditForm().element.exists, - ).ok(); -}).before(async () => { - await createWidget('dxDataGrid', { - dataSource: [...new Array(40)].map((_, index) => ({ id: index + 1, text: `item ${index + 1}` })), - keyExpr: 'id', - paging: { - pageIndex: 1, - }, - columns: ['id', 'text'], - showBorders: true, - editing: { mode: 'popup', allowAdding: true }, - onInitNewRow(e) { - e.data.id = 0; - e.data.text = 'test'; - }, - height: 300, - }); -}); diff --git a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/undefinedValues.ts b/e2e/testcafe-devextreme/tests/dataGrid/common/editing/undefinedValues.ts deleted file mode 100644 index c1545f1ab58d..000000000000 --- a/e2e/testcafe-devextreme/tests/dataGrid/common/editing/undefinedValues.ts +++ /dev/null @@ -1,40 +0,0 @@ -import DataGrid from 'devextreme-testcafe-models/dataGrid'; -import { createWidget } from '../../../../helpers/createWidget'; -import url from '../../../../helpers/getPageUrl'; - -fixture.disablePageReloads`Editing - undefined values` - .disablePageReloads - .page(url(__dirname, '../../../container.html')); - -test('Should properly set nested undefined values (T1226946)', async (t) => { - const dataGrid = new DataGrid('#container'); - const firstCell = dataGrid.getDataCell(0, 0); - const secondCell = dataGrid.getDataCell(1, 0); - - await t.expect(firstCell.element().textContent).eql('100'); - await t.expect(secondCell.element().textContent).eql('undefined'); - - await dataGrid.apiCellValue(0, 0, { data: undefined }); - await dataGrid.apiSaveEditData(); - - await t.expect(firstCell.element().textContent).eql('undefined'); - await t.expect(secondCell.element().textContent).eql('undefined'); -}).before(async () => createWidget('dxDataGrid', { - dataSource: [{ - id: 0, - value: { - data: 100, - }, - }, { - id: 1, - value: { - data: undefined, - }, - }], - keyExpr: 'id', - columns: [{ - dataField: 'value', - customizeText: (cellInfo) => String(cellInfo.value.data ?? 'undefined'), - }], - showBorders: true, -}));