84 lines
2.7 KiB
JavaScript
84 lines
2.7 KiB
JavaScript
/* 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>');
|
|
controller = $componentController('vnRouteTicketPopup', {$element, $scope});
|
|
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');
|
|
|
|
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();
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('setTicketsRoute()', () => {
|
|
it('should perform a POST query to add tickets to the route', () => {
|
|
controller.$.model = {refresh: jest.fn()};
|
|
|
|
controller.route = {id: 1101};
|
|
controller.$.model.data = [{id: 1, checked: false}];
|
|
|
|
const existingTicket = controller.$.model.data[0];
|
|
|
|
controller.route = {id: 111};
|
|
|
|
controller.possibleTickets = [
|
|
{id: 2, checked: false},
|
|
{id: 3, checked: true},
|
|
{id: 4, checked: false},
|
|
{id: 5, checked: true},
|
|
];
|
|
|
|
let expectedResult = [
|
|
existingTicket,
|
|
{id: 3},
|
|
{id: 5}
|
|
];
|
|
|
|
$httpBackend.expectPOST(`Routes/${controller.route.id}/updateVolume`).respond(200);
|
|
$httpBackend.whenPOST('Tickets/crud').respond();
|
|
controller.setTicketsRoute();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.$.model.data).toEqual(expectedResult);
|
|
// expect(controller.$.possibleTicketsDialog.hide).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
});
|