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

83 lines
3.1 KiB
JavaScript
Raw Normal View History

import './index.js';
describe('Ticket', () => {
describe('Component vnTicketSale', () => {
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_;
$scope = $rootScope.$new();
$scope.index = {model: {instances: [{id: 1}, {id: 2}]}, accept: () => {
return {
then: () => {}
};
}};
$state = _$state_;
$state.params.id = 1;
controller = $componentController('vnTicketSale', {$scope: $scope}, {$state: $state});
}));
describe('isChecked() setter/getter', () => {
it('should set isChecked value to true when one of the instances has the value checked to true', () => {
let lines = [
{checked: false},
{checked: true}
];
$scope.index.model.instances = lines;
expect(controller.isChecked).toBeTruthy();
});
});
describe('onStateOkClick()', () => {
it('should perform a get and then call a function', () => {
let filter = {where: {code: "OK"}, fields: ["id"]};
filter = encodeURIComponent(JSON.stringify(filter));
let res = [{id: 3}];
spyOn(controller, 'onStateChange');
$httpBackend.whenGET(`/ticket/api/States?filter=${filter}`).respond(res);
$httpBackend.expectGET(`/ticket/api/States?filter=${filter}`);
controller.onStateOkClick();
$httpBackend.flush();
expect(controller.onStateChange).toHaveBeenCalledWith(3);
});
});
describe('onStateChange()', () => {
it('should perform a post and then call a function', () => {
$httpBackend.expectPOST(`/ticket/api/TicketTrackings`).respond();
controller.card = {reload: () => {}};
controller.onStateChange(3);
$httpBackend.flush();
});
});
describe('onRemoveLinesClick()', () => {
it('should remove an object of the model if has the attribute cheched true', () => {
$scope.index.model.instances = [{id: 1, checked: true}, {id: 2, checked: false}];
controller.onRemoveLinesClick();
expect($scope.index.model.instances).toEqual([{id: 2, checked: false}]);
});
it('should make a post if an object the model has the attribute cheched true', () => {
$scope.index.model.instances = [{id: 1, checked: false}, {id: 2, checked: false}];
$httpBackend.expectPOST(`/ticket/api/Sales/crudSale`).respond();
controller.onRemoveLinesClick();
$httpBackend.flush();
});
});
});
});