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', () => {
|
2019-09-30 12:49:04 +00:00
|
|
|
let $scope;
|
2018-08-30 07:19:09 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('claim'));
|
2018-08-30 07:19:09 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
2019-09-30 12:49:04 +00:00
|
|
|
$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);
|
2023-03-06 07:14:26 +00:00
|
|
|
$httpBackend.whenGET(`ClaimStates/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}];
|
2018-12-20 13:37:29 +00:00
|
|
|
controller.salesClaimed = [{id: 1, sale: {}}];
|
2019-06-12 06:19:02 +00:00
|
|
|
controller.$.model = crudModel;
|
|
|
|
controller.$.addSales = {
|
2018-08-30 07:19:09 +00:00
|
|
|
hide: () => {},
|
|
|
|
show: () => {}
|
|
|
|
};
|
2019-12-13 07:01:13 +00:00
|
|
|
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();
|
2019-06-12 06:19:02 +00:00
|
|
|
expect(controller.$.addSales.show).toHaveBeenCalledWith();
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getClaimableFromTicket()', () => {
|
|
|
|
it('should make a query and set salesToClaim', () => {
|
2019-10-24 22:53:53 +00:00
|
|
|
$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');
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.expectPOST(`ClaimBeginnings/`).respond({});
|
2018-08-30 07:19:09 +00:00
|
|
|
controller.addClaimedSale(1);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2019-06-12 06:19:02 +00:00
|
|
|
expect(controller.$.addSales.hide).toHaveBeenCalledWith();
|
2019-04-08 07:01:10 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('claim.card.development');
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-18 08:10:42 +00:00
|
|
|
describe('deleteClaimedSale()', () => {
|
2018-08-30 07:19:09 +00:00
|
|
|
it('should make a delete and call refresh and showSuccess', () => {
|
2021-02-02 08:08:11 +00:00
|
|
|
const claimedIndex = 1;
|
|
|
|
controller.claimedIndex = claimedIndex;
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.model, 'remove');
|
2021-02-02 08:08:11 +00:00
|
|
|
jest.spyOn(controller.$.model, 'save');
|
2020-06-18 08:10:42 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2021-02-02 08:08:11 +00:00
|
|
|
|
2020-06-23 11:26:21 +00:00
|
|
|
controller.deleteClaimedSale();
|
2018-08-30 07:19:09 +00:00
|
|
|
|
2021-02-02 08:08:11 +00:00
|
|
|
expect(controller.$.model.remove).toHaveBeenCalledWith(claimedIndex);
|
|
|
|
expect(controller.$.model.save).toHaveBeenCalledWith();
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setClaimedQuantity(id, claimedQuantity)', () => {
|
|
|
|
it('should make a patch and call refresh and showSuccess', () => {
|
2023-03-08 06:47:25 +00:00
|
|
|
const id = 1;
|
|
|
|
const claimedQuantity = 1;
|
|
|
|
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2023-03-08 06:47:25 +00:00
|
|
|
$httpBackend.expectPATCH(`ClaimBeginnings/${id}`).respond({});
|
|
|
|
controller.setClaimedQuantity(id, claimedQuantity);
|
2018-08-30 07:19:09 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2018-08-30 07:19:09 +00:00
|
|
|
});
|
|
|
|
});
|
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-12 06:19:02 +00:00
|
|
|
|
2019-06-18 05:57:41 +00:00
|
|
|
describe('updateDiscount()', () => {
|
2019-06-12 06:19:02 +00:00
|
|
|
it('should perform a query if the new discount differs from the claim discount', () => {
|
2019-06-17 10:13:05 +00:00
|
|
|
controller.saleClaimed = {sale: {
|
|
|
|
discount: 5,
|
|
|
|
id: 7,
|
|
|
|
ticketFk: 1,
|
|
|
|
price: 2,
|
|
|
|
quantity: 10}};
|
2019-06-12 06:19:02 +00:00
|
|
|
controller.newDiscount = 10;
|
2019-06-17 10:13:05 +00:00
|
|
|
|
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');
|
2019-06-12 06:19:02 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('POST', 'Tickets/1/updateDiscount').respond({});
|
2019-06-12 06:19:02 +00:00
|
|
|
controller.updateDiscount();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2019-12-13 07:01:13 +00:00
|
|
|
expect(controller.calculateTotals).toHaveBeenCalledWith();
|
2019-06-12 06:19:02 +00:00
|
|
|
expect(controller.clearDiscount).toHaveBeenCalledWith();
|
2020-07-23 15:10:07 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
2019-12-13 07:01:13 +00:00
|
|
|
expect(controller.$.editPopover.hide).toHaveBeenCalledWith();
|
2019-06-12 06:19:02 +00:00
|
|
|
});
|
|
|
|
});
|
2019-09-30 12:49:04 +00:00
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|