2019-06-06 07:34:36 +00:00
|
|
|
import '../editDiscount.js';
|
2018-06-28 13:21:04 +00:00
|
|
|
|
|
|
|
describe('Ticket', () => {
|
|
|
|
describe('Component vnTicketSaleEditDiscount', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $state;
|
|
|
|
let $scope;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('ticket', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2018-06-28 13:21:04 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, $rootScope) => {
|
2018-06-28 13:21:04 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.index = {model: {instances: [{id: 1}, {id: 2}]}, accept: () => {
|
|
|
|
return {
|
|
|
|
then: () => {}
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
$state = _$state_;
|
2019-06-05 11:39:15 +00:00
|
|
|
$state.params.id = 11;
|
2018-12-22 10:59:26 +00:00
|
|
|
controller = $componentController('vnTicketSaleEditDiscount', {$scope, $state});
|
2019-06-05 11:39:15 +00:00
|
|
|
controller._edit = [{id: 3}];
|
2019-02-15 12:13:23 +00:00
|
|
|
controller.onHide = () => {};
|
2018-06-28 13:21:04 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-06-05 11:39:15 +00:00
|
|
|
$httpBackend.expectPOST(`/api/Tickets/11/updateDiscount`).respond();
|
2018-06-28 13:21:04 +00:00
|
|
|
controller.updateDiscount();
|
|
|
|
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
|
2019-06-05 11:39:15 +00:00
|
|
|
it(`should throw if there's no changes on discount and it isn't bulk`, () => {
|
2018-06-28 13:21:04 +00:00
|
|
|
controller.bulk = false;
|
2019-06-05 11:39:15 +00:00
|
|
|
controller.newDiscount = 15;
|
|
|
|
controller.edit = [{discount: 15}];
|
2018-12-22 10:59:26 +00:00
|
|
|
spyOn(controller.vnApp, 'showError');
|
2018-06-28 13:21:04 +00:00
|
|
|
controller.updateDiscount();
|
|
|
|
|
2019-05-29 09:11:54 +00:00
|
|
|
expect(controller.vnApp.showError).toHaveBeenCalledWith('There are no changes to save');
|
2018-06-28 13:21:04 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-06 07:34:36 +00:00
|
|
|
describe('clearDiscount()', () => {
|
2018-06-28 13:21:04 +00:00
|
|
|
it('should set newDiscount to null', () => {
|
2019-06-06 07:34:36 +00:00
|
|
|
controller.clearDiscount();
|
2018-06-28 13:21:04 +00:00
|
|
|
|
|
|
|
expect(controller.newDiscount).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|