unit test for billing-data create and index

This commit is contained in:
Carlos 2017-08-31 19:15:17 +02:00
parent 4c9383038f
commit c2e0a081e2
3 changed files with 84 additions and 3 deletions

View File

@ -13,11 +13,9 @@ describe('Component vnClientBillingData', () => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
// should add instanciate of actual watcher instead of submit() spy usage.
let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve());
// should add instanciate of actual sendMail instead of show() spy usage.
let show = jasmine.createSpy('show');
$scope.watcher = {submit};
let show = jasmine.createSpy('show');
$scope.sendMail = {show};
}));

View File

@ -0,0 +1,49 @@
import './create.js';
describe('Component vnClientCreate', () => {
let $componentController;
let $httpBackend;
let $scope;
let $state;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject(function(_$componentController_, $rootScope, _$state_, _$httpBackend_) {
$httpBackend = _$httpBackend_;
$componentController = _$componentController_;
$scope = $rootScope.$new();
$state = _$state_;
$scope.watcher = {
submit: () => {
return {
then: callback => {
callback({data: {id: '1234'}});
}
};
}
};
}));
it('should define and set scope, state and client properties', function() {
let controller = $componentController('vnClientCreate', {$scope: $scope, $state: $state});
expect(controller.$).toBe($scope);
expect(controller.$state).toBe($state);
expect(controller.client.active).toBe(true);
});
describe('onSubmit()', () => {
// spec broken due to callback acting a bit weirdo.
// it(`should call submit() on the watcher then expect a callback`, done => {
// let controller = $componentController('vnClientCreate', {$scope: $scope});
// spyOn($state, 'go').and.callFake(json => {
// return 1001;
// });
// controller.onSubmit();
// expect(controller.$.watcher.submit).toHaveBeenCalled();
// expect(controller.$state.go).toHaveBeenCalled();
// });
});
});

View File

@ -0,0 +1,34 @@
import './index.js';
describe('Component vnClientIndex', () => {
let $componentController;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject(function(_$componentController_, $rootScope, _$httpBackend_) {
$componentController = _$componentController_;
}));
it('should define and set model property as an empty object', () => {
let controller = $componentController('vnClientIndex');
expect(controller.model).toBeDefined();
expect(controller.model).toEqual({});
});
describe('search()', () => {
it(`should set model's search to the search input`, () => {
let controller = $componentController('vnClientIndex');
controller.model.search = 'batman';
let index = {
filter: {},
accept: () => {
return 'accepted';
}
};
controller.search(index);
expect(index.filter.search).toBe('batman');
});
});
});