From 44992d383dcaa25feaa772db0b377031fc3337ca Mon Sep 17 00:00:00 2001 From: Andrew Makarov Date: Thu, 7 Sep 2023 18:53:26 +0400 Subject: [PATCH] dxGrid - Add more TS typing in onRowUpdating, onRowDeleting, onRowAdding events(T1186997) (#25504) --- js/common/grids.d.ts | 12 +- testing/testcafe/model/dataGrid/data/cell.ts | 5 + .../tests/dataGrid/editing/editingEvents.ts | 173 ++++++++++++++++++ ts/dx.all.d.ts | 6 +- 4 files changed, 187 insertions(+), 9 deletions(-) create mode 100644 testing/testcafe/tests/dataGrid/editing/editingEvents.ts diff --git a/js/common/grids.d.ts b/js/common/grids.d.ts index 67ce70595423..103dad767221 100644 --- a/js/common/grids.d.ts +++ b/js/common/grids.d.ts @@ -2746,9 +2746,9 @@ export type RowInsertingInfo = { data: TRowData; /** * @docid - * @type Promise + * @type boolean|Promise|Promise */ - cancel: boolean | PromiseLike; + cancel: boolean | PromiseLike | PromiseLike; }; /** @@ -2793,9 +2793,9 @@ export interface RowRemovingInfo { readonly key: TKey; /** * @docid - * @type boolean|Promise + * @type boolean|Promise|Promise */ - cancel: boolean | PromiseLike; + cancel: boolean | PromiseLike | PromiseLike; } /** @@ -2835,9 +2835,9 @@ export interface RowUpdatingInfo { readonly key: TKey; /** * @docid - * @type boolean|Promise + * @type boolean|Promise|Promise */ - cancel: boolean | PromiseLike; + cancel: boolean | PromiseLike | PromiseLike; } /** diff --git a/testing/testcafe/model/dataGrid/data/cell.ts b/testing/testcafe/model/dataGrid/data/cell.ts index b98bd8a32e20..158fd30c9d4c 100644 --- a/testing/testcafe/model/dataGrid/data/cell.ts +++ b/testing/testcafe/model/dataGrid/data/cell.ts @@ -19,6 +19,7 @@ const CLASS = { checkbox: 'dx-checkbox', linkEdit: 'dx-link-edit', linkSave: 'dx-link-save', + linkDelete: 'dx-link-delete', }; export default class DataCell extends FocusableElement { @@ -71,6 +72,10 @@ export default class DataCell extends FocusableElement { return this.element.find(`.${CLASS.linkSave}`); } + getLinkDelete(): Selector { + return this.element.find(`.${CLASS.linkDelete}`); + } + getIconByTitle(title: string): Selector { return this.element.find(`a[title=${title}]`); } diff --git a/testing/testcafe/tests/dataGrid/editing/editingEvents.ts b/testing/testcafe/tests/dataGrid/editing/editingEvents.ts new file mode 100644 index 000000000000..074baab3461a --- /dev/null +++ b/testing/testcafe/tests/dataGrid/editing/editingEvents.ts @@ -0,0 +1,173 @@ +import { ClientFunction } from 'testcafe'; +import createWidget from '../../../helpers/createWidget'; +import url from '../../../helpers/getPageUrl'; +import DataGrid from '../../../model/dataGrid'; + +fixture`Editing events` + .page(url(__dirname, '../../container.html')); + +// T1186997 +const testCases = [{ + caseName: 'e.cancel = promise:true', + expected: true, + + onRowUpdating: ClientFunction((e) => { + e.cancel = new Promise((resolve) => { + resolve(true); + }); + }), + onRowInserting: ClientFunction((e) => { + e.cancel = new Promise((resolve) => { + resolve(true); + }); + }), + onRowRemoving: ClientFunction((e) => { + e.cancel = new Promise((resolve) => { + resolve(true); + }); + }), +}, { + caseName: 'e.cancel = true', + expected: true, + + onRowUpdating: ClientFunction((e) => { + e.cancel = true; + }), + onRowInserting: ClientFunction((e) => { + e.cancel = true; + }), + onRowRemoving: ClientFunction((e) => { + e.cancel = true; + }), +}, { + caseName: 'e.cancel = promise:false', + expected: false, + + onRowUpdating: ClientFunction((e) => { + e.cancel = new Promise((resolve) => { + resolve(false); + }); + }), + onRowInserting: ClientFunction((e) => { + e.cancel = new Promise((resolve) => { + resolve(false); + }); + }), + onRowRemoving: ClientFunction((e) => { + e.cancel = new Promise((resolve) => { + resolve(false); + }); + }), +}, { + caseName: 'e.cancel = false', + expected: false, + + onRowUpdating: ClientFunction((e) => { + e.cancel = false; + }), + onRowInserting: ClientFunction((e) => { + e.cancel = false; + }), + onRowRemoving: ClientFunction((e) => { + e.cancel = false; + }), +}]; + +// onRowUpdating +testCases.forEach(({ caseName, expected, onRowUpdating }) => { + test(`onRowUpdating event should be work valid in case '${caseName}'`, async (t) => { + const dataGrid = new DataGrid('#container'); + const dataRow = dataGrid.getDataRow(0); + + await t + .click(dataRow.getDataCell(1).getLinkEdit()); + + await t + .typeText(dataRow.getDataCell(0).getEditor().element, 'test text') + .click(dataRow.getDataCell(1).getLinkSave()); + + await t.expect(dataRow.getDataCell(1).getLinkSave().exists).eql(expected); + }).before(async () => { + await createWidget('dxDataGrid', { + dataSource: [{ + ID: 1, + FirstName: 'John', + }], + columns: [{ + dataField: 'FirstName', + caption: 'Firs tName', + }], + height: 300, + editing: { + mode: 'row', + allowUpdating: true, + }, + onRowUpdating, + }); + }); +}); + +// onRowInserting +testCases.forEach(({ caseName, expected, onRowInserting }) => { + test(`onRowInserting event should be work valid in case '${caseName}'`, async (t) => { + const dataGrid = new DataGrid('#container'); + + const addRowButton = dataGrid.getToolbar().getItem(); + await t + .click(addRowButton); + + const dataRow = dataGrid.getDataRow(0); + await t + .typeText(dataRow.getDataCell(0).getEditor().element, 'test text') + .click(dataRow.getDataCell(1).getLinkSave()); + + await t + .expect(dataRow.getDataCell(0).getEditor().element.exists).eql(expected) + .expect(dataRow.getDataCell(1).getLinkSave().exists).eql(expected); + }).before(async () => { + await createWidget('dxDataGrid', { + dataSource: [], + columns: [{ + dataField: 'FirstName', + caption: 'Firs tName', + }], + height: 300, + editing: { + mode: 'row', + allowAdding: true, + }, + onRowInserting, + }); + }); +}); + +// onRowRemoving +testCases.forEach(({ caseName, expected, onRowRemoving }) => { + test(`onRowRemoving event should be work valid in case '${caseName}'`, async (t) => { + const dataGrid = new DataGrid('#container'); + + await t + .click(dataGrid.getDataRow(0).getDataCell(1).getLinkDelete()); + + await t + .expect(dataGrid.getDataRow(0).element.exists).eql(expected); + }).before(async () => { + await createWidget('dxDataGrid', { + dataSource: [{ + ID: 1, + FirstName: 'John', + }], + columns: [{ + dataField: 'FirstName', + caption: 'Firs tName', + }], + height: 300, + editing: { + mode: 'row', + allowDeleting: true, + confirmDelete: false, + }, + onRowRemoving, + }); + }); +}); diff --git a/ts/dx.all.d.ts b/ts/dx.all.d.ts index 05b292a211ad..3b475ac5abae 100644 --- a/ts/dx.all.d.ts +++ b/ts/dx.all.d.ts @@ -4184,7 +4184,7 @@ declare module DevExpress.common.grids { /** * [descr:RowInsertingInfo.cancel] */ - cancel: boolean | PromiseLike; + cancel: boolean | PromiseLike | PromiseLike; }; /** * [descr:RowKeyInfo] @@ -4230,7 +4230,7 @@ declare module DevExpress.common.grids { /** * [descr:RowRemovingInfo.cancel] */ - cancel: boolean | PromiseLike; + cancel: boolean | PromiseLike | PromiseLike; } /** * [descr:RowUpdatedInfo] @@ -4270,7 +4270,7 @@ declare module DevExpress.common.grids { /** * [descr:RowUpdatingInfo.cancel] */ - cancel: boolean | PromiseLike; + cancel: boolean | PromiseLike | PromiseLike; } /** * [descr:RowValidatingInfo]