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

110 lines
3.7 KiB
JavaScript
Raw Normal View History

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
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: () => {}
};
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
}));
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
const id = 1;
2018-08-09 12:42: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();
2022-11-14 14:11:33 +00:00
const landed = new Date();
2022-10-07 11:49:42 +00:00
const ticket = {
clientFk: 1101,
2022-11-14 14:11:33 +00:00
landed: landed,
2022-10-07 11:49:42 +00:00
addressFk: 121,
agencyModeFk: 1,
warehouseFk: 1
};
2022-10-20 06:17:15 +00:00
const routeId = null;
2022-10-07 11:49:42 +00:00
controller.ticket = ticket;
2022-10-20 06:17:15 +00:00
const ticketToTransfer = {id: 28};
const expectedParams = {
2022-10-07 11:49:42 +00:00
clientId: 1101,
2022-11-14 14:11:33 +00:00
landed: landed,
2022-10-20 06:17:15 +00:00
warehouseId: 1,
2022-10-07 11:49:42 +00:00
addressId: 121,
agencyModeId: 1,
2022-10-20 06:17:15 +00:00
routeId: null,
expeditionIds: [1, 2]
2022-10-07 11:49:42 +00:00
};
2022-10-20 06:17:15 +00:00
$httpBackend.expect('POST', 'Expeditions/moveExpeditions', expectedParams).respond(ticketToTransfer);
controller.createTicket(ticket.landed, routeId);
2022-10-07 11:49:42 +00:00
$httpBackend.flush();
2022-10-20 06:17:15 +00:00
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', {id: ticketToTransfer.id});
2022-10-07 11:49:42 +00:00
});
});
2018-08-09 12:42:02 +00:00
});
});