salix/modules/claim/front/detail/index.spec.js

144 lines
5.7 KiB
JavaScript
Raw Normal View History

2018-08-30 07:19:09 +00:00
import './index.js';
2018-12-27 11:54:16 +00:00
import crudModel from 'core/mocks/crud-model';
2018-08-30 07:19:09 +00:00
2018-09-05 11:01:21 +00:00
describe('claim', () => {
2018-08-30 07:19:09 +00:00
describe('Component vnClaimDetail', () => {
let $scope;
2018-08-30 07:19:09 +00:00
let controller;
let $httpBackend;
beforeEach(ngModule('claim'));
2018-08-30 07:19:09 +00:00
2020-03-16 10:58:14 +00:00
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => {
$scope = $rootScope.$new();
$scope.descriptor = {
show: () => {}
};
2018-08-30 07:19:09 +00:00
$httpBackend = _$httpBackend_;
2020-01-07 12:03:45 +00:00
$httpBackend.whenGET('Claims/ClaimBeginnings').respond({});
$httpBackend.whenGET(`Tickets/1/isEditable`).respond(true);
2020-06-17 05:25:05 +00:00
$httpBackend.whenGET(`Claims/2/isEditable`).respond(true);
2020-03-16 10:58:14 +00:00
const $element = angular.element('<vn-claim-detail></vn-claim-detail>');
controller = $componentController('vnClaimDetail', {$element, $scope});
2020-06-17 05:25:05 +00:00
controller.claim = {
ticketFk: 1,
id: 2}
;
2018-11-23 13:30:01 +00:00
controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}];
controller.salesClaimed = [{id: 1, sale: {}}];
controller.$.model = crudModel;
controller.$.addSales = {
2018-08-30 07:19:09 +00:00
hide: () => {},
show: () => {}
};
controller.$.editPopover = {
hide: () => {}
};
2020-03-16 10:58:14 +00:00
jest.spyOn(controller.aclService, 'hasAny').mockReturnValue(true);
2018-08-30 07:19:09 +00:00
}));
describe('openAddSalesDialog()', () => {
it('should call getClaimableFromTicket and $.addSales.show', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'getClaimableFromTicket');
jest.spyOn(controller.$.addSales, 'show');
2018-08-30 07:19:09 +00:00
controller.openAddSalesDialog();
expect(controller.getClaimableFromTicket).toHaveBeenCalledWith();
expect(controller.$.addSales.show).toHaveBeenCalledWith();
2018-08-30 07:19:09 +00:00
});
});
describe('getClaimableFromTicket()', () => {
it('should make a query and set salesToClaim', () => {
$httpBackend.expectGET(`Sales/getClaimableFromTicket?ticketFk=1`).respond(200, 1);
2018-08-30 07:19:09 +00:00
controller.getClaimableFromTicket();
$httpBackend.flush();
expect(controller.salesToClaim).toEqual(1);
});
});
2018-11-23 13:30:01 +00:00
describe('addClaimedSale(index)', () => {
2018-08-30 07:19:09 +00:00
it('should make a post and call refresh, hide and showSuccess', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.$.addSales, 'hide');
jest.spyOn(controller.$state, 'go');
$httpBackend.expectPOST(`ClaimBeginnings/`).respond({});
2018-08-30 07:19:09 +00:00
controller.addClaimedSale(1);
$httpBackend.flush();
expect(controller.$.addSales.hide).toHaveBeenCalledWith();
expect(controller.$state.go).toHaveBeenCalledWith('claim.card.development');
2018-08-30 07:19:09 +00:00
});
});
describe('deleteClaimedSale()', () => {
2018-08-30 07:19:09 +00:00
it('should make a delete and call refresh and showSuccess', () => {
controller.sale = {id: 1};
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.$.model, 'remove');
jest.spyOn(controller.vnApp, 'showSuccess');
2020-06-23 11:26:21 +00:00
$httpBackend.expectDELETE(`ClaimBeginnings/1`).respond('ok');
controller.deleteClaimedSale();
2018-08-30 07:19:09 +00:00
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
2018-08-30 07:19:09 +00:00
});
});
describe('setClaimedQuantity(id, claimedQuantity)', () => {
it('should make a patch and call refresh and showSuccess', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPATCH(`ClaimBeginnings/`).respond({});
2018-08-30 07:19:09 +00:00
controller.setClaimedQuantity(1, 1);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
2018-09-05 09:45:33 +00:00
describe('calculateTotals()', () => {
it('should set paidTotal and claimedTotal to 0 if salesClaimed has no data', () => {
controller.salesClaimed = [];
controller.calculateTotals();
expect(controller.paidTotal).toEqual(0);
expect(controller.claimedTotal).toEqual(0);
});
});
2019-06-18 05:57:41 +00:00
describe('updateDiscount()', () => {
it('should perform a query if the new discount differs from the claim discount', () => {
controller.saleClaimed = {sale: {
discount: 5,
id: 7,
ticketFk: 1,
price: 2,
quantity: 10}};
controller.newDiscount = 10;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller, 'calculateTotals');
jest.spyOn(controller, 'clearDiscount');
jest.spyOn(controller.$.editPopover, 'hide');
$httpBackend.when('POST', 'Tickets/1/updateDiscount').respond({});
controller.updateDiscount();
$httpBackend.flush();
expect(controller.calculateTotals).toHaveBeenCalledWith();
expect(controller.clearDiscount).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.$.editPopover.hide).toHaveBeenCalledWith();
});
});
2020-06-17 05:25:05 +00:00
describe('isTicketEditable()', () => {
it('should check if the ticket assigned to the claim is editable', () => {
controller.isTicketEditable();
2020-01-07 12:03:45 +00:00
$httpBackend.flush();
expect(controller.isEditable).toBeTruthy();
});
});
2018-08-30 07:19:09 +00:00
});
});