Skip to content

Commit

Permalink
dxGrid - Add more TS typing in onRowUpdating, onRowDeleting, onRowAdd…
Browse files Browse the repository at this point in the history
…ing events(T1186997) (#25504)
  • Loading branch information
andrewmakarov authored Sep 7, 2023
1 parent c31e412 commit 44992d3
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 9 deletions.
12 changes: 6 additions & 6 deletions js/common/grids.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2746,9 +2746,9 @@ export type RowInsertingInfo<TRowData = any> = {
data: TRowData;
/**
* @docid
* @type Promise<void>
* @type boolean|Promise<boolean>|Promise<void>
*/
cancel: boolean | PromiseLike<void>;
cancel: boolean | PromiseLike<boolean> | PromiseLike<void>;
};

/**
Expand Down Expand Up @@ -2793,9 +2793,9 @@ export interface RowRemovingInfo<TRowData = any, TKey = any> {
readonly key: TKey;
/**
* @docid
* @type boolean|Promise<void>
* @type boolean|Promise<boolean>|Promise<void>
*/
cancel: boolean | PromiseLike<void>;
cancel: boolean | PromiseLike<boolean> | PromiseLike<void>;
}

/**
Expand Down Expand Up @@ -2835,9 +2835,9 @@ export interface RowUpdatingInfo<TRowData = any, TKey = any> {
readonly key: TKey;
/**
* @docid
* @type boolean|Promise<void>
* @type boolean|Promise<boolean>|Promise<void>
*/
cancel: boolean | PromiseLike<void>;
cancel: boolean | PromiseLike<boolean> | PromiseLike<void>;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions testing/testcafe/model/dataGrid/data/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}]`);
}
Expand Down
173 changes: 173 additions & 0 deletions testing/testcafe/tests/dataGrid/editing/editingEvents.ts
Original file line number Diff line number Diff line change
@@ -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,
});
});
});
6 changes: 3 additions & 3 deletions ts/dx.all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4184,7 +4184,7 @@ declare module DevExpress.common.grids {
/**
* [descr:RowInsertingInfo.cancel]
*/
cancel: boolean | PromiseLike<void>;
cancel: boolean | PromiseLike<boolean> | PromiseLike<void>;
};
/**
* [descr:RowKeyInfo]
Expand Down Expand Up @@ -4230,7 +4230,7 @@ declare module DevExpress.common.grids {
/**
* [descr:RowRemovingInfo.cancel]
*/
cancel: boolean | PromiseLike<void>;
cancel: boolean | PromiseLike<boolean> | PromiseLike<void>;
}
/**
* [descr:RowUpdatedInfo]
Expand Down Expand Up @@ -4270,7 +4270,7 @@ declare module DevExpress.common.grids {
/**
* [descr:RowUpdatingInfo.cancel]
*/
cancel: boolean | PromiseLike<void>;
cancel: boolean | PromiseLike<boolean> | PromiseLike<void>;
}
/**
* [descr:RowValidatingInfo]
Expand Down

0 comments on commit 44992d3

Please sign in to comment.