salix/modules/ticket/front/expedition/index.spec.js

113 lines
3.8 KiB
JavaScript

import './index';
describe('Ticket', () => {
describe('Component vnTicketExpedition', () => {
let controller;
let $scope;
let $httpBackend;
let $window;
beforeEach(ngModule('ticket'));
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$window_) => {
$window = _$window_;
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
$scope.model = {
refresh: () => {}
};
controller = $componentController('vnTicketExpedition', {$element: null, $scope});
controller.$.model.data = [
{id: 1},
{id: 2},
{id: 3}
];
const modelData = controller.$.model.data;
modelData[0].checked = true;
modelData[1].checked = true;
}));
describe('onDialogAccept()', () => {
it('should perform a DELETE query', () => {
jest.spyOn($scope.model, 'refresh');
const id = 1;
$httpBackend.expectDELETE(`Expeditions/${id}`).respond(200);
controller.onDialogAccept(id);
$httpBackend.flush();
expect($scope.model.refresh).toHaveBeenCalledWith();
});
});
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();
});
});
describe('onRemove()', () => {
it('should make a query and then call to the model refresh() method', () => {
jest.spyOn($scope.model, 'refresh');
const expectedParams = {expeditionIds: [1, 2]};
$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 = {
expeditionIds: [1, 2],
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});
});
});
});
});