Skip to content

Commit

Permalink
Update delete before recoed data cancel test
Browse files Browse the repository at this point in the history
  • Loading branch information
BobrikovMikhail committed Aug 6, 2024
1 parent f060ff6 commit 6180170
Showing 1 changed file with 55 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,84 +6,75 @@ import FilterOperator from 'ember-flexberry-data/query/filter-operator';
import { click } from '@ember/test-helpers';
import $ from 'jquery';

executeTest('check delete before record data cancel test', (store, assert, app) => {
executeTest('check delete before record data cancel test', async (store, assert, app) => {
assert.expect(5);
let path = 'components-examples/flexberry-objectlistview/before-delete-record/folv-for-before-delete-record-data-cancel';
let modelName = 'ember-flexberry-dummy-suggestion-type';
let howAddRec = 1;
let uuid = '0' + generateUniqueId();
const path = 'components-examples/flexberry-objectlistview/before-delete-record/folv-for-before-delete-record-data-cancel';
const modelName = 'ember-flexberry-dummy-suggestion-type';
const howAddRec = 1;
const uuid = '0' + generateUniqueId();

// Add records for deleting.
run(() => {
await run(async() => {
let newRecord = store.createRecord(modelName, { name: uuid });
let done1 = assert.async();

newRecord.save().then(() => {
addDataForDestroy(newRecord);
let builder = new Builder(store).from(modelName).count();
let done = assert.async();
store.query(modelName, builder.build()).then((result) => {
visit(path + '?perPage=' + result.meta.count);
andThen(() => {
assert.equal(currentPath(), path);
await newRecord.save()
addDataForDestroy(newRecord);
let builder = new Builder(store).from(modelName).count();

let result = await store.query(modelName, builder.build());
await visit(path + '?perPage=' + result.meta.count);

assert.equal(currentPath(), path);

let olvContainerClass = '.object-list-view-container';
let trTableClass = 'table.object-list-view tbody tr';
let olvContainerClass = '.object-list-view-container';
let trTableClass = 'table.object-list-view tbody tr';

let $folvContainer = $(olvContainerClass);
let $rows = () => { return $(trTableClass, $folvContainer).toArray(); };
let $folvContainer = $(olvContainerClass);
let $rows = () => { return $(trTableClass, $folvContainer).toArray(); };

// Check that the records have been added.
let recordIsForDeleting = $rows().reduce((sum, element) => {
let nameRecord = $.trim(element.children[1].innerText);
let flag = nameRecord.indexOf(uuid) >= 0;
return sum + flag;
}, 0);
// Check that the records have been added.
let recordIsForDeleting = $rows().reduce((sum, element) => {
let nameRecord = $.trim(element.children[1].innerText);
let flag = nameRecord.indexOf(uuid) >= 0;
return sum + flag;
}, 0);

assert.equal(recordIsForDeleting > 0, true, howAddRec + ' record added');
assert.equal(recordIsForDeleting > 0, true, howAddRec + ' record added');

/* eslint-disable no-unused-vars */
let clickPromises = [];
$rows().forEach(function(element, i, arr) {
let nameRecord = $.trim(element.children[1].innerText);
if (nameRecord.indexOf(uuid) >= 0) {
let $deleteBtnInRow = $('.object-list-view-row-delete-button', element)[0];
clickPromises.push(click($deleteBtnInRow));
}
});
/* eslint-enable no-unused-vars */
/* eslint-disable no-unused-vars */
let clickPromises = [];
$rows().forEach(function(element, i, arr) {
let nameRecord = $.trim(element.children[1].innerText);
if (nameRecord.indexOf(uuid) >= 0) {
let $deleteBtnInRow = $('.object-list-view-row-delete-button', element)[0];
clickPromises.push(click($deleteBtnInRow));
}
});
/* eslint-enable no-unused-vars */

Promise.all(clickPromises).then(() => {
let done2 = assert.async();
await Promise.all(clickPromises);

// Check that the records wasn't remove in beforeDeleteRecord.
let controller = app.__container__.lookup('controller:' + currentRouteName());
assert.ok(controller.recordWasNotDelete, 'Records wasn\'t remove in beforeDeleteRecord');
// Check that the records wasn't remove in beforeDeleteRecord.
let controller = app.__container__.lookup('controller:' + currentRouteName());
assert.ok(controller.recordWasNotDelete, 'Records wasn\'t remove in beforeDeleteRecord');

// Check that the records have been removed.
let recordsIsDeleteBtnInRow = $rows().every((element) => {
let nameRecord = $.trim(element.children[1].innerText);
return nameRecord.indexOf(uuid) < 0;
});
// Check that the records have been removed.
let recordsIsDeleteBtnInRow = $rows().every((element) => {
let nameRecord = $.trim(element.children[1].innerText);
return nameRecord.indexOf(uuid) < 0;
});

assert.notOk(recordsIsDeleteBtnInRow, 'Each entry begins with \'' + uuid + '\' wasn\'t deleted with button in row');
assert.notOk(recordsIsDeleteBtnInRow, 'Each entry begins with \'' + uuid + '\' wasn\'t deleted with button in row');

// Check that the records hadn't removed from store.
let builder2 = new Builder(store, modelName).where('name', FilterOperator.Eq, uuid).count();
let timeout = 500;
later((function() {
store.query(modelName, builder2.build()).then((result) => {
assert.ok(result.meta.count, 'record \'' + uuid + '\'not found in store');
done2();
}).finally(() => {
newRecord.destroyRecord();
});
}), timeout);
});
});
done();
});
done1();
});
// Check that the records hadn't removed from store.
let builder2 = new Builder(store, modelName).where('name', FilterOperator.Eq, uuid).count();
let timeout = 500;
await new Promise(resolve =>
later(async() => {
let result = await store.query(modelName, builder2.build());
assert.ok(result.meta.count, 'record \'' + uuid + '\'not found in store');
resolve();
await newRecord.destroyRecord();
}, timeout));
});
});

0 comments on commit 6180170

Please sign in to comment.