jasmine ESLint plugging added to dev dependencies and refactor on all specs according to eslint rules.

This commit is contained in:
Carlos 2017-09-20 14:01:33 +02:00
parent e20dd82928
commit 9ed9e13b54
16 changed files with 69 additions and 44 deletions

View File

@ -1,5 +1,9 @@
extends: [eslint:recommended, google] extends: [eslint:recommended, google, plugin:jasmine/recommended]
installedESLint: true installedESLint: true
plugins:
- jasmine
env:
jasmine: true
rules: rules:
indent: [error, 4] indent: [error, 4]
require-jsdoc: 0 require-jsdoc: 0

View File

@ -17,6 +17,7 @@ describe('Client', () => {
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.clientFk).toBe(1234); expect(controller.address.clientFk).toBe(1234);
expect(controller.address.enabled).toBe(true); expect(controller.address.enabled).toBe(true);
}); });

View File

@ -17,6 +17,7 @@ describe('Client', () => {
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

@ -33,6 +33,7 @@ describe('Client', () => {
}; };
controller.billData = {}; controller.billData = {};
controller.copyData(controller.client); controller.copyData(controller.client);
expect(controller.billData).toEqual(controller.client); expect(controller.billData).toEqual(controller.client);
}); });
}); });
@ -43,8 +44,8 @@ describe('Client', () => {
spyOn(controller, 'checkPaymentChanges'); spyOn(controller, 'checkPaymentChanges');
controller.submit() controller.submit()
.then(() => { .then(() => {
expect(controller.$.watcher.submit).toHaveBeenCalled(); expect(controller.$.watcher.submit).toHaveBeenCalledWith();
expect(controller.checkPaymentChanges).toHaveBeenCalled(); expect(controller.checkPaymentChanges).toHaveBeenCalledWith();
done(); done();
}); });
}); });
@ -56,6 +57,7 @@ describe('Client', () => {
controller.billData = {marvelHero: 'Silver Surfer'}; controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Silver Surfer'}; controller.client = {marvelHero: 'Silver Surfer'};
controller.checkPaymentChanges(); controller.checkPaymentChanges();
expect(controller.$.sendMail.show).not.toHaveBeenCalled(); expect(controller.$.sendMail.show).not.toHaveBeenCalled();
}); });
@ -64,7 +66,8 @@ describe('Client', () => {
controller.billData = {marvelHero: 'Silver Surfer'}; controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Spider-Man'}; controller.client = {marvelHero: 'Spider-Man'};
controller.checkPaymentChanges(); controller.checkPaymentChanges();
expect(controller.$.sendMail.show).toHaveBeenCalled();
expect(controller.$.sendMail.show).toHaveBeenCalledWith();
}); });
}); });

View File

@ -16,6 +16,7 @@ describe('Client', () => {
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

@ -27,6 +27,7 @@ describe('Client', () => {
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}); let controller = $componentController('vnClientCreate', {$scope: $scope});
expect(controller.$).toBe($scope); expect(controller.$).toBe($scope);
expect(controller.$state).toBe($state); expect(controller.$state).toBe($state);
expect(controller.client.active).toBe(true); expect(controller.client.active).toBe(true);
@ -37,6 +38,7 @@ describe('Client', () => {
let controller = $componentController('vnClientCreate', {$scope: $scope}); let controller = $componentController('vnClientCreate', {$scope: $scope});
spyOn($state, 'go'); spyOn($state, 'go');
controller.onSubmit(); controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.basicData', {id: '1234'}); expect(controller.$state.go).toHaveBeenCalledWith('clientCard.basicData', {id: '1234'});
}); });
}); });

View File

@ -18,10 +18,13 @@ describe('Client', () => {
it('should check if active is defined and diferent from the new value', () => { it('should check if active is defined and diferent from the new value', () => {
let controller = $componentController('vnDescriptor', {$scope: $scope}); let controller = $componentController('vnDescriptor', {$scope: $scope});
controller.client = {id: 1}; controller.client = {id: 1};
expect(controller._active).toBe(undefined); expect(controller._active).toBe(undefined);
controller.active = false; controller.active = false;
expect(controller._active).toBe(false); expect(controller._active).toBe(false);
controller.active = true; controller.active = true;
expect(controller._active).toBe(true); expect(controller._active).toBe(true);
}); });
}); });

