refactor in all client specs to next describes accordingly

This commit is contained in:
Carlos 2017-09-04 15:06:43 +02:00
parent 0f6e81ce83
commit 352e68ed58
10 changed files with 281 additions and 257 deletions

View File

@ -1,23 +1,25 @@
import './address-create.js';
describe('Component vnAddressCreate', () => {
let $componentController;
let $state;
describe('Client', () => {
describe('Component vnAddressCreate', () => {
let $componentController;
let $state;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_) => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.id = '1234';
}));
beforeEach(angular.mock.inject((_$componentController_, _$state_) => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.id = '1234';
}));
it('should define and set address property', () => {
let controller = $componentController('vnAddressCreate', {$state: $state});
expect(controller.address).toBeDefined();
expect(controller.address.clientFk).toBe(1234);
expect(controller.address.enabled).toBe(true);
it('should define and set address property', () => {
let controller = $componentController('vnAddressCreate', {$state: $state});
expect(controller.address).toBeDefined();
expect(controller.address.clientFk).toBe(1234);
expect(controller.address.enabled).toBe(true);
});
});
});

View File

@ -1,21 +1,23 @@
import './address-edit.js';
describe('Component vnAddressEdit', () => {
let $componentController;
let $state;
describe('Client', () => {
describe('Component vnAddressEdit', () => {
let $componentController;
let $state;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_) => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.addressId = '1234';
}));
beforeEach(angular.mock.inject((_$componentController_, _$state_) => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.addressId = '1234';
}));
it('should define and set address property', () => {
let controller = $componentController('vnAddressEdit', {$state: $state});
expect(controller.address.id).toBe(1234);
it('should define and set address property', () => {
let controller = $componentController('vnAddressEdit', {$state: $state});
expect(controller.address.id).toBe(1234);
});
});
});

View File

@ -1,80 +1,82 @@
import './billing-data.js';
describe('Component vnClientBillingData', () => {
let $componentController;
let $httpBackend;
let $scope;
describe('Client', () => {
describe('Component vnClientBillingData', () => {
let $componentController;
let $httpBackend;
let $scope;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve());
$scope.watcher = {submit};
let show = jasmine.createSpy('show');
$scope.sendMail = {show};
}));
describe('copyData()', () => {
it(`should define billData using client's data`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {
credit: 1000000000000,
creditInsurance: null,
discount: 99,
dueDay: 0,
iban: null,
payMethodFk: 1
};
controller.billData = {};
controller.copyData(controller.client);
expect(controller.billData).toEqual(controller.client);
beforeEach(() => {
angular.mock.module('client');
});
});
describe('submit()', () => {
it(`should call submit() on the watcher then receive a callback`, done => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
spyOn(controller, 'checkPaymentChanges');
controller.submit()
.then(() => {
expect(controller.$.watcher.submit).toHaveBeenCalled();
expect(controller.checkPaymentChanges).toHaveBeenCalled();
done();
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve());
$scope.watcher = {submit};
let show = jasmine.createSpy('show');
$scope.sendMail = {show};
}));
describe('copyData()', () => {
it(`should define billData using client's data`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {
credit: 1000000000000,
creditInsurance: null,
discount: 99,
dueDay: 0,
iban: null,
payMethodFk: 1
};
controller.billData = {};
controller.copyData(controller.client);
expect(controller.billData).toEqual(controller.client);
});
});
describe('submit()', () => {
it(`should call submit() on the watcher then receive a callback`, done => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
spyOn(controller, 'checkPaymentChanges');
controller.submit()
.then(() => {
expect(controller.$.watcher.submit).toHaveBeenCalled();
expect(controller.checkPaymentChanges).toHaveBeenCalled();
done();
});
});
});
describe('checkPaymentChanges()', () => {
it(`should not call sendMail.show() if there are no changes on billing data`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Silver Surfer'};
controller.checkPaymentChanges();
expect(controller.$.sendMail.show).not.toHaveBeenCalled();
});
it(`should call sendMail.show() if there are changes on billing data object`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Spider-Man'};
controller.checkPaymentChanges();
expect(controller.$.sendMail.show).toHaveBeenCalled();
});
});
describe('returnDialog()', () => {
it('should request to send notification email', () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {id: '123'};
$httpBackend.when('POST', `/mailer/manuscript/${controller.client.id}/payment-update`).respond('done');
$httpBackend.expectPOST(`/mailer/manuscript/${controller.client.id}/payment-update`);
controller.returnDialog('ACCEPT');
$httpBackend.flush();
});
});
});
describe('checkPaymentChanges()', () => {
it(`should not call sendMail.show() if there are no changes on billing data`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Silver Surfer'};
controller.checkPaymentChanges();
expect(controller.$.sendMail.show).not.toHaveBeenCalled();
});
it(`should call sendMail.show() if there are changes on billing data object`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Spider-Man'};
controller.checkPaymentChanges();
expect(controller.$.sendMail.show).toHaveBeenCalled();
});
});
describe('returnDialog()', () => {
it('should request to send notification email', () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {id: '123'};
$httpBackend.when('POST', `/mailer/manuscript/${controller.client.id}/payment-update`).respond('done');
$httpBackend.expectPOST(`/mailer/manuscript/${controller.client.id}/payment-update`);
controller.returnDialog('ACCEPT');
$httpBackend.flush();
});
});
});

