2019-10-23 07:25:28 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Route', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('route'));
|
2019-10-23 07:25:28 +00:00
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
controller = $componentController('vnRouteTickets');
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('route setter/getter', () => {
|
|
|
|
it('should return the route id', () => {
|
|
|
|
controller.route = 2;
|
|
|
|
|
|
|
|
expect(controller.route).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isChecked getter', () => {
|
|
|
|
it('should return false if none of the tickets is checked or there are no tickets', () => {
|
|
|
|
expect(controller.isChecked).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return true if any of the tickets is checked', () => {
|
|
|
|
controller.tickets = [{checked: true}];
|
|
|
|
|
|
|
|
expect(controller.isChecked).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('buildPossibleTicketsFilter()', () => {
|
|
|
|
it('should build the possible tickets filter', () => {
|
|
|
|
let expectedFilter = {
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'warehouse',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
relation: 'address'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
where: {
|
|
|
|
landed: {
|
|
|
|
between: [
|
|
|
|
jasmine.any(Date),
|
|
|
|
jasmine.any(Date)
|
|
|
|
]
|
|
|
|
},
|
|
|
|
routeFk: null,
|
|
|
|
zoneFk: 67
|
|
|
|
}
|
|
|
|
};
|
|
|
|
controller.route = {
|
|
|
|
finished: new Date(),
|
|
|
|
routeFk: null,
|
|
|
|
zoneFk: 67
|
|
|
|
};
|
|
|
|
|
|
|
|
controller.buildPossibleTicketsFilter();
|
|
|
|
|
|
|
|
expect(controller.possibleTicketsFilter).toEqual(expectedFilter);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getHighestPriority()', () => {
|
|
|
|
it('should return the highest value found in priorities plus 1', () => {
|
|
|
|
controller.$.model = {data: [
|
|
|
|
{priority: 99},
|
|
|
|
{priority: 1},
|
|
|
|
{priority: 2},
|
|
|
|
{priority: 3},
|
|
|
|
{priority: 4},
|
|
|
|
{priority: 5},
|
|
|
|
]};
|
|
|
|
|
|
|
|
let result = controller.getHighestPriority();
|
|
|
|
|
|
|
|
expect(result).toEqual(100);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setPriority()', () => {
|
|
|
|
it('should set a ticket priority', () => {
|
|
|
|
controller.$.model = {refresh: () => {}};
|
|
|
|
spyOn(controller.$.model, 'refresh');
|
|
|
|
spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
const ticketId = 1;
|
|
|
|
const priority = 999;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.expectPATCH(`Tickets/${ticketId}/`).respond('ok');
|
2019-10-23 07:25:28 +00:00
|
|
|
controller.setPriority(ticketId, priority);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getSelectedItems()', () => {
|
|
|
|
it('should return the selected items', () => {
|
|
|
|
let items = [
|
|
|
|
{id: 1, checked: true},
|
|
|
|
{id: 2, checked: false},
|
|
|
|
{id: 3, checked: true},
|
|
|
|
{id: 4, checked: false},
|
|
|
|
{id: 5, checked: true},
|
|
|
|
];
|
|
|
|
|
|
|
|
let selectedItems = controller.getSelectedItems(items);
|
|
|
|
|
|
|
|
expect(selectedItems).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('goToBuscaman()', () => {
|
|
|
|
it('should open buscaman with the given arguments', () => {
|
|
|
|
spyOn(window, 'open');
|
2019-12-10 11:42:14 +00:00
|
|
|
const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460 Av Espioca 100+to:n19 London my street';
|
|
|
|
controller.route = {vehicleFk: 1};
|
|
|
|
const url = `Routes/${controller.route.vehicleFk}/getDeliveryPoint`;
|
|
|
|
$httpBackend.expectGET(url).respond('46460 Av Espioca 100');
|
|
|
|
|
2019-10-23 07:25:28 +00:00
|
|
|
controller.tickets = [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
checked: true,
|
|
|
|
address: {
|
|
|
|
street: 'my street',
|
|
|
|
postalCode: 'n19',
|
|
|
|
city: 'London'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
controller.goToBuscaman();
|
2019-12-10 11:42:14 +00:00
|
|
|
$httpBackend.flush();
|
2019-10-23 07:25:28 +00:00
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalledWith(expectedUrl, '_blank');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('showDeleteConfirm()', () => {
|
|
|
|
it('should open a confirm dialog after setting the selected ticket into the controller', () => {
|
|
|
|
controller.$.confirm = {show: () => {}};
|
|
|
|
spyOn(controller.$.confirm, 'show');
|
|
|
|
let ticketId = 1;
|
|
|
|
|
|
|
|
controller.showDeleteConfirm(ticketId);
|
|
|
|
|
|
|
|
expect(controller.selectedTicket).toEqual(ticketId);
|
|
|
|
expect(controller.$.confirm.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeTicketFromRoute()', () => {
|
|
|
|
it('should perform a patch query then call showSuccess and updateVolume methods', () => {
|
|
|
|
spyOn(controller, 'updateVolume');
|
|
|
|
spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
let ticketId = 1;
|
|
|
|
controller.selectedTicket = ticketId;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.expectPATCH(`Tickets/${ticketId}/`).respond('ok');
|
2019-10-30 15:57:14 +00:00
|
|
|
controller.removeTicketFromRoute('accept');
|
2019-10-23 07:25:28 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket removed from route');
|
|
|
|
expect(controller.updateVolume).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateVolume()', () => {
|
|
|
|
it('should perform a POST query then call both reload and refresh methods', () => {
|
|
|
|
controller.$.model = {refresh: () => {}};
|
|
|
|
controller.card = {reload: () => {}};
|
|
|
|
controller.$stateParamds = {id: 999};
|
|
|
|
spyOn(controller.$.model, 'refresh');
|
|
|
|
spyOn(controller.card, 'reload');
|
|
|
|
|
|
|
|
let ticketId = 1;
|
|
|
|
controller.selectedTicket = ticketId;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
const url = `Routes/${controller.$stateParams.id}/updateVolume`;
|
2019-10-23 07:25:28 +00:00
|
|
|
$httpBackend.expectPOST(url).respond('ok');
|
|
|
|
controller.updateVolume();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
|
|
expect(controller.card.reload).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('guessPriority()', () => {
|
|
|
|
it('should perform a GET query then call both refresh and showSuccess methods', () => {
|
|
|
|
controller.$.model = {refresh: () => {}};
|
|
|
|
spyOn(controller.$.model, 'refresh');
|
|
|
|
spyOn(controller.vnApp, 'showSuccess');
|
2019-10-23 13:04:05 +00:00
|
|
|
controller.$stateParams = {id: 99};
|
2019-10-23 07:25:28 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
const url = `Routes/${controller.$stateParams.id}/guessPriority/`;
|
2019-10-23 07:25:28 +00:00
|
|
|
$httpBackend.expectGET(url).respond('ok');
|
|
|
|
controller.guessPriority();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Order changed');
|
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('showTicketDescriptor()', () => {
|
|
|
|
it('should call the descriptor show function after setting the parent and the ticket id', () => {
|
|
|
|
controller.$.ticketDescriptor = {show: () => {}};
|
|
|
|
spyOn(controller.$.ticketDescriptor, 'show');
|
|
|
|
const event = {target: {}, preventDefault: () => {}};
|
|
|
|
spyOn(event, 'preventDefault');
|
|
|
|
const ticketId = 999;
|
|
|
|
controller.showTicketDescriptor(event, ticketId);
|
|
|
|
|
|
|
|
expect(controller.$.ticketDescriptor.ticketFk).toEqual(ticketId);
|
|
|
|
expect(controller.$.ticketDescriptor.show).toHaveBeenCalledWith();
|
|
|
|
expect(event.preventDefault).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('showClientDescriptor()', () => {
|
|
|
|
it('should call the descriptor show method after setting the parent and the client id', () => {
|
|
|
|
controller.$.clientDescriptor = {show: () => {}};
|
|
|
|
spyOn(controller.$.clientDescriptor, 'show');
|
|
|
|
const event = {target: {}, preventDefault: () => {}};
|
|
|
|
spyOn(event, 'preventDefault');
|
|
|
|
const clientId = 999;
|
|
|
|
controller.showClientDescriptor(event, clientId);
|
|
|
|
|
|
|
|
expect(controller.$.clientDescriptor.clientFk).toEqual(clientId);
|
|
|
|
expect(controller.$.clientDescriptor.show).toHaveBeenCalledWith();
|
|
|
|
expect(event.preventDefault).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('openPossibleTicketsDialog()', () => {
|
|
|
|
it('should call both refresh and show methods in posible tickets model and dialog', () => {
|
|
|
|
controller.$.possibleTicketsModel = {refresh: () => {}};
|
|
|
|
spyOn(controller.$.possibleTicketsModel, 'refresh');
|
|
|
|
controller.$.possibleTicketsDialog = {show: () => {}};
|
|
|
|
spyOn(controller.$.possibleTicketsDialog, 'show');
|
|
|
|
|
|
|
|
controller.openPossibleTicketsDialog();
|
|
|
|
|
|
|
|
expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith();
|
|
|
|
expect(controller.$.possibleTicketsDialog.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setTicketsRoute()', () => {
|
|
|
|
it('should perform a POST query to add tickets to the route', done => {
|
|
|
|
controller.$.possibleTicketsModel = {save: () => {}};
|
|
|
|
spyOn(controller.$.possibleTicketsModel, 'save').and.returnValue(Promise.resolve());
|
|
|
|
controller.$.model = {data: [
|
|
|
|
{id: 1, checked: false}
|
|
|
|
]};
|
|
|
|
|
|
|
|
controller.route = {id: 111};
|
|
|
|
|
|
|
|
controller.possibleTickets = [
|
|
|
|
{id: 2, checked: false},
|
|
|
|
{id: 3, checked: true},
|
|
|
|
{id: 4, checked: false},
|
|
|
|
{id: 5, checked: true},
|
|
|
|
];
|
|
|
|
|
|
|
|
let expectedResult = [
|
|
|
|
{checked: false, id: 1},
|
|
|
|
{id: 3, routeFk: 111},
|
|
|
|
{id: 5, routeFk: 111}
|
|
|
|
];
|
|
|
|
|
2019-10-30 15:57:14 +00:00
|
|
|
controller.setTicketsRoute('accept').then(() => {
|
2019-10-23 07:25:28 +00:00
|
|
|
expect(controller.$.model.data).toEqual(expectedResult);
|
|
|
|
done();
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should just return a promise', () => {
|
2019-10-30 15:57:14 +00:00
|
|
|
expect(controller.setTicketsRoute('cancel')).toEqual(jasmine.any(Promise));
|
2019-10-23 07:25:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|