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

55 lines
1.9 KiB
JavaScript
Raw Normal View History

import './sale.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('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();
});
});
});
});