View File

@ -14,6 +14,7 @@ describe('Client', () => {
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'); let controller = $componentController('vnClientIndex');
expect(controller.model).toEqual({}); expect(controller.model).toEqual({});
}); });
@ -28,6 +29,7 @@ describe('Client', () => {
} }
}; };
controller.search(index); controller.search(index);
expect(index.filter.search).toBe('batman'); expect(index.filter.search).toBe('batman');
}); });
}); });

View File

@ -17,6 +17,7 @@ describe('Client', () => {
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

@ -24,6 +24,7 @@ describe('Client', () => {
}; };
spyOn(controller, 'getObservation').and.returnValue(); spyOn(controller, 'getObservation').and.returnValue();
controller.$onChanges(); controller.$onChanges();
expect(controller.getObservation).toHaveBeenCalledWith(1234); expect(controller.getObservation).toHaveBeenCalledWith(1234);
}); });
}); });
@ -46,6 +47,7 @@ describe('Client', () => {
controller.client = {id: '1234'}; controller.client = {id: '1234'};
spyOn(controller.$state, 'go'); spyOn(controller.$state, 'go');
controller.newObservation(); controller.newObservation();
expect(controller.$state.go).toHaveBeenCalledWith('clientCard.notes.create', Object({id: '1234'})); expect(controller.$state.go).toHaveBeenCalledWith('clientCard.notes.create', Object({id: '1234'}));
}); });
}); });

View File

@ -21,17 +21,20 @@ describe('Client', () => {
spyOn(controller, 'onSubmit'); spyOn(controller, 'onSubmit');
controller.setStorageValue(); controller.setStorageValue();
controller.onSubmit(); controller.onSubmit();
expect(controller.setStorageValue).toHaveBeenCalled();
expect(controller.onSubmit).toHaveBeenCalled(); expect(controller.setStorageValue).toHaveBeenCalledWith();
expect(controller.onSubmit).toHaveBeenCalledWith();
}); });
}); });
describe('$onChanges()', () => { describe('$onChanges()', () => {
it(`should set filter properties using the search values`, () => { it(`should set filter properties using the search values`, () => {
let controller = $componentController('vnClientSearchPanel', {$window: $window}); let controller = $componentController('vnClientSearchPanel', {$window: $window});
expect(controller.filter).not.toBeDefined(); expect(controller.filter).not.toBeDefined();
spyOn(JSON, 'parse').and.returnValue({data: 'data'}); spyOn(JSON, 'parse').and.returnValue({data: 'data'});
controller.$onChanges(); controller.$onChanges();
expect(controller.filter).toBe(JSON.parse({data: 'data'})); expect(controller.filter).toBe(JSON.parse({data: 'data'}));
}); });
}); });

View File

