Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dxGrid - Add more TS typing in onRowUpdating, onRowDeleting, onRowAdding events(T1186997) #25504

Merged
merged 8 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions js/common/grids.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2748,7 +2748,7 @@ export type RowInsertingInfo<TRowData = any> = {
* @docid
* @type Promise<void>
*/
cancel: boolean | PromiseLike<void>;
cancel: boolean | PromiseLike<boolean> | PromiseLike<void>;
};

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

/**
Expand Down Expand Up @@ -2837,7 +2837,7 @@ export interface RowUpdatingInfo<TRowData = any, TKey = any> {
* @docid
* @type 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 @@ -17,6 +17,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 @@ -65,6 +66,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