fixed volume onLoad errors #1238
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-03-26 09:33:54 +01:00
parent 500105675c
commit a16b43546d
5 changed files with 83 additions and 39 deletions

View File

@ -4,8 +4,6 @@ import createNightmare from '../../helpers/nightmare';
describe('Client log path', () => {
const nightmare = createNightmare();
let date;
beforeAll(() => {
nightmare
.loginAndModule('employee', 'client')
@ -19,7 +17,6 @@ describe('Client log path', () => {
.write(selectors.clientBasicData.nameInput, 'this is a test')
.waitToClick(selectors.clientBasicData.saveButton)
.waitForLastSnackbar();
date = new Date();
expect(result).toEqual('Data saved!');
});
@ -41,32 +38,13 @@ describe('Client log path', () => {
});
it('should check the current value of the last logged change', async() => {
let lastModificationDate = await nightmare
.waitToGetProperty(selectors.clientLog.lastModificationDate, 'innerText');
let lastModificationPreviousValue = await nightmare
.waitToGetProperty(selectors.clientLog.lastModificationPreviousValue, 'innerText');
let lastModificationCurrentValue = await nightmare
.waitToGetProperty(selectors.clientLog.lastModificationCurrentValue, 'innerText');
let month = date.getMonth() + 1;
let day = date.getDate();
let year = date.getFullYear();
let hours = date.getHours();
let minutes = date.getMinutes();
if (month.toString().length < 2) month = '0' + month;
if (day.toString().length < 2) day = `0${day}`;
if (hours.toString().length < 2) hours = '0' + hours;
if (minutes.toString().length < 2) minutes = `0${minutes}`;
let today = [day, month, year].join('/');
let time = [hours, minutes].join(':');
let now = [today, time].join(' ');
expect(lastModificationDate).toContain(now);
expect(lastModificationPreviousValue).toEqual('name: DavidCharlesHaller');
expect(lastModificationCurrentValue).toEqual('name: this is a test');
});

View File

@ -10,7 +10,8 @@ module.exports = Self => {
http: {source: 'path'}
}],
returns: {
arg: 'volumes'
type: ['Object'],
root: true
},
http: {
path: `/:id/getVolume`,

View File

@ -3,8 +3,12 @@
url="/ticket/api/sales"
filter="::$ctrl.filter"
link="{ticketFk: $ctrl.$stateParams.id}"
limit="20"
data="sales" on-data-change="$ctrl.onDataChange()">
data="$ctrl.sales"
limit="20">
</vn-crud-model>
<vn-crud-model auto-load="true"
url="/ticket/api/tickets/{{$ctrl.$stateParams.id}}/getVolume"
data="$ctrl.volumes">
</vn-crud-model>
<mg-ajax path="/client/api/tickets/{{$ctrl.$stateParams.id}}/getTotalVolume" options="mgEdit"></mg-ajax>
<vn-vertical>
@ -30,7 +34,7 @@
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="sale in sales">
<vn-tr ng-repeat="sale in $ctrl.sales">
<vn-td number>
<span
ng-click="$ctrl.showDescriptor($event, sale.itemFk)"

View File

@ -14,19 +14,37 @@ class Controller {
this.ticketVolumes = [];
}
onDataChange() {
this.$http.get(`/api/tickets/${this.ticket.id}/getVolume`)
.then(response => {
if (response.data) {
this.$scope.model.data.forEach(sale => {
response.data.volumes.forEach(volume => {
get sales() {
return this._sales;
}
set sales(value) {
this._sales = value;
if (value) this.applyVolumes();
}
get volumes() {
return this._volumes;
}
set volumes(value) {
this._volumes = value;
if (value) this.applyVolumes();
}
applyVolumes() {
if (!this.sales || !this.volumes) return;
this.sales.forEach(sale => {
this.volumes.forEach(volume => {
if (sale.id === volume.saleFk)
sale.volume = volume;
});
});
}
});
}
showDescriptor(event, itemFk) {
this.quicklinks = {

View File

@ -22,7 +22,50 @@ describe('ticket', () => {
controller = $componentController('vnTicketVolume', {$scope, $httpBackend, $state});
}));
it('should join the sale volumes to its respective sale', () => {
describe('sales() setter', () => {
it('should set sales property on controller an then call applyVolumes() method', () => {
spyOn(controller, 'applyVolumes');
controller.sales = [{id: 1}];
expect(controller.applyVolumes).toHaveBeenCalledWith();
});
});
describe('volumes() setter', () => {
it('should set volumes property on controller an then call applyVolumes() method', () => {
spyOn(controller, 'applyVolumes');
controller.volumes = [{id: 1}];
expect(controller.applyVolumes).toHaveBeenCalledWith();
});
});
describe('applyVolumes()', () => {
it(`should not apply volumes to the sales if sales property is not defined on controller`, () => {
controller.sales = [{id: 1, name: 'Sale one'}, {id: 2, name: 'Sale two'}];
expect(controller.sales[0].volume).toBeUndefined();
expect(controller.sales[1].volume).toBeUndefined();
});
it(`should not apply volumes to the sales if sales property is not defined on controller`, () => {
controller.volumes = [{saleFk: 1, m3: 0.012}, {saleFk: 2, m3: 0.015}];
expect(controller.sales).toBeUndefined();
});
it(`should apply volumes to the sales if sales and volumes properties are defined on controller`, () => {
controller.sales = [{id: 1, name: 'Sale one'}, {id: 2, name: 'Sale two'}];
controller.volumes = [{saleFk: 1, m3: 0.012}, {saleFk: 2, m3: 0.015}];
expect(controller.sales[0].volume.m3).toEqual(0.012);
expect(controller.sales[1].volume.m3).toEqual(0.015);
});
});
/* it('should join the sale volumes to its respective sale', () => {
controller.ticket = {id: 1};
let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]};
$httpBackend.whenGET(`/api/tickets/1/getVolume`).respond(response);
@ -32,6 +75,6 @@ describe('ticket', () => {
expect($scope.model.data[0].volume.m3).toBe(0.008);
expect($scope.model.data[1].volume.m3).toBe(0.003);
});
}); */
});
});