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

View File

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

View File

@ -1,80 +1,82 @@
import './billing-data.js'; import './billing-data.js';
describe('Component vnClientBillingData', () => { describe('Client', () => {
let $componentController; describe('Component vnClientBillingData', () => {
let $httpBackend; let $componentController;
let $scope; let $httpBackend;
let $scope;
beforeEach(() => { beforeEach(() => {
angular.mock.module('client'); 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);
}); });
});
describe('submit()', () => { beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
it(`should call submit() on the watcher then receive a callback`, done => { $componentController = _$componentController_;
let controller = $componentController('vnClientBillingData', {$scope: $scope}); $httpBackend = _$httpBackend_;
spyOn(controller, 'checkPaymentChanges'); $scope = $rootScope.$new();
controller.submit() let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve());
.then(() => { $scope.watcher = {submit};
expect(controller.$.watcher.submit).toHaveBeenCalled(); let show = jasmine.createSpy('show');
expect(controller.checkPaymentChanges).toHaveBeenCalled(); $scope.sendMail = {show};
done(); }));
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'; import './card.js';
describe('Component vnClientCard', () => { describe('Client', () => {
let $componentController; describe('Component vnClientCard', () => {
let $scope; let $componentController;
let $scope;
beforeEach(() => { beforeEach(() => {
angular.mock.module('client'); angular.mock.module('client');
}); });
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_; $componentController = _$componentController_;
$scope = $rootScope; $scope = $rootScope;
})); }));
it('should define and set client property to null in the module instance', () => { it('should define and set client property to null in the module instance', () => {
let controller = $componentController('vnClientCard', {$scope: $scope}); let controller = $componentController('vnClientCard', {$scope: $scope});
expect(controller.client).toBeDefined(); expect(controller.client).toBeDefined();
expect(controller.client).toBe(null); expect(controller.client).toBe(null);
});
}); });
}); });

View File

@ -1,42 +1,44 @@
import './create.js'; import './create.js';
describe('Component vnClientCreate', () => { describe('Client', () => {
let $componentController; describe('Component vnClientCreate', () => {
let $scope; let $componentController;
let $state; let $scope;
let $state;
beforeEach(() => { beforeEach(() => {
angular.mock.module('client'); angular.mock.module('client');
}); });
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => { beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => {
$componentController = _$componentController_; $componentController = _$componentController_;
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$state = _$state_; $state = _$state_;
$scope.watcher = { $scope.watcher = {
submit: () => { submit: () => {
return { return {
then: callback => { then: callback => {
callback({data: {id: '1234'}}); callback({data: {id: '1234'}});
} }
}; };
} }
}; };
})); }));
it('should define and set scope, state and client properties', () => { 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`, () => {
let controller = $componentController('vnClientCreate', {$scope: $scope}); let controller = $componentController('vnClientCreate', {$scope: $scope});
spyOn($state, 'go'); expect(controller.$).toBe($scope);
controller.onSubmit(); expect(controller.$state).toBe($state);
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.basicData', {id: '1234'}); 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'; import './index.js';
describe('Component vnClientIndex', () => { describe('Client', () => {
let $componentController; describe('Component vnClientIndex', () => {
let $componentController;
beforeEach(() => { beforeEach(() => {
angular.mock.module('client'); angular.mock.module('client');
}); });
beforeEach(angular.mock.inject(_$componentController_ => { beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_; $componentController = _$componentController_;
})); }));
it('should define and set model property as an empty object', () => { 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`, () => {
let controller = $componentController('vnClientIndex'); let controller = $componentController('vnClientIndex');
controller.model.search = 'batman'; expect(controller.model).toEqual({});
let index = { });
filter: {},
accept: () => { describe('search()', () => {
return 'accepted'; it(`should set model's search to the search input`, () => {
} let controller = $componentController('vnClientIndex');
}; controller.model.search = 'batman';
controller.search(index); let index = {
expect(index.filter.search).toBe('batman'); filter: {},
accept: () => {
return 'accepted';
}
};
controller.search(index);
expect(index.filter.search).toBe('batman');
});
}); });
}); });
}); });

View File

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

View File

@ -1,51 +1,53 @@
import './notes.js'; import './notes.js';
describe('Component vnClientNotes', () => { describe('Client', () => {
let $componentController; describe('Component vnClientNotes', () => {
let $state; let $componentController;
let $httpBackend; let $state;
let $httpBackend;
beforeEach(() => { beforeEach(() => {
angular.mock.module('client'); 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);
}); });
});
describe('$getObservation()', () => { beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
it(`should request to GET the client notes`, () => { $componentController = _$componentController_;
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state}); $state = _$state_;
controller.client = {id: '1234'}; $httpBackend = _$httpBackend_;
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, */*'}); describe('$onChanges()', () => {
controller.getObservation(); it(`should call getObservation() with the client id`, () => {
$httpBackend.flush(); 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()', () => { describe('$getObservation()', () => {
it(`should redirect the user to the newObservation view`, () => { it(`should request to GET the client notes`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state}); let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {id: '1234'}; controller.client = {id: '1234'};
spyOn(controller.$state, 'go'); let json = JSON.stringify({where: {clientFk: '1234'}, order: 'created DESC'});
controller.newObservation(); $httpBackend.when('GET', `/client/api/clientObservations?filter=${json}`).respond('ok');
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.notes.create', Object({id: '1234'})); $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'; import './search-panel.js';
describe('Component vnClientSearchPanel', () => { describe('Client', () => {
let $componentController; describe('Component vnClientSearchPanel', () => {
let $window; let $componentController;
let $window;
beforeEach(() => { beforeEach(() => {
angular.mock.module('client'); 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();
}); });
});
describe('$onChanges()', () => { beforeEach(angular.mock.inject((_$componentController_, _$window_) => {
it(`should set filter properties using the search values`, () => { $componentController = _$componentController_;
let controller = $componentController('vnClientSearchPanel', {$window: $window}); $window = _$window_;
expect(controller.filter).not.toBeDefined(); }));
spyOn(JSON, 'parse').and.returnValue({data: 'data'});
controller.$onChanges(); describe('onSearch()', () => {
expect(controller.filter).toBe(JSON.parse({data: 'data'})); 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', () => {
});
});