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-tr ng-repeat="ticket in $ctrl.summary.tickets">
<vn-td shrink>{{ticket.priority | dashIfEmpty}}</vn-td> <vn-td shrink>{{ticket.priority | dashIfEmpty}}</vn-td>
<vn-td expand title="{{ticket.address.street}}">{{ticket.street}}</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 shrink>{{ticket.postalCode}}</vn-td>
<vn-td> <vn-td>
<span <span

View File

@ -31,6 +31,21 @@ class Controller extends Summary {
this.sumPackages(); 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', { ngModule.vnComponent('vnRouteSummary', {

View File

@ -37,5 +37,29 @@ describe('Route', () => {
expect(controller.packagesTotal).toEqual(4); 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; return selectedItems;
} }
goToBuscaman(clickedLine) { goToBuscaman(ticket) {
if (!this.route.vehicleFk) if (!this.route.vehicleFk)
throw new UserError(`The route doesn't have a vehicle`); throw new UserError(`The route doesn't have a vehicle`);
let query = `Routes/${this.route.vehicleFk}/getDeliveryPoint`;
this.$http.get(query).then(response => { this.$http.get(`Routes/${this.route.vehicleFk}/getDeliveryPoint`).then(res => {
if (!response.data) if (!res.data)
throw new UserError(`The route's vehicle doesn't have a delivery point`); throw new UserError(`The route's vehicle doesn't have a delivery point`);
return response.data; let addresses = res.data;
}).then(address => { const lines = ticket ? [ticket] : this.getSelectedItems(this.tickets);
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=';
lines.forEach((line, index) => { lines.forEach((line, index) => {
const previusLine = lines[index - 1] ? lines[index - 1].street : null; const previousLine = lines[index - 1] ? lines[index - 1].street : null;
if (previusLine != line.street) if (previousLine != line.street)
addresses = addresses + '+to:' + line.postalCode + ' ' + line.city + ' ' + 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'); window.open(url + encodeURI(addresses), '_blank');
}); });
} }

View File

@ -136,7 +136,7 @@ describe('Route', () => {
describe('goToBuscaman()', () => { describe('goToBuscaman()', () => {
it('should open buscaman with the given arguments', () => { it('should open buscaman with the given arguments', () => {
jest.spyOn(window, 'open').mockReturnThis(); 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}; controller.route = {vehicleFk: 1};
const url = `Routes/${controller.route.vehicleFk}/getDeliveryPoint`; const url = `Routes/${controller.route.vehicleFk}/getDeliveryPoint`;
$httpBackend.expectGET(url).respond('46460 Av Espioca 100'); $httpBackend.expectGET(url).respond('46460 Av Espioca 100');