Skip to content

Commit

Permalink
Add onRowRemoving test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmakarov committed Sep 4, 2023
1 parent 3c66fca commit 04bfffa
Showing 1 changed file with 109 additions and 7 deletions.
116 changes: 109 additions & 7 deletions testing/testcafe/tests/dataGrid/editing/editingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,80 @@ fixture`Editing events`
.page(url(__dirname, '../../container.html'));

// T1186997

// onRowUpdating
[{
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;
}),
}].forEach(({ caseName, expected, onRowUpdating }) => {
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
.click(dataRow.getDataCell(1).getLinkEdit());

await t
.typeText(dataRow.getDataCell(0).getEditor().element, 'test text')
Expand All @@ -54,8 +92,7 @@ fixture`Editing events`
dataSource: [{
ID: 1,
FirstName: 'John',
},
],
}],
columns: [{
dataField: 'FirstName',
caption: 'Firs tName',
Expand All @@ -69,3 +106,68 @@ fixture`Editing events`
});
});
});

// 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,
});
});
});

0 comments on commit 04bfffa

Please sign in to comment.