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

97 lines
3.9 KiB
JavaScript

import './index.js';
import crudModel from 'core/mocks/crud-model';
describe('claim', () => {
describe('Component vnClaimDetail', () => {
let controller;
let $httpBackend;
let $state;
let aclService;
beforeEach(ngModule('claim'));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', 'claim/api/Claims/ClaimBeginnings').respond({});
$state = _$state_;
aclService = {hasAny: () => true};
controller = $componentController('vnClaimDetail', {$state, aclService});
controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}];
controller.salesClaimed = [{id: 1, sale: {}}];
controller.claim = {ticketFk: 1};
controller.$scope.model = crudModel;
controller.$scope.addSales = {
hide: () => {},
show: () => {}
};
}));
describe('openAddSalesDialog()', () => {
it('should call getClaimableFromTicket and $.addSales.show', () => {
controller.$ = {addSales: {show: () => {}}};
spyOn(controller, 'getClaimableFromTicket');
spyOn(controller.$scope.addSales, 'show');
controller.openAddSalesDialog();
expect(controller.getClaimableFromTicket).toHaveBeenCalledWith();
expect(controller.$scope.addSales.show).toHaveBeenCalledWith();
});
});
describe('getClaimableFromTicket()', () => {
it('should make a query and set salesToClaim', () => {
$httpBackend.expectGET(`/api/Sales/getClaimableFromTicket?ticketFk=1`).respond(200, 1);
controller.getClaimableFromTicket();
$httpBackend.flush();
expect(controller.salesToClaim).toEqual(1);
});
});
describe('addClaimedSale(index)', () => {
it('should make a post and call refresh, hide and showSuccess', () => {
spyOn(controller.$scope.addSales, 'hide');
spyOn(controller.$state, 'go');
$httpBackend.expectPOST(`claim/api/ClaimBeginnings/`).respond({});
controller.addClaimedSale(1);
$httpBackend.flush();
expect(controller.$scope.addSales.hide).toHaveBeenCalledWith();
expect(controller.$state.go).toHaveBeenCalledWith('claim.card.development');
});
});
describe('deleteClaimedSale(index)', () => {
it('should make a delete and call refresh and showSuccess', () => {
spyOn(controller.$scope.model, 'remove');
$httpBackend.expectDELETE(`claim/api/ClaimBeginnings/1`).respond({});
controller.deleteClaimedSale(0);
$httpBackend.flush();
expect(controller.$scope.model.remove).toHaveBeenCalledWith(0);
});
});
describe('setClaimedQuantity(id, claimedQuantity)', () => {
it('should make a patch and call refresh and showSuccess', () => {
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPATCH(`claim/api/ClaimBeginnings/`).respond({});
controller.setClaimedQuantity(1, 1);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
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);
});
});
});
});