salix/modules/route/front/summary/index.spec.js

66 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2019-03-22 10:10:23 +00:00
import './index.js';
describe('Route', () => {
describe('Component summary', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('route'));
2019-03-22 10:10:23 +00:00
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, _$httpBackend_) => {
2019-03-22 10:10:23 +00:00
$httpBackend = _$httpBackend_;
2020-03-17 14:24:55 +00:00
const $element = angular.element('<vn-route-summary></vn-route-summary>');
controller = $componentController('vnRouteSummary', {$element});
2019-03-22 10:10:23 +00:00
controller.route = {id: 1};
}));
describe('getSummary()', () => {
it('should perform a query to set summary', () => {
$httpBackend.when('GET', `Routes/1/summary`).respond(200, 24);
2019-03-22 10:10:23 +00:00
controller.getSummary();
$httpBackend.flush();
expect(controller.summary).toEqual(24);
});
});
2019-03-25 12:16:34 +00:00
describe('sumPackages()', () => {
it('should calculate the packages total', () => {
controller.summary = {
tickets: [
{packages: 3},
{packages: 1}
]
};
controller.sumPackages();
expect(controller.packagesTotal).toEqual(4);
});
});
2023-03-01 13:22:25 +00:00
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');
});
});
2019-03-22 10:10:23 +00:00
});
});