View File

@ -1,21 +1,23 @@
import './card.js';
describe('Component vnClientCard', () => {
let $componentController;
let $scope;
describe('Client', () => {
describe('Component vnClientCard', () => {
let $componentController;
let $scope;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope;
}));
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope;
}));
it('should define and set client property to null in the module instance', () => {
let controller = $componentController('vnClientCard', {$scope: $scope});
expect(controller.client).toBeDefined();
expect(controller.client).toBe(null);
it('should define and set client property to null in the module instance', () => {
let controller = $componentController('vnClientCard', {$scope: $scope});
expect(controller.client).toBeDefined();
expect(controller.client).toBe(null);
});
});
});

View File

@ -1,42 +1,44 @@
import './create.js';
describe('Component vnClientCreate', () => {
let $componentController;
let $scope;
let $state;
describe('Client', () => {
describe('Component vnClientCreate', () => {
let $componentController;
let $scope;
let $state;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$state = _$state_;
$scope.watcher = {
submit: () => {
return {
then: callback => {
callback({data: {id: '1234'}});
}
};
}
};
}));
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => {
$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', () => {
let controller = $componentController('vnClientCreate', {$scope: $scope});
expect(controller.$).toBe($scope);
expect(controller.$state).toBe($state);
expect(controller.client.active).toBe(true);
});
describe('onSubmit()', () => {
it(`should call submit() on the watcher then expect a callback`, () => {
it('should define and set scope, state and client properties', () => {
let controller = $componentController('vnClientCreate', {$scope: $scope});
spyOn($state, 'go');
controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.basicData', {id: '1234'});
expect(controller.$).toBe($scope);
expect(controller.$state).toBe($state);
expect(controller.client.active).toBe(true);
});
describe('onSubmit()', () => {
it(`should call submit() on the watcher then expect a callback`, () => {
let controller = $componentController('vnClientCreate', {$scope: $scope});
spyOn($state, 'go');
controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.basicData', {id: '1234'});
});
});
});
});

View File

@ -1,33 +1,35 @@
import './index.js';
describe('Component vnClientIndex', () => {
let $componentController;
describe('Client', () => {
describe('Component vnClientIndex', () => {
let $componentController;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
}));
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
}));
it('should define and set model property as an empty object', () => {
let controller = $componentController('vnClientIndex');
expect(controller.model).toEqual({});
});
describe('search()', () => {
it(`should set model's search to the search input`, () => {
it('should define and set model property as an empty object', () => {
let controller = $componentController('vnClientIndex');
controller.model.search = 'batman';
let index = {
filter: {},
accept: () => {
return 'accepted';
}
};
controller.search(index);
expect(index.filter.search).toBe('batman');
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');
});
});
});
});

View File

@ -1,22 +1,24 @@
import './note-create.js';
describe('Component vnNoteCreate', () => {
let $componentController;
let $state;
describe('Client', () => {
describe('Component vnNoteCreate', () => {
let $componentController;
let $state;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_) => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.id = '1234';
}));
beforeEach(angular.mock.inject((_$componentController_, _$state_) => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.id = '1234';
}));
it('should define clientFk using $state.params.id', () => {
let controller = $componentController('vnNoteCreate', {$state: $state});
expect(controller.note.clientFk).toBe(1234);
expect(controller.note.client).toBe(undefined);
it('should define clientFk using $state.params.id', () => {
let controller = $componentController('vnNoteCreate', {$state: $state});
expect(controller.note.clientFk).toBe(1234);
expect(controller.note.client).toBe(undefined);
});
});
});

View File

