refs #5070 refactor and added tests
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-03-01 14:22:25 +01:00
parent 48da6403fa
commit d62fbab3f1
5 changed files with 56 additions and 18 deletions

View File

@ -93,7 +93,14 @@
<vn-tr ng-repeat="ticket in $ctrl.summary.tickets">
<vn-td shrink>{{ticket.priority | dashIfEmpty}}</vn-td>
<vn-td expand title="{{ticket.address.street}}">{{ticket.street}}</vn-td>
<vn-td expand>{{ticket.city}}</vn-td>
<vn-td
expand
ng-click="$ctrl.goToBuscaman(ticket)"
class="link"
vn-tooltip="Open buscaman"
tooltip-position="up">
{{::ticket.city}}
</vn-td>
<vn-td shrink>{{ticket.postalCode}}</vn-td>
<vn-td>
<span

View File

@ -31,6 +31,21 @@ class Controller extends Summary {
this.sumPackages();
});
}
goToBuscaman(ticket) {
if (!this.route.vehicleFk)
throw new UserError(`The route doesn't have a vehicle`);
let query = `Routes/${this.route.vehicleFk}/getDeliveryPoint`;
this.$http.get(query).then(response => {
if (!response.data)
throw new UserError(`The route's vehicle doesn't have a delivery point`);
const address = response.data + '+to:' + ticket.postalCode + ' ' + ticket.city + ' ' + ticket.street;
const url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
window.open(url + encodeURI(address), '_blank');
});
}
}
ngModule.vnComponent('vnRouteSummary', {

View File

@ -37,5 +37,29 @@ describe('Route', () => {
expect(controller.packagesTotal).toEqual(4);
});
});
describe('goToBuscaman()', () => {
it('should open buscaman with the given arguments', () => {
jest.spyOn(window, 'open').mockReturnThis();
const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460%20Av%20Espioca%20100+to:n19%20London%20my%20street';
controller.route = {vehicleFk: 1};
const url = `Routes/${controller.route.vehicleFk}/getDeliveryPoint`;
$httpBackend.when('GET', `Routes/1/summary`).respond();
$httpBackend.expectGET(url).respond('46460 Av Espioca 100');
const ticket = {
id: 1,
checked: true,
street: 'my street',
postalCode: 'n19',
city: 'London'
};
controller.goToBuscaman(ticket);
$httpBackend.flush();
expect(window.open).toHaveBeenCalledWith(expectedUrl, '_blank');
});
});
});
});

View File

@ -74,31 +74,23 @@ class Controller extends Section {
return selectedItems;
}
goToBuscaman(clickedLine) {
goToBuscaman(ticket) {
if (!this.route.vehicleFk)
throw new UserError(`The route doesn't have a vehicle`);
let query = `Routes/${this.route.vehicleFk}/getDeliveryPoint`;
this.$http.get(query).then(response => {
if (!response.data)
this.$http.get(`Routes/${this.route.vehicleFk}/getDeliveryPoint`).then(res => {
if (!res.data)
throw new UserError(`The route's vehicle doesn't have a delivery point`);
return response.data;
}).then(address => {
let addresses;
if (address) addresses = address;
let lines = this.getSelectedItems(this.tickets);
if (clickedLine) lines = [clickedLine];
let url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
let addresses = res.data;
const lines = ticket ? [ticket] : this.getSelectedItems(this.tickets);
lines.forEach((line, index) => {
const previusLine = lines[index - 1] ? lines[index - 1].street : null;
if (previusLine != line.street)
const previousLine = lines[index - 1] ? lines[index - 1].street : null;
if (previousLine != line.street)
addresses = addresses + '+to:' + line.postalCode + ' ' + line.city + ' ' + line.street;
});
if (clickedLine) addresses = addresses.replace(address + '+to:', '',);
const url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
window.open(url + encodeURI(addresses), '_blank');
});
}

View File

@ -136,7 +136,7 @@ describe('Route', () => {
describe('goToBuscaman()', () => {
it('should open buscaman with the given arguments', () => {
jest.spyOn(window, 'open').mockReturnThis();
const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460 Av Espioca 100+to:n19 London my street';
const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460%20Av%20Espioca%20100+to:n19%20London%20my%20street';
controller.route = {vehicleFk: 1};
const url = `Routes/${controller.route.vehicleFk}/getDeliveryPoint`;
$httpBackend.expectGET(url).respond('46460 Av Espioca 100');