2018-08-09 12:42:02 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Ticket', () => {
|
|
|
|
describe('Component vnTicketExpedition', () => {
|
|
|
|
let controller;
|
|
|
|
let $scope;
|
|
|
|
let $httpBackend;
|
2022-05-04 08:35:31 +00:00
|
|
|
let $window;
|
2018-08-09 12:42:02 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-08-09 12:42:02 +00:00
|
|
|
|
2022-05-04 08:35:31 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$window_) => {
|
|
|
|
$window = _$window_;
|
2018-08-09 12:42:02 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.model = {
|
|
|
|
refresh: () => {}
|
|
|
|
};
|
2020-04-28 12:26:02 +00:00
|
|
|
controller = $componentController('vnTicketExpedition', {$element: null, $scope});
|
2022-10-07 11:49:42 +00:00
|
|
|
controller.$.model.data = [
|
|
|
|
{id: 1},
|
|
|
|
{id: 2},
|
|
|
|
{id: 3}
|
|
|
|
];
|
|
|
|
const modelData = controller.$.model.data;
|
|
|
|
modelData[0].checked = true;
|
|
|
|
modelData[1].checked = true;
|
2018-08-09 12:42:02 +00:00
|
|
|
}));
|
|
|
|
|
2020-04-28 12:26:02 +00:00
|
|
|
describe('onDialogAccept()', () => {
|
2018-08-09 12:42:02 +00:00
|
|
|
it('should perform a DELETE query', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn($scope.model, 'refresh');
|
2018-08-09 12:42:02 +00:00
|
|
|
|
2020-04-28 12:26:02 +00:00
|
|
|
const id = 1;
|
2018-08-09 12:42:02 +00:00
|
|
|
|
2020-04-28 12:26:02 +00:00
|
|
|
$httpBackend.expectDELETE(`Expeditions/${id}`).respond(200);
|
|
|
|
controller.onDialogAccept(id);
|
2018-08-09 12:42:02 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect($scope.model.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2022-05-04 08:35:31 +00:00
|
|
|
|
2022-05-04 10:05:46 +00:00
|
|
|
describe('showLog()', () => {
|
|
|
|
it('should show the popover status log', () => {
|
|
|
|
controller.$.statusLog = {show: () => {}};
|
|
|
|
jest.spyOn(controller.$.statusLog, 'show');
|
|
|
|
|
|
|
|
const expedition = {id: 1};
|
|
|
|
|
|
|
|
const event = new MouseEvent('click', {
|
|
|
|
view: $window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true
|
|
|
|
});
|
|
|
|
controller.showLog(event, expedition);
|
|
|
|
|
|
|
|
expect(controller.$.statusLog.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2022-10-07 11:49:42 +00:00
|
|
|
|
|
|
|
describe('onRemove()', () => {
|
|
|
|
it('should make a query and then call to the model refresh() method', () => {
|
|
|
|
jest.spyOn($scope.model, 'refresh');
|
|
|
|
|
2022-10-18 09:47:37 +00:00
|
|
|
const expectedParams = {expeditionIds: [1, 2]};
|
2022-10-07 11:49:42 +00:00
|
|
|
$httpBackend.expect('POST', 'Expeditions/deleteExpeditions', expectedParams).respond(200);
|
|
|
|
controller.onRemove();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect($scope.model.refresh).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createTicket()', () => {
|
|
|
|
it('should make a query and then call to the $state go() method', () => {
|
|
|
|
jest.spyOn(controller.$state, 'go').mockReturnThis();
|
|
|
|
|
|
|
|
const ticket = {
|
|
|
|
clientFk: 1101,
|
|
|
|
landed: new Date(),
|
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 1,
|
|
|
|
warehouseFk: 1
|
|
|
|
};
|
|
|
|
controller.ticket = ticket;
|
|
|
|
|
|
|
|
const expectedTicket = {
|
|
|
|
clientId: 1101,
|
|
|
|
landed: new Date(),
|
|
|
|
addressId: 121,
|
|
|
|
agencyModeId: 1,
|
|
|
|
warehouseId: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
const ticketIdToTransfer = 28;
|
|
|
|
const expectedResponse = {id: ticketIdToTransfer};
|
|
|
|
|
|
|
|
const expectedParams = {
|
2022-10-18 09:47:37 +00:00
|
|
|
expeditionIds: [1, 2],
|
2022-10-07 11:49:42 +00:00
|
|
|
ticketId: 28
|
|
|
|
};
|
|
|
|
$httpBackend.expect('POST', 'Tickets/new', expectedTicket).respond(expectedResponse);
|
|
|
|
$httpBackend.expect('POST', 'Expeditions/moveExpeditions', expectedParams).respond(200);
|
|
|
|
controller.createTicket();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', {id: ticketIdToTransfer});
|
|
|
|
});
|
|
|
|
});
|
2018-08-09 12:42:02 +00:00
|
|
|
});
|
|
|
|
});
|