salix/client/claim/src/detail/index.spec.js

106 lines
4.3 KiB
JavaScript
Raw Normal View History

2018-08-30 07:19:09 +00:00
import './index.js';
2018-11-23 13:30:01 +00:00
import {crudModel} from '../../../helpers/crudModelHelper';
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 $componentController;
let controller;
let $httpBackend;
let $state;
beforeEach(() => {
angular.mock.module('claim');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_, $rootScope) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$httpBackend.when('GET', 'claim/api/Claims/ClaimBeginnings').respond({});
$state = _$state_;
$state.params.id = 1;
controller = $componentController('vnClaimDetail', {$state: $state});
2018-11-23 13:30:01 +00:00
controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}];
controller.salesClaimed = [{id: 1}];
2018-08-30 07:19:09 +00:00
controller.claim = {ticketFk: 1};
2018-11-23 13:30:01 +00:00
controller.$.model = crudModel;
2018-08-30 07:19:09 +00:00
controller.$.addSales = {
hide: () => {},
show: () => {}
};
}));
describe('openAddSalesDialog()', () => {
it('should call getClaimableFromTicket and $.addSales.show', () => {
controller.$ = {addSales: {show: () => {}}};
spyOn(controller, 'getClaimableFromTicket');
spyOn(controller.$.addSales, 'show');
controller.openAddSalesDialog();
expect(controller.getClaimableFromTicket).toHaveBeenCalledWith();
expect(controller.$.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);
});
});
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', () => {
spyOn(controller.$.model, 'refresh');
spyOn(controller.$.addSales, 'hide');
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPOST(`claim/api/ClaimBeginnings/`).respond({});
controller.addClaimedSale(1);
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.$.addSales.hide).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
2018-11-23 13:30:01 +00:00
describe('deleteClaimedSale(index)', () => {
2018-08-30 07:19:09 +00:00
it('should make a delete and call refresh and showSuccess', () => {
2018-11-23 13:30:01 +00:00
spyOn(controller.$.model, 'remove');
2018-08-30 07:19:09 +00:00
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectDELETE(`claim/api/ClaimBeginnings/1`).respond({});
2018-11-23 13:30:01 +00:00
controller.deleteClaimedSale(0);
2018-08-30 07:19:09 +00:00
$httpBackend.flush();
2018-11-23 13:30:01 +00:00
expect(controller.$.model.remove).toHaveBeenCalledWith(0);
2018-08-30 07:19:09 +00:00
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
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!');
});
});
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);
});
});
2018-08-30 07:19:09 +00:00
});
});