@ -1,51 +1,53 @@
import './notes.js';
describe('Component vnClientNotes', () => {
let $componentController;
let $state;
let $httpBackend;
describe('Client', () => {
describe('Component vnClientNotes', () => {
let $componentController;
let $state;
let $httpBackend;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
$componentController = _$componentController_;
$state = _$state_;
$httpBackend = _$httpBackend_;
}));
describe('$onChanges()', () => {
it(`should call getObservation() with the client id`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {
id: 1234
};
spyOn(controller, 'getObservation').and.returnValue();
controller.$onChanges();
expect(controller.getObservation).toHaveBeenCalledWith(1234);
beforeEach(() => {
angular.mock.module('client');
});
});
describe('$getObservation()', () => {
it(`should request to GET the client notes`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {id: '1234'};
let json = JSON.stringify({where: {clientFk: '1234'}, order: 'created DESC'});
$httpBackend.when('GET', `/client/api/clientObservations?filter=${json}`).respond('ok');
$httpBackend.expectGET(`/client/api/clientObservations?filter=${json}`, {Accept: 'application/json, text/plain, */*'});
controller.getObservation();
$httpBackend.flush();
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
$componentController = _$componentController_;
$state = _$state_;
$httpBackend = _$httpBackend_;
}));
describe('$onChanges()', () => {
it(`should call getObservation() with the client id`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {
id: 1234
};
spyOn(controller, 'getObservation').and.returnValue();
controller.$onChanges();
expect(controller.getObservation).toHaveBeenCalledWith(1234);
});
});
});
describe('$newObservation()', () => {
it(`should redirect the user to the newObservation view`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {id: '1234'};
spyOn(controller.$state, 'go');
controller.newObservation();
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.notes.create', Object({id: '1234'}));
describe('$getObservation()', () => {
it(`should request to GET the client notes`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {id: '1234'};
let json = JSON.stringify({where: {clientFk: '1234'}, order: 'created DESC'});
$httpBackend.when('GET', `/client/api/clientObservations?filter=${json}`).respond('ok');
$httpBackend.expectGET(`/client/api/clientObservations?filter=${json}`, {Accept: 'application/json, text/plain, */*'});
controller.getObservation();
$httpBackend.flush();
});
});
describe('$newObservation()', () => {
it(`should redirect the user to the newObservation view`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {id: '1234'};
spyOn(controller.$state, 'go');
controller.newObservation();
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.notes.create', Object({id: '1234'}));
});
});
});
});

View File

@ -1,37 +1,39 @@
import './search-panel.js';
describe('Component vnClientSearchPanel', () => {
let $componentController;
let $window;
describe('Client', () => {
describe('Component vnClientSearchPanel', () => {
let $componentController;
let $window;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$window_) => {
$componentController = _$componentController_;
$window = _$window_;
}));
describe('onSearch()', () => {
it(`should call setStorageValue() and onSubmit()`, () => {
let controller = $componentController('vnClientSearchPanel', {$window: $window});
spyOn(controller, 'setStorageValue');
spyOn(controller, 'onSubmit');
controller.setStorageValue();
controller.onSubmit();
expect(controller.setStorageValue).toHaveBeenCalled();
expect(controller.onSubmit).toHaveBeenCalled();
beforeEach(() => {
angular.mock.module('client');
});
});
describe('$onChanges()', () => {
it(`should set filter properties using the search values`, () => {
let controller = $componentController('vnClientSearchPanel', {$window: $window});
expect(controller.filter).not.toBeDefined();
spyOn(JSON, 'parse').and.returnValue({data: 'data'});
controller.$onChanges();
expect(controller.filter).toBe(JSON.parse({data: 'data'}));
beforeEach(angular.mock.inject((_$componentController_, _$window_) => {
$componentController = _$componentController_;
$window = _$window_;
}));
describe('onSearch()', () => {
it(`should call setStorageValue() and onSubmit()`, () => {
let controller = $componentController('vnClientSearchPanel', {$window: $window});
spyOn(controller, 'setStorageValue');
spyOn(controller, 'onSubmit');
controller.setStorageValue();
controller.onSubmit();
expect(controller.setStorageValue).toHaveBeenCalled();
expect(controller.onSubmit).toHaveBeenCalled();
});
});
describe('$onChanges()', () => {
it(`should set filter properties using the search values`, () => {
let controller = $componentController('vnClientSearchPanel', {$window: $window});
expect(controller.filter).not.toBeDefined();
spyOn(JSON, 'parse').and.returnValue({data: 'data'});
controller.$onChanges();
expect(controller.filter).toBe(JSON.parse({data: 'data'}));
});
});
});
});

View File

@ -0,0 +1,6 @@
import './autocomplete.js';
describe('Core', () => {
describe('Component mdlUpdate', () => {
});
});