salix/client/ticket/src/sale/editDiscount.spec.js

90 lines
3.2 KiB
JavaScript
Raw Normal View History

import './editDiscount.js';
describe('Ticket', () => {
describe('Component vnTicketSaleEditDiscount', () => {
let $componentController;
let controller;
let $httpBackend;
let $state;
let $scope;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_, $rootScope) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
$scope.index = {model: {instances: [{id: 1}, {id: 2}]}, accept: () => {
return {
then: () => {}
};
}};
$state = _$state_;
$state.params.id = 1;
controller = $componentController('vnTicketSaleEditDiscount', {$scope: $scope, $state: $state});
controller._edit = [{id: 3, discount: 15}];
controller.hide = () => {};
}));
describe('edit() setter', () => {
it('should set _edit value and call setNewDiscount', () => {
spyOn(controller, 'setNewDiscount');
controller.edit = {id: 1};
expect(controller.edit).toEqual({id: 1});
expect(controller.setNewDiscount).toHaveBeenCalledWith();
});
});
describe('bulk() setter', () => {
it('should set _bulk value and call setNewDiscount', () => {
spyOn(controller, 'setNewDiscount');
controller.bulk = true;
expect(controller.bulk).toEqual(true);
expect(controller.setNewDiscount).toHaveBeenCalledWith();
});
});
describe('setNewDiscount()', () => {
it('should set NewDiscount to edit[0].discount value if it doesnt exists', () => {
controller.edit = [{discount: 1}];
controller.setNewDiscount();
expect(controller.newDiscount).toEqual(1);
});
});
describe('updateDiscount()', () => {
it('should make a query if the discount value has been modified or the bulk value is true', () => {
controller.bulk = true;
controller.newDiscount = 15;
$httpBackend.expectPOST(`/ticket/api/Sales/updateDiscount`).respond();
controller.updateDiscount();
$httpBackend.flush();
});
it('should call vnApp.showError if the discount value hasnt has been modified and the bulk value is false', () => {
controller.bulk = false;
spyOn(controller.vnApp, "showError");
controller.updateDiscount();
expect(controller.vnApp.showError).toHaveBeenCalledWith('There is no changes to save');
});
});
describe('clear()', () => {
it('should set newDiscount to null', () => {
controller.clear();
expect(controller.newDiscount).toEqual(null);
});
});
});
});