This commit is contained in:
parent
500105675c
commit
a16b43546d
|
@ -4,8 +4,6 @@ import createNightmare from '../../helpers/nightmare';
|
||||||
describe('Client log path', () => {
|
describe('Client log path', () => {
|
||||||
const nightmare = createNightmare();
|
const nightmare = createNightmare();
|
||||||
|
|
||||||
let date;
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
nightmare
|
nightmare
|
||||||
.loginAndModule('employee', 'client')
|
.loginAndModule('employee', 'client')
|
||||||
|
@ -19,7 +17,6 @@ describe('Client log path', () => {
|
||||||
.write(selectors.clientBasicData.nameInput, 'this is a test')
|
.write(selectors.clientBasicData.nameInput, 'this is a test')
|
||||||
.waitToClick(selectors.clientBasicData.saveButton)
|
.waitToClick(selectors.clientBasicData.saveButton)
|
||||||
.waitForLastSnackbar();
|
.waitForLastSnackbar();
|
||||||
date = new Date();
|
|
||||||
|
|
||||||
expect(result).toEqual('Data saved!');
|
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() => {
|
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
|
let lastModificationPreviousValue = await nightmare
|
||||||
.waitToGetProperty(selectors.clientLog.lastModificationPreviousValue, 'innerText');
|
.waitToGetProperty(selectors.clientLog.lastModificationPreviousValue, 'innerText');
|
||||||
|
|
||||||
let lastModificationCurrentValue = await nightmare
|
let lastModificationCurrentValue = await nightmare
|
||||||
.waitToGetProperty(selectors.clientLog.lastModificationCurrentValue, 'innerText');
|
.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(lastModificationPreviousValue).toEqual('name: DavidCharlesHaller');
|
||||||
expect(lastModificationCurrentValue).toEqual('name: this is a test');
|
expect(lastModificationCurrentValue).toEqual('name: this is a test');
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,8 @@ module.exports = Self => {
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
arg: 'volumes'
|
type: ['Object'],
|
||||||
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/:id/getVolume`,
|
path: `/:id/getVolume`,
|
||||||
|
|
|
@ -3,8 +3,12 @@
|
||||||
url="/ticket/api/sales"
|
url="/ticket/api/sales"
|
||||||
filter="::$ctrl.filter"
|
filter="::$ctrl.filter"
|
||||||
link="{ticketFk: $ctrl.$stateParams.id}"
|
link="{ticketFk: $ctrl.$stateParams.id}"
|
||||||
limit="20"
|
data="$ctrl.sales"
|
||||||
data="sales" on-data-change="$ctrl.onDataChange()">
|
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>
|
</vn-crud-model>
|
||||||
<mg-ajax path="/client/api/tickets/{{$ctrl.$stateParams.id}}/getTotalVolume" options="mgEdit"></mg-ajax>
|
<mg-ajax path="/client/api/tickets/{{$ctrl.$stateParams.id}}/getTotalVolume" options="mgEdit"></mg-ajax>
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
|
@ -30,7 +34,7 @@
|
||||||
</vn-tr>
|
</vn-tr>
|
||||||
</vn-thead>
|
</vn-thead>
|
||||||
<vn-tbody>
|
<vn-tbody>
|
||||||
<vn-tr ng-repeat="sale in sales">
|
<vn-tr ng-repeat="sale in $ctrl.sales">
|
||||||
<vn-td number>
|
<vn-td number>
|
||||||
<span
|
<span
|
||||||
ng-click="$ctrl.showDescriptor($event, sale.itemFk)"
|
ng-click="$ctrl.showDescriptor($event, sale.itemFk)"
|
||||||
|
|
|
@ -14,19 +14,37 @@ class Controller {
|
||||||
this.ticketVolumes = [];
|
this.ticketVolumes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
onDataChange() {
|
get sales() {
|
||||||
this.$http.get(`/api/tickets/${this.ticket.id}/getVolume`)
|
return this._sales;
|
||||||
.then(response => {
|
}
|
||||||
if (response.data) {
|
|
||||||
this.$scope.model.data.forEach(sale => {
|
set sales(value) {
|
||||||
response.data.volumes.forEach(volume => {
|
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)
|
if (sale.id === volume.saleFk)
|
||||||
sale.volume = volume;
|
sale.volume = volume;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
showDescriptor(event, itemFk) {
|
showDescriptor(event, itemFk) {
|
||||||
this.quicklinks = {
|
this.quicklinks = {
|
||||||
|
|
|
@ -22,7 +22,50 @@ describe('ticket', () => {
|
||||||
controller = $componentController('vnTicketVolume', {$scope, $httpBackend, $state});
|
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};
|
controller.ticket = {id: 1};
|
||||||
let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]};
|
let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]};
|
||||||
$httpBackend.whenGET(`/api/tickets/1/getVolume`).respond(response);
|
$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[0].volume.m3).toBe(0.008);
|
||||||
expect($scope.model.data[1].volume.m3).toBe(0.003);
|
expect($scope.model.data[1].volume.m3).toBe(0.003);
|
||||||
});
|
}); */
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue