backend unit test for barcode duplicity plus e2e path completed

This commit is contained in:
Carlos Jimenez 2018-02-19 11:55:45 +01:00
parent f2d5d58513
commit dcf5bf61da
5 changed files with 121 additions and 62 deletions

View File

@ -1,31 +1,31 @@
<form name="form" ng-submit="$ctrl.submit()"> <form name="form" ng-submit="$ctrl.submit()">
<vn-card> <vn-card>
<vn-vertical pad-large> <vn-vertical pad-large>
<vn-one margin-medium-top> <vn-one margin-medium-top>
<vn-title>Item Barcodes</vn-title> <vn-title>Item Barcodes</vn-title>
<mg-ajax path="/item/api/ItemBarcodes" options="mgIndex as barcodes"></mg-ajax> <mg-ajax path="/item/api/ItemBarcodes" options="mgIndex as barcodes"></mg-ajax>
<vn-horizontal ng-repeat="barcode in $ctrl.barcodes track by $index"> <vn-horizontal ng-repeat="barcode in $ctrl.barcodes track by $index">
<vn-textfield vn-three label="code" model="barcode.code" vn-acl="buyer, replenisher"></vn-textfield> <vn-textfield vn-three label="code" model="barcode.code" vn-acl="buyer, replenisher"></vn-textfield>
<vn-one pad-medium-top> <vn-one pad-medium-top>
<vn-icon <vn-icon
vn-acl="buyer, replenisher" vn-acl="buyer, replenisher"
pointer pointer
medium-grey medium-grey
icon="remove_circle_outline" icon="remove_circle_outline"
ng-click="$ctrl.removeBarcode($index)"> ng-click="$ctrl.removeBarcode($index)">
</vn-icon> </vn-icon>
<vn-icon <vn-icon
vn-acl="buyer, replenisher" vn-acl="buyer, replenisher"
pointer pointer
margin-medium-left margin-medium-left
orange orange
icon="add_circle" icon="add_circle"
ng-if = "barcode.showAddIcon" ng-if = "barcode.showAddIcon"
ng-click="$ctrl.addBarcode()" ng-click="$ctrl.addBarcode()"
></vn-icon> ></vn-icon>
</vn-one> </vn-one>
</vn-horizontal> </vn-horizontal>
</vn-one> </vn-one>
</vn-vertical> </vn-vertical>
</vn-card> </vn-card>
<vn-button-bar> <vn-button-bar>

View File

@ -145,8 +145,16 @@ export default {
searchItemInput: `${components.vnTextfield}`, searchItemInput: `${components.vnTextfield}`,
searchButton: `${components.vnSearchBar} > vn-icon-button > button` searchButton: `${components.vnSearchBar} > vn-icon-button > button`
}, },
itemBasicData: {
basicDataButton: `${components.vnMenuItem}[ui-sref="item.card.data"]`
},
itemBarcodes: { itemBarcodes: {
barcodeButton: `${components.vnMenuItem}[ui-sref="item.card.itemBarcode"]` barcodeButton: `${components.vnMenuItem}[ui-sref="item.card.itemBarcode"]`,
addBarcodeButton: `${components.vnIcon}[icon="add_circle"]`,
thirdCodeInput: `vn-horizontal:nth-child(5) > ${components.vnTextfield}`,
fourthCodeInput: `vn-horizontal:nth-child(6) > ${components.vnTextfield}`,
submitBarcodesButton: `${components.vnSubmit}`,
firstCodeRemoveButton: `vn-horizontal:nth-child(3) > vn-one > ${components.vnIcon}[icon="remove_circle_outline"]`
} }
}; };

View File

@ -55,17 +55,47 @@ describe('create item barcodes path', () => {
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
// it(`should click on the search result to access to the item barcodes`, done => { it(`should click on the search result to access to the item barcodes`, done => {
// nightmare nightmare
// .waitForTextInElement(selectors.itemsIndex.searchResult, 'Gem of Time') .waitForTextInElement(selectors.itemsIndex.searchResult, 'Gem of Time')
// .waitToClick(selectors.itemsIndex.searchResult) .waitToClick(selectors.itemsIndex.searchResult)
// .waitToClick(selectors.itemBarcodes.barcodeButton) .waitToClick(selectors.itemBarcodes.barcodeButton)
// .waitForURL('barcode') .waitForURL('barcode')
// .url() .url()
// .then(url => { .then(url => {
// expect(url).toContain('barcode'); expect(url).toContain('barcode');
// done(); done();
// }) })
// .catch(catchErrors(done)); .catch(catchErrors(done));
// }); });
it(`should click create a new code and delete a former one`, done => {
nightmare
.waitToClick(selectors.itemBarcodes.addBarcodeButton)
.type(selectors.itemBarcodes.fourthCodeInput, '5')
.click(selectors.itemBarcodes.firstCodeRemoveButton)
.click(selectors.itemBarcodes.submitBarcodesButton)
.wait(selectors.globalItems.snackbarIsActive)
.getInnerText(selectors.globalItems.snackbarIsActive)
.then(result => {
expect(result).toContain('Data saved!');
done();
})
.catch(catchErrors(done));
});
it(`should confirm the barcode 5 is created and it is now the third barcode as the first was deleted`, done => {
nightmare
.waitForSnackbarReset()
.click(selectors.itemBasicData.basicDataButton)
.wait(selectors.itemBasicData.nameInput)
.click(selectors.itemBarcodes.barcodeButton)
.wait(200)
.getInputValue(selectors.itemBarcodes.thirdCodeInput)
.then(result => {
expect(result).toEqual('5');
done();
})
.catch(catchErrors(done));
});
}); });

View File

@ -1,7 +1,19 @@
const crudItemBarcodes = require('../crudItemBarcodes'); const crudItemBarcodes = require('../crudItemBarcodes');
const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors;
let mysql = require('mysql2');
describe('Item crudItemBarcodes()', () => { describe('Item crudItemBarcodes()', () => {
let connection;
beforeAll(() => {
connection = mysql.createConnection({
multipleStatements: true,
host: 'localhost',
user: 'root',
password: '',
database: 'salix'
});
});
it('should call the destroyAll methodif there are ids in delete Array', done => { it('should call the destroyAll methodif there are ids in delete Array', done => {
let self = jasmine.createSpyObj('self', ['remoteMethod', 'crudItemBarcodes', 'destroyAll', 'create', 'upsert']); let self = jasmine.createSpyObj('self', ['remoteMethod', 'crudItemBarcodes', 'destroyAll', 'create', 'upsert']);
@ -48,4 +60,13 @@ describe('Item crudItemBarcodes()', () => {
}) })
.catch(catchErrors(done)); .catch(catchErrors(done));
}); });
it('should return an error when attempting to save a duplicated barcode', done => {
let callback = (err, res) => {
expect(err.toString()).toBe("Error: Duplicate entry '4' for key 'PRIMARY'");
done();
};
connection.query('INSERT INTO `vn`.`itemBarcode` VALUES (4, 2 ,4 );', callback);
});
}); });

View File

@ -1,28 +1,28 @@
{ {
"name": "ItemBarcode", "name": "ItemBarcode",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "itemBarcode", "table": "itemBarcode",
"database": "vn" "database": "vn"
}
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"code": {
"type": "String",
"required": true
} }
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
}, },
"relations": { "code": {
"item": { "type": "String",
"type": "belongsTo", "required": true
"model": "Item",
"foreignKey": "itemFk"
}
} }
},
"relations": {
"item": {
"type": "belongsTo",
"model": "Item",
"foreignKey": "itemFk"
}
} }
}