E2E fixes, model bug fixes, Nightmare getProperty extensions

This commit is contained in:
Juan 2018-10-19 19:54:46 +02:00
parent 74e234a099
commit 4607bce91e
8 changed files with 88 additions and 165 deletions

View File

@ -149,8 +149,10 @@ export default class CrudModel extends ModelProxy {
let update = []; let update = [];
let remove = []; let remove = [];
let pk = this.primaryKey;
for (let row of this.removed) for (let row of this.removed)
remove.push(row[this.primaryKey]); remove.push(row.$orgRow[pk]);
for (let row of this._data) { for (let row of this._data) {
if (row.$isNew) { if (row.$isNew) {
@ -163,7 +165,10 @@ export default class CrudModel extends ModelProxy {
let data = {}; let data = {};
for (let prop in row.$oldData) for (let prop in row.$oldData)
data[prop] = row[prop]; data[prop] = row[prop];
update.push(data); update.push({
data,
where: {[pk]: row.$orgRow[pk]}
});
} }
} }

View File

@ -17,8 +17,7 @@ export class Filtrable {
* *
* @property {String|Array<String>|Function} order The sort specification * @property {String|Array<String>|Function} order The sort specification
*/ */
export class Sortable { export class Sortable {}
}
/** /**
* Paginable model. * Paginable model.
@ -75,7 +74,7 @@ export default class ModelProxy extends DataModel {
this.proxiedData = new Array(value.length); this.proxiedData = new Array(value.length);
for (let i = 0; i < value.length; i++) for (let i = 0; i < value.length; i++)
this.proxiedData[i] = this.createRow(Object.assign({}, value[i]), i); this.proxiedData[i] = this.createRow(Object.assign({}, value[i]), i, value[i]);
} else } else
this.proxiedData = null; this.proxiedData = null;
@ -119,7 +118,7 @@ export default class ModelProxy extends DataModel {
return index; return index;
} }
createRow(obj, index) { createRow(obj, index, orgRow) {
let proxy = new Proxy(obj, { let proxy = new Proxy(obj, {
set: (obj, prop, value) => { set: (obj, prop, value) => {
if (prop.charAt(0) !== '$' && value !== obj[prop] && !obj.$isNew) { if (prop.charAt(0) !== '$' && value !== obj[prop] && !obj.$isNew) {
@ -134,6 +133,7 @@ export default class ModelProxy extends DataModel {
}); });
Object.assign(proxy, { Object.assign(proxy, {
$orgIndex: index, $orgIndex: index,
$orgRow: orgRow,
$oldData: null, $oldData: null,
$isNew: false $isNew: false
}); });
@ -155,17 +155,18 @@ export default class ModelProxy extends DataModel {
let orgData = this.orgData; let orgData = this.orgData;
if (!data) return; if (!data) return;
for (let row of this.removed) { for (let row of data) {
if (row.$isNew) { if (row.$isNew) {
let data = {}; let orgRow = {};
for (let prop in row) for (let prop in row)
if (prop.charAt(0) !== '$') if (prop.charAt(0) !== '$')
data[prop] = row[prop]; orgRow[prop] = row[prop];
row.$orgIndex = orgData.push(data) - 1; row.$orgIndex = orgData.push(orgRow) - 1;
row.$orgRow = orgRow;
row.$isNew = false; row.$isNew = false;
} else if (row.$oldData) } else if (row.$oldData)
for (let prop in row.$oldData) for (let prop in row.$oldData)
orgData[row.$orgIndex][prop] = row[prop]; row.$orgRow[prop] = row[prop];
} }
let removed = this.removed; let removed = this.removed;

View File

@ -44,6 +44,21 @@ Nightmare.action('parsedUrl', function(done) {
}); });
}); });
Nightmare.action('getProperty', function(selector, property, done) {
this.evaluate_now((selector, property) => {
return document.querySelector(selector)[property];
}, done, selector, property);
});
Nightmare.action('waitProperty', function(selector, property, done) {
this.wait((selector, property) => {
let element = document.querySelector(selector);
return element && element[property] != null && element[property] !== '';
}, selector, property)
.getProperty(selector, property)
.then(result => done(null, result), done);
});
Nightmare.action('getInnerText', function(selector, done) { Nightmare.action('getInnerText', function(selector, done) {
this.wait(selector) this.wait(selector)
.evaluate_now(function(elementToSelect) { .evaluate_now(function(elementToSelect) {

View File

@ -63,21 +63,22 @@ describe('Item', () => {
return nightmare return nightmare
.click(selectors.itemTags.tagsButton) .click(selectors.itemTags.tagsButton)
.wait(selectors.itemTags.firstTagDisabled) .wait(selectors.itemTags.firstTagDisabled)
.click(selectors.itemTax.taxButton)
.waitToClick(selectors.itemTax.taxButton) .waitToClick(selectors.itemTax.taxButton)
.waitForTextInInput(selectors.itemTax.firstClassSelect, 'general') .waitForTextInInput(selectors.itemTax.firstClassSelect, 'reduced')
.getInputValue(selectors.itemTax.firstClassSelect) .getInputValue(selectors.itemTax.firstClassSelect)
.then(result => { .then(result => {
expect(result).toEqual('General VAT'); expect(result).toEqual('Reduced VAT');
return nightmare return nightmare
.getInputValue(selectors.itemTax.secondClassSelect); .getInputValue(selectors.itemTax.secondClassSelect);
}) })
.then(result => { .then(result => {
expect(result).toEqual('Reduced VAT'); expect(result).toEqual('General VAT');
return nightmare return nightmare
.getInputValue(selectors.itemTax.thirdClassSelect); .getInputValue(selectors.itemTax.thirdClassSelect);
}) })
.then(result => { .then(result => {
expect(result).toEqual('General VAT'); expect(result).toEqual('Reduced VAT');
}); });
}); });
}); });

View File

@ -60,142 +60,62 @@ describe('Item', () => {
}); });
}); });
it(`should confirm the first select is the expected one`, () => { it(`should reload tags form to check that the changes are saved`, () => {
return nightmare return nightmare
.click(selectors.itemBasicData.basicDataButton) .click(selectors.itemBasicData.basicDataButton)
.wait(selectors.itemBasicData.nameInput) .wait(selectors.itemBasicData.nameInput)
.click(selectors.itemTags.tagsButton) .click(selectors.itemTags.tagsButton)
.waitForTextInInput(selectors.itemTags.firstTagSelect, 'Diámetro') .wait('vn-item-tags');
.getInputValue(selectors.itemTags.firstTagSelect)
.then(result => {
expect(result).toEqual('Diámetro');
});
}); });
it(`should confirm the first value is the expected one`, () => { it(`should confirm the first row data is the expected one`, async() => {
return nightmare let tag = await nightmare.getProperty(selectors.itemTags.firstTagSelect, 'value');
.waitForTextInInput(selectors.itemTags.firstValueInput, '50') let value = await nightmare.getProperty(selectors.itemTags.firstValueInput, 'value');
.getInputValue(selectors.itemTags.firstValueInput) let relevancy = await nightmare.getProperty(selectors.itemTags.firstRelevancyInput, 'value');
.then(result => {
expect(result).toEqual('50'); expect(tag).toEqual('Ancho de la base');
}); expect(value).toEqual('50');
expect(relevancy).toEqual('1');
}); });
it(`should confirm the first relevancy is the expected one`, () => { it(`should confirm the second row data is the expected one`, async() => {
return nightmare let tag = await nightmare.getProperty(selectors.itemTags.secondTagSelect, 'value');
.waitForTextInInput(selectors.itemTags.firstRelevancyInput, '1') let value = await nightmare.getProperty(selectors.itemTags.secondValueInput, 'value');
.getInputValue(selectors.itemTags.firstRelevancyInput) let relevancy = await nightmare.getProperty(selectors.itemTags.secondRelevancyInput, 'value');
.then(result => {
expect(result).toEqual('1'); expect(tag).toEqual('Variedad');
}); expect(value).toEqual('Gem1');
expect(relevancy).toEqual('2');
}); });
it(`should confirm the second select is the expected one`, () => { it(`should confirm the second row data is the expected one`, async() => {
return nightmare let tag = await nightmare.getProperty(selectors.itemTags.thirdTagSelect, 'value');
.waitForTextInInput(selectors.itemTags.secondTagSelect, 'Variedad') let value = await nightmare.getProperty(selectors.itemTags.thirdValueInput, 'value');
.getInputValue(selectors.itemTags.secondTagSelect) let relevancy = await nightmare.getProperty(selectors.itemTags.thirdRelevancyInput, 'value');
.then(result => {
expect(result).toEqual('Variedad'); expect(tag).toEqual('Longitud(cm)');
}); expect(value).toEqual('5');
expect(relevancy).toEqual('3');
}); });
it(`should confirm the second value is the expected one`, () => { it(`should confirm the fourth row data is the expected one`, async() => {
return nightmare let tag = await nightmare.getProperty(selectors.itemTags.fourthTagSelect, 'value');
.waitForTextInInput(selectors.itemTags.secondValueInput, 'Gem1') let value = await nightmare.getProperty(selectors.itemTags.fourthValueInput, 'value');
.getInputValue(selectors.itemTags.secondValueInput) let relevancy = await nightmare.getProperty(selectors.itemTags.fourthRelevancyInput, 'value');
.then(result => {
expect(result).toEqual('Gem1'); expect(tag).toEqual('Proveedor');
}); expect(value).toEqual('Marvel1');
expect(relevancy).toEqual('4');
}); });
it(`should confirm the second relevancy is the expected one`, () => { it(`should confirm the fifth row data is the expected one`, async() => {
return nightmare let tag = await nightmare.getProperty(selectors.itemTags.fifthTagSelect, 'value');
.waitForTextInInput(selectors.itemTags.secondRelevancyInput, '2') let value = await nightmare.getProperty(selectors.itemTags.fifthValueInput, 'value');
.getInputValue(selectors.itemTags.secondRelevancyInput) let relevancy = await nightmare.getProperty(selectors.itemTags.fifthRelevancyInput, 'value');
.then(result => {
expect(result).toEqual('2');
});
});
it(`should confirm the third select is the expected one`, () => { expect(tag).toEqual('Color');
return nightmare expect(value).toEqual('Yellow');
.waitForTextInInput(selectors.itemTags.thirdTagSelect, 'Longitud(cm)') expect(relevancy).toEqual('5');
.getInputValue(selectors.itemTags.thirdTagSelect)
.then(result => {
expect(result).toEqual('Longitud(cm)');
});
});
it(`should confirm the third value is the expected one`, () => {
return nightmare
.waitForTextInInput(selectors.itemTags.thirdValueInput, '5')
.getInputValue(selectors.itemTags.thirdValueInput)
.then(result => {
expect(result).toEqual('5');
});
});
it(`should confirm the third relevancy is the expected one`, () => {
return nightmare
.waitForTextInInput(selectors.itemTags.thirdRelevancyInput, '3')
.getInputValue(selectors.itemTags.thirdRelevancyInput)
.then(result => {
expect(result).toEqual('3');
});
});
it(`should confirm the fourth select is the expected one`, () => {
return nightmare
.waitForTextInInput(selectors.itemTags.fourthTagSelect, 'Proveedor')
.getInputValue(selectors.itemTags.fourthTagSelect)
.then(result => {
expect(result).toEqual('Proveedor');
});
});
it(`should confirm the fourth value is the expected one`, () => {
return nightmare
.waitForTextInInput(selectors.itemTags.fourthValueInput, 'Marvel1')
.getInputValue(selectors.itemTags.fourthValueInput)
.then(result => {
expect(result).toEqual('Marvel1');
});
});
it(`should confirm the fourth relevancy is the expected one`, () => {
return nightmare
.waitForTextInInput(selectors.itemTags.fourthRelevancyInput, '4')
.getInputValue(selectors.itemTags.fourthRelevancyInput)
.then(result => {
expect(result).toEqual('4');
});
});
it(`should confirm the fifth select is the expected one`, () => {
return nightmare
.waitForTextInInput(selectors.itemTags.fifthTagSelect, 'Color')
.getInputValue(selectors.itemTags.fifthTagSelect)
.then(result => {
expect(result).toEqual('Color');
});
});
it(`should confirm the fifth value is the expected one`, () => {
return nightmare
.waitForTextInInput(selectors.itemTags.fifthValueInput, 'Yellow')
.getInputValue(selectors.itemTags.fifthValueInput)
.then(result => {
expect(result).toEqual('Yellow');
});
});
it(`should confirm the fifth relevancy is the expected one`, () => {
return nightmare
.waitForTextInInput(selectors.itemTags.fifthRelevancyInput, '5')
.getInputValue(selectors.itemTags.fifthRelevancyInput)
.then(result => {
expect(result).toEqual('5');
});
}); });
}); });
}); });

View File

@ -49,7 +49,6 @@ describe('Ticket', () => {
.waitToClick(selectors.ticketNotes.firstNoteRemoveButton) .waitToClick(selectors.ticketNotes.firstNoteRemoveButton)
.waitToClick(selectors.ticketNotes.addNoteButton) .waitToClick(selectors.ticketNotes.addNoteButton)
.waitToClick(selectors.ticketNotes.firstNoteSelect) .waitToClick(selectors.ticketNotes.firstNoteSelect)
.waitForTextInElement(selectors.ticketNotes.firstNoteSelectSecondOption, 'observation two')
.waitToClick(selectors.ticketNotes.firstNoteSelectSecondOption) .waitToClick(selectors.ticketNotes.firstNoteSelectSecondOption)
.type(selectors.ticketNotes.firstDescriptionInput, 'description') .type(selectors.ticketNotes.firstDescriptionInput, 'description')
.click(selectors.ticketNotes.submitNotesButton) .click(selectors.ticketNotes.submitNotesButton)
@ -64,12 +63,11 @@ describe('Ticket', () => {
.click(selectors.ticketPackages.packagesButton) .click(selectors.ticketPackages.packagesButton)
.wait(selectors.ticketPackages.firstPackageSelect) .wait(selectors.ticketPackages.firstPackageSelect)
.click(selectors.ticketNotes.notesButton) .click(selectors.ticketNotes.notesButton)
.waitForTextInInput(selectors.ticketNotes.firstNoteSelect, 'observation two') .waitProperty(selectors.ticketNotes.firstNoteSelect, 'value')
.getInputValue(selectors.ticketNotes.firstNoteSelect)
.then(result => { .then(result => {
expect(result).toEqual('observation two'); expect(result).toEqual('observation one');
return nightmare return nightmare
.getInputValue(selectors.ticketNotes.firstDescriptionInput); .getProperty(selectors.ticketNotes.firstDescriptionInput, 'value');
}) })
.then(result => { .then(result => {
expect(result).toEqual('description'); expect(result).toEqual('description');

29
package-lock.json generated
View File

@ -5,9 +5,9 @@
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@types/node": { "@types/node": {
"version": "8.10.32", "version": "8.10.36",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.32.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.36.tgz",
"integrity": "sha512-8OfXpkB3E0jhpcpyVlqJDV5mkXlrsJrDZR7q0uss8SBdW8IxNdx/J2o5m7cM2qbFzyd/o+aV5Z4OJcIukI6UlA==", "integrity": "sha512-SL6KhfM7PTqiFmbCW3eVNwVBZ+88Mrzbuvn9olPsfv43mbiWaFY+nRcz/TGGku0/lc2FepdMbImdMY1JrQ+zbw==",
"dev": true "dev": true
}, },
"@uirouter/angularjs": { "@uirouter/angularjs": {
@ -4407,7 +4407,7 @@
}, },
"jsonfile": { "jsonfile": {
"version": "2.4.0", "version": "2.4.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", "resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
"integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -5525,21 +5525,6 @@
"typedarray": "^0.0.6" "typedarray": "^0.0.6"
} }
}, },
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha1-XRKFFd8TT/Mn6QpMk/Tgd6U2NB8=",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
},
"process-nextick-args": { "process-nextick-args": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
@ -5548,7 +5533,7 @@
}, },
"readable-stream": { "readable-stream": {
"version": "2.3.6", "version": "2.3.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -17380,7 +17365,7 @@
}, },
"readable-stream": { "readable-stream": {
"version": "1.1.14", "version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -21864,7 +21849,6 @@
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -22033,7 +22017,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }

View File

@ -153,7 +153,7 @@ module.exports = function(Self) {
try { try {
let promises = []; let promises = [];
actions.update.forEach(toUpdate => { actions.update.forEach(toUpdate => {
promises.push(this.upsert(toUpdate, options)); promises.push(this.upsertWithWhere(toUpdate.where, toUpdate.data, options));
}); });
await Promise.all(promises); await Promise.all(promises);
} catch (error) { } catch (error) {