front unit tests fix for lastests buys
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2021-11-11 17:18:19 +01:00
parent 4fe7d4f566
commit acd2d2e51f
3 changed files with 72 additions and 46 deletions

View File

@ -63,8 +63,21 @@ describe('Entry', () => {
} }
]}`; ]}`;
const expectedBuys = [ const expectedBuys = [
{'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, {
{'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} 'buyingValue': 5.77,
'description': 'Bow',
'grouping': 1,
'packing': 1,
'size': 1,
'volume': 1200},
{
'buyingValue': 2.16,
'description': 'Arrow',
'grouping': 1,
'packing': 1,
'size': 25,
'volume': 1125}
]; ];
controller.fillData(rawData); controller.fillData(rawData);
controller.$.$apply(); controller.$.$apply();
@ -81,8 +94,21 @@ describe('Entry', () => {
describe('fetchBuys()', () => { describe('fetchBuys()', () => {
it(`should perform a query to fetch the buys data`, () => { it(`should perform a query to fetch the buys data`, () => {
const buys = [ const buys = [
{'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, {
{'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} 'buyingValue': 5.77,
'description': 'Bow',
'grouping': 1,
'packing': 1,
'size': 1,
'volume': 1200},
{
'buyingValue': 2.16,
'description': 'Arrow',
'grouping': 1,
'packing': 1,
'size': 25,
'volume': 1125}
]; ];
const serializedParams = $httpParamSerializer({buys}); const serializedParams = $httpParamSerializer({buys});
@ -105,17 +131,31 @@ describe('Entry', () => {
observation: '123456', observation: '123456',
ref: '1, 2', ref: '1, 2',
buys: [ buys: [
{'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, {
{'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} 'buyingValue': 5.77,
'description': 'Bow',
'grouping': 1,
'packing': 1,
'size': 1,
'volume': 1200},
{
'buyingValue': 2.16,
'description': 'Arrow',
'grouping': 1,
'packing': 1,
'size': 25,
'volume': 1125}
] ]
}; };
controller.onSubmit(); controller.onSubmit();
expect(controller.vnApp.showError).toHaveBeenCalledWith(`Some of the imported buys doesn't have an item`); const message = `Some of the imported buys doesn't have an item`;
expect(controller.vnApp.showError).toHaveBeenCalledWith(message);
}); });
it(`should perform a query to update columns`, () => { it(`should now perform a query to update columns`, () => {
jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.vnApp, 'showSuccess');
controller.$state.go = jest.fn(); controller.$state.go = jest.fn();
@ -123,8 +163,22 @@ describe('Entry', () => {
observation: '123456', observation: '123456',
ref: '1, 2', ref: '1, 2',
buys: [ buys: [
{'itemFk': 10, 'buyingValue': 5.77, 'description': 'Bow', 'grouping': 1, 'packing': 1, 'size': 1, 'volume': 1200}, {
{'itemFk': 11, 'buyingValue': 2.16, 'description': 'Arrow', 'grouping': 1, 'packing': 1, 'size': 25, 'volume': 1125} 'itemFk': 10,
'buyingValue': 5.77,
'description': 'Bow',
'grouping': 1,
'packing': 1,
'size': 1,
'volume': 1200},
{
'itemFk': 11,
'buyingValue': 2.16,
'description': 'Arrow',
'grouping': 1,
'packing': 1,
'size': 25,
'volume': 1125}
] ]
}; };
const params = controller.import; const params = controller.import;

View File

@ -143,7 +143,7 @@ export default class Controller extends Section {
for (let row of this.checked) for (let row of this.checked)
rowsToEdit.push({id: row.id, itemFk: row.itemFk}); rowsToEdit.push({id: row.id, itemFk: row.itemFk});
let data = { const data = {
field: this.editedColumn.field, field: this.editedColumn.field,
newValue: this.editedColumn.newValue, newValue: this.editedColumn.newValue,
lines: rowsToEdit lines: rowsToEdit

View File

@ -7,9 +7,9 @@ describe('Entry', () => {
beforeEach(ngModule('entry')); beforeEach(ngModule('entry'));
beforeEach(angular.mock.inject(($componentController, $compile, $rootScope, _$httpBackend_) => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
let $element = $compile('<vn-entry-latest-buys></vn-entry-latest-buys')($rootScope); const $element = angular.element('<vn-entry-latest-buys></vn-entry-latest-buys');
controller = $componentController('vnEntryLatestBuys', {$element}); controller = $componentController('vnEntryLatestBuys', {$element});
controller.$ = { controller.$ = {
model: {refresh: () => {}}, model: {refresh: () => {}},
@ -31,10 +31,10 @@ describe('Entry', () => {
describe('get checked', () => { describe('get checked', () => {
it(`should return a set of checked lines`, () => { it(`should return a set of checked lines`, () => {
controller.$.model.data = [ controller.$.model.data = [
{checked: true, id: 1}, {$checked: true, id: 1},
{checked: true, id: 2}, {$checked: true, id: 2},
{checked: true, id: 3}, {$checked: true, id: 3},
{checked: false, id: 4}, {$checked: false, id: 4},
]; ];
let result = controller.checked; let result = controller.checked;
@ -43,38 +43,10 @@ describe('Entry', () => {
}); });
}); });
describe('uncheck()', () => {
it(`should clear the selection of lines on the controller`, () => {
controller.$.model.data = [
{checked: true, id: 1},
{checked: true, id: 2},
{checked: true, id: 3},
{checked: false, id: 4},
];
let result = controller.checked;
expect(result.length).toEqual(3);
controller.uncheck();
result = controller.checked;
expect(result.length).toEqual(0);
});
});
describe('onEditAccept()', () => { describe('onEditAccept()', () => {
it(`should perform a query to update columns`, () => { it(`should perform a query to update columns`, () => {
$httpBackend.whenGET('UserConfigViews/getConfig?tableCode=latestBuys').respond([]);
$httpBackend.whenGET('Buys/latestBuysFilter?filter=%7B%22limit%22:20%7D').respond([
{entryFk: 1},
{entryFk: 2},
{entryFk: 3},
{entryFk: 4}
]);
controller.editedColumn = {field: 'my field', newValue: 'the new value'}; controller.editedColumn = {field: 'my field', newValue: 'the new value'};
let query = 'Buys/editLatestBuys'; const query = 'Buys/editLatestBuys';
$httpBackend.expectPOST(query).respond(); $httpBackend.expectPOST(query).respond();
controller.onEditAccept(); controller.onEditAccept();