2022-03-08 14:17:18 +00:00
|
|
|
/* eslint max-len: ["error", { "code": 150 }]*/
|
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Route', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $scope;
|
|
|
|
|
|
|
|
beforeEach(ngModule('route'));
|
|
|
|
|
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
const $element = angular.element('<vn-route-ticket-popup></vn-route-ticket-popup>');
|
2022-03-09 07:08:13 +00:00
|
|
|
const $transclude = {
|
|
|
|
$$boundTransclude: {
|
|
|
|
$$slots: []
|
|
|
|
}
|
|
|
|
};
|
|
|
|
controller = $componentController('vnRouteTicketPopup', {$element, $scope, $transclude});
|
2022-03-08 14:17:18 +00:00
|
|
|
controller.route = {id: 1};
|
|
|
|
controller.$.model = {
|
|
|
|
refresh: () => {},
|
|
|
|
remove: () => {}
|
|
|
|
};
|
|
|
|
controller.card = {reload: () => {}};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('unlink()', () => {
|
|
|
|
it('should call the route unlink endpoint with the agency and zone ids', () => {
|
|
|
|
controller.$.model = {refresh: jest.fn()};
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2022-03-09 07:08:13 +00:00
|
|
|
jest.spyOn(controller, 'hide');
|
2022-03-08 14:17:18 +00:00
|
|
|
|
|
|
|
controller.route = {
|
|
|
|
agencyModeFk: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
const ticket = {
|
|
|
|
zoneFk: 2,
|
|
|
|
};
|
|
|
|
const params = {
|
|
|
|
agencyModeId: controller.route.agencyModeFk,
|
|
|
|
zoneId: ticket.zoneFk,
|
|
|
|
};
|
|
|
|
|
|
|
|
$httpBackend.expectPOST(`Routes/unlink`, params).respond('ok');
|
|
|
|
controller.unlinkZone(ticket);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2022-03-09 07:08:13 +00:00
|
|
|
expect(controller.hide).toHaveBeenCalled();
|
2022-03-08 14:17:18 +00:00
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setTicketsRoute()', () => {
|
|
|
|
it('should perform a POST query to add tickets to the route', () => {
|
|
|
|
controller.$.model = {refresh: jest.fn()};
|
2022-03-09 07:08:13 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
jest.spyOn(controller, 'hide');
|
2022-03-08 14:17:18 +00:00
|
|
|
|
|
|
|
controller.route = {id: 111};
|
|
|
|
|
|
|
|
controller.possibleTickets = [
|
|
|
|
{id: 2, checked: false},
|
|
|
|
{id: 3, checked: true},
|
|
|
|
{id: 4, checked: false},
|
|
|
|
{id: 5, checked: true},
|
|
|
|
];
|
|
|
|
|
2022-03-09 07:08:13 +00:00
|
|
|
$httpBackend.whenPOST(`Routes/${controller.route.id}/updateVolume`).respond(200);
|
|
|
|
$httpBackend.expectPOST('Tickets/crud').respond();
|
2022-03-08 14:17:18 +00:00
|
|
|
controller.setTicketsRoute();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2022-03-09 07:08:13 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
expect(controller.hide).toHaveBeenCalled();
|
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
2022-03-08 14:17:18 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|