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

109 lines
4.4 KiB
JavaScript
Raw Normal View History

2018-09-05 09:34:23 +00:00
import './index.js';
describe('claim', () => {
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;
2018-09-24 10:12:36 +00:00
controller = $componentController('vnClaimAction', {$state: $state});
2018-09-05 09:34:23 +00:00
controller.claim = {ticketFk: 1};
controller.$.model = {refresh: () => {}};
controller.$.addSales = {
hide: () => {},
show: () => {}
};
}));
describe('openAddSalesDialog()', () => {
it('should call getClaimableFromTicket and $.addSales.show', () => {
controller.$ = {addSales: {show: () => {}}};
2018-09-24 10:12:36 +00:00
spyOn(controller, 'getClaimedSales');
2018-09-05 09:34:23 +00:00
spyOn(controller.$.addSales, 'show');
controller.openAddSalesDialog();
2018-09-24 10:12:36 +00:00
expect(controller.getClaimedSales).toHaveBeenCalledWith();
2018-09-05 09:34:23 +00:00
expect(controller.$.addSales.show).toHaveBeenCalledWith();
});
});
2018-09-24 10:12:36 +00:00
describe('getClaimedSales()', () => {
2018-09-05 09:34:23 +00:00
it('should make a query and set salesToClaim', () => {
2018-09-24 10:12:36 +00:00
controller.claim.id = 1;
$httpBackend.expectGET(`/claim/api/ClaimBeginnings/1`).respond(200, 1);
controller.getClaimedSales();
2018-09-05 09:34:23 +00:00
$httpBackend.flush();
2018-09-24 10:12:36 +00:00
expect(controller.claimedSales).toEqual(1);
2018-09-05 09:34:23 +00:00
});
});
describe('addClaimedSale(saleFk)', () => {
it('should make a post and call refresh, hide and showSuccess', () => {
spyOn(controller.$.model, 'refresh');
spyOn(controller.$.addSales, 'hide');
spyOn(controller.vnApp, 'showSuccess');
2018-09-24 10:12:36 +00:00
$httpBackend.expectPOST(`claim/api/ClaimEnds/`).respond({});
2018-09-05 09:34:23 +00:00
controller.addClaimedSale(1);
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.$.addSales.hide).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
describe('deleteClaimedSale(id)', () => {
it('should make a delete and call refresh and showSuccess', () => {
spyOn(controller.$.model, 'refresh');
spyOn(controller.vnApp, 'showSuccess');
2018-09-24 10:12:36 +00:00
$httpBackend.expectDELETE(`claim/api/ClaimEnds/1`).respond({});
2018-09-05 09:34:23 +00:00
controller.deleteClaimedSale(1);
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
2018-09-24 10:12:36 +00:00
describe('setClaimDestination(id, claimDestinationFk)', () => {
2018-09-05 09:34:23 +00:00
it('should make a patch and call refresh and showSuccess', () => {
spyOn(controller.$.model, 'refresh');
spyOn(controller.vnApp, 'showSuccess');
2018-09-24 10:12:36 +00:00
$httpBackend.expectPATCH(`claim/api/ClaimEnds/`).respond({});
controller.setClaimDestination(1, 1);
2018-09-05 09:34:23 +00:00
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
2018-09-24 10:12:36 +00:00
describe('calculateTotals()', () => {
it('should calculate the total price of the items claimed', () => {
controller.salesClaimed = [
{sale: {quantity: 5, price: 2, discount: 0}},
{sale: {quantity: 10, price: 2, discount: 0}},
{sale: {quantity: 10, price: 2, discount: 0}}
];
controller.calculateTotals();
expect(controller.claimedTotal).toEqual(50);
});
});
2018-09-05 09:34:23 +00:00
});
});