@ -24,6 +24,7 @@ describe('Component VnClientWebAccess', () => {
controller.client = {client: 'Bruce Wayne', account: 'Wayne Industries'}; controller.client = {client: 'Bruce Wayne', account: 'Wayne Industries'};
controller.account = {}; controller.account = {};
controller.$onChanges(); controller.$onChanges();
expect(controller.account).toBe('Wayne Industries'); expect(controller.account).toBe('Wayne Industries');
}); });
}); });
@ -34,6 +35,7 @@ describe('Component VnClientWebAccess', () => {
controller.newPassword = 'm24x8'; controller.newPassword = 'm24x8';
controller.repeatPassword = 'm24x8'; controller.repeatPassword = 'm24x8';
controller.onPassOpen(); controller.onPassOpen();
expect(controller.newPassword).toBe(''); expect(controller.newPassword).toBe('');
expect(controller.repeatPassword).toBe(''); expect(controller.repeatPassword).toBe('');
}); });
@ -52,22 +54,24 @@ describe('Component VnClientWebAccess', () => {
}); });
describe(`when password is empty`, () => { describe(`when password is empty`, () => {
it('should throw an error', () => { it(`should throw Passwords can't be empty error`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope}); let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'}; controller.client = {id: '1234'};
controller.newPassword = ''; controller.newPassword = '';
controller.onPassChange('ACCEPT'); controller.onPassChange('ACCEPT');
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords can't be empty`); expect(vnApp.showError).toHaveBeenCalledWith(`Passwords can't be empty`);
}); });
}); });
describe(`when passwords don't match`, () => { describe(`when passwords don't match`, () => {
it('should throw an error', () => { it(`should throw Passwords don't match error`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope}); let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'}; controller.client = {id: '1234'};
controller.newPassword = 'm24x8'; controller.newPassword = 'm24x8';
controller.repeatPassword = 'notMatchingPassword'; controller.repeatPassword = 'notMatchingPassword';
controller.onPassChange('ACCEPT'); controller.onPassChange('ACCEPT');
expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`); expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`);
}); });
}); });

View File

@ -17,6 +17,7 @@ describe('Core', () => {
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.clientFk).toBe(1234); expect(controller.address.clientFk).toBe(1234);
expect(controller.address.enabled).toBe(true); expect(controller.address.enabled).toBe(true);
}); });

View File

@ -36,6 +36,7 @@
"eslint-config-loopback": "^4.0.0", "eslint-config-loopback": "^4.0.0",
"eslint-config-xo": "^0.17.0", "eslint-config-xo": "^0.17.0",
"eslint-plugin-angular": "^1.4.1", "eslint-plugin-angular": "^1.4.1",
"eslint-plugin-jasmine": "^2.8.4",
"file-loader": "^0.9.0", "file-loader": "^0.9.0",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-concat": "^2.6.0", "gulp-concat": "^2.6.0",

View File

@ -1,32 +1,31 @@
// import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; import {catchErrors} from '../../../../../../services/utils/jasmineHelpers';
// let app = require('../../../../server/server'); let app = require('../../../../server/server');
// describe('Client Create()', () => { describe('Client Create()', () => {
let data = {
name: 'Max Eisenhardt',
userName: 'Magneto',
email: 'magneto@marvel.com',
fi: 'X-tax number',
socialName: 'The X-Men'
};
// let data = { it('should createa new account', done => {
// name: 'Max Eisenhardt', app.models.Client.createUserProfile(data, () => {
// userName: 'Magneto', app.models.Account.findOne({where: {name: data.userName}})
// email: 'magneto@marvel.com', .then(account => {
// fi: 'X-tax number', expect(account.name).toEqual(data.userName);
// socialName: 'The X-Men' app.models.Client.findOne({where: {name: data.name}})
// } .then(client => {
expect(client.id).toEqual(account.id);
// it('should createa new account', (done) => { expect(client.name).toEqual(data.name);
// app.models.Client.createUserProfile(data, () => { expect(client.email).toEqual(data.email);
// app.models.Account.findOne({where: {name: data.userName}}) expect(client.fi).toEqual(data.fi);
// .then(account => { expect(client.socialName).toEqual(data.socialName);
// expect(account.name).toEqual(data.userName) done();
// app.models.Client.findOne({where: {name: data.name}}) });
// .then(client => { })
// expect(client.id).toEqual(account.id); .catch(catchErrors(done));
// expect(client.name).toEqual(data.name); });
// expect(client.email).toEqual(data.email); });
// expect(client.fi).toEqual(data.fi); });
// expect(client.socialName).toEqual(data.socialName);
// done();
// });
// })
// .catch(catchErrors(done));
// });
// });
// });

View File

@ -1,7 +1,4 @@
module.exports = function(Agency) { module.exports = Agency => {
let serverFilter = {where: {isManaged: {neq: 0}}};
var serverFilter = {"where": {"isManaged": {"neq": 0}}};
Agency.defineScope(serverFilter); Agency.defineScope(serverFilter);
};
}