From 352e68ed584fec0f7e0800a2c44e723bae49b14a Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 4 Sep 2017 15:06:43 +0200 Subject: [PATCH] refactor in all client specs to next describes accordingly --- .../src/address-create/address-create.spec.js | 34 +++-- .../src/address-edit/address-edit.spec.js | 30 ++-- .../src/billing-data/billing-data.spec.js | 144 +++++++++--------- client/client/src/card/card.spec.js | 30 ++-- client/client/src/create/create.spec.js | 68 +++++---- client/client/src/index/index.spec.js | 50 +++--- .../src/note-create/note-create.spec.js | 32 ++-- client/client/src/notes/notes.spec.js | 84 +++++----- .../src/search-panel/search-panel.spec.js | 60 ++++---- .../src/autocomplete/autocomplete.spec.js | 6 + 10 files changed, 281 insertions(+), 257 deletions(-) diff --git a/client/client/src/address-create/address-create.spec.js b/client/client/src/address-create/address-create.spec.js index a93d42ed4..a33d6c86a 100644 --- a/client/client/src/address-create/address-create.spec.js +++ b/client/client/src/address-create/address-create.spec.js @@ -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); + }); }); }); diff --git a/client/client/src/address-edit/address-edit.spec.js b/client/client/src/address-edit/address-edit.spec.js index b2072e1a8..b2bbdc50d 100644 --- a/client/client/src/address-edit/address-edit.spec.js +++ b/client/client/src/address-edit/address-edit.spec.js @@ -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); + }); }); }); diff --git a/client/client/src/billing-data/billing-data.spec.js b/client/client/src/billing-data/billing-data.spec.js index ceeaabf57..c028bab67 100644 --- a/client/client/src/billing-data/billing-data.spec.js +++ b/client/client/src/billing-data/billing-data.spec.js @@ -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(); - }); - }); }); diff --git a/client/client/src/card/card.spec.js b/client/client/src/card/card.spec.js index b6fa24221..f63a3fc9a 100644 --- a/client/client/src/card/card.spec.js +++ b/client/client/src/card/card.spec.js @@ -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); + }); }); }); diff --git a/client/client/src/create/create.spec.js b/client/client/src/create/create.spec.js index 4859d31a6..881513b3b 100644 --- a/client/client/src/create/create.spec.js +++ b/client/client/src/create/create.spec.js @@ -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'}); + }); }); }); }); diff --git a/client/client/src/index/index.spec.js b/client/client/src/index/index.spec.js index f5c7fd5fe..48a34bf0a 100644 --- a/client/client/src/index/index.spec.js +++ b/client/client/src/index/index.spec.js @@ -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'); + }); }); }); }); diff --git a/client/client/src/note-create/note-create.spec.js b/client/client/src/note-create/note-create.spec.js index 669bfe128..444dc3ba3 100644 --- a/client/client/src/note-create/note-create.spec.js +++ b/client/client/src/note-create/note-create.spec.js @@ -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); + }); }); }); diff --git a/client/client/src/notes/notes.spec.js b/client/client/src/notes/notes.spec.js index bfb3e24c8..e5a771dc2 100644 --- a/client/client/src/notes/notes.spec.js +++ b/client/client/src/notes/notes.spec.js @@ -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'})); + }); }); }); }); diff --git a/client/client/src/search-panel/search-panel.spec.js b/client/client/src/search-panel/search-panel.spec.js index 8e318a1e2..514df7209 100644 --- a/client/client/src/search-panel/search-panel.spec.js +++ b/client/client/src/search-panel/search-panel.spec.js @@ -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'})); + }); }); }); }); diff --git a/client/core/src/autocomplete/autocomplete.spec.js b/client/core/src/autocomplete/autocomplete.spec.js index e69de29bb..ed22aa513 100644 --- a/client/core/src/autocomplete/autocomplete.spec.js +++ b/client/core/src/autocomplete/autocomplete.spec.js @@ -0,0 +1,6 @@ +import './autocomplete.js'; + +describe('Core', () => { + describe('Component mdlUpdate', () => { + }); +});