Skip to content

Commit 8dcb3b0

Browse files
authored
Merge pull request #39 from Lemoncode/issue38-fix-indentation
Added two size spaces indentation
2 parents 43c0634 + 6a43468 commit 8dcb3b0

File tree

64 files changed

+2980
-2979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2980
-2979
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2

lib/src/baseFormValidation.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import {} from 'core-js';
1+
import { } from 'core-js';
22
import { IValidationEngine, ValidationEngine } from './validationEngine';
33
import { FieldValidationResult, FormValidationResult } from './entities';
44
import { consts } from './consts';
55

66
export class BaseFormValidation {
7-
_validationEngine: IValidationEngine;
7+
_validationEngine: IValidationEngine;
88

9-
constructor() {
10-
this._validationEngine = new ValidationEngine();
11-
}
9+
constructor() {
10+
this._validationEngine = new ValidationEngine();
11+
}
1212

13-
public validateField(vm: any, key: string, value: any, filter : any = consts.defaultFilter): Promise<FieldValidationResult> {
14-
return this._validationEngine.triggerFieldValidation(vm, key, value, filter);
15-
}
13+
public validateField(vm: any, key: string, value: any, filter: any = consts.defaultFilter): Promise<FieldValidationResult> {
14+
return this._validationEngine.triggerFieldValidation(vm, key, value, filter);
15+
}
1616

17-
public validateForm(vm: any): Promise<FormValidationResult> {
18-
return this._validationEngine.validateFullForm(vm);
19-
}
17+
public validateForm(vm: any): Promise<FormValidationResult> {
18+
return this._validationEngine.validateFullForm(vm);
19+
}
2020
}

lib/src/consts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const consts = {
2-
globalFormValidationId : "_GLOBAL_FORM_",
3-
defaultFilter: {OnChange : true}
2+
globalFormValidationId: "_GLOBAL_FORM_",
3+
defaultFilter: { OnChange: true }
44
}

lib/src/entities.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
import {} from 'core-js';
1+
import { } from 'core-js';
22

33
export class FormNameToFieldNameMapping {
4-
formFieldName : string;
5-
vmFieldName : string;
4+
formFieldName: string;
5+
vmFieldName: string;
66
}
77

88
export class FieldValidation {
9-
public validationFn :(vm, value) => Promise<FieldValidationResult>;
10-
public filter : any;
9+
public validationFn: (vm, value) => Promise<FieldValidationResult>;
10+
public filter: any;
1111
}
1212

1313
export class FieldValidationResult {
14-
key : string;
15-
type : string;
16-
succeeded : boolean;
17-
errorMessage : string;
14+
key: string;
15+
type: string;
16+
succeeded: boolean;
17+
errorMessage: string;
1818

19-
constructor() {
20-
this.key = '';
21-
this.type = '';
22-
this.succeeded = false;
23-
this.errorMessage = '';
19+
constructor() {
20+
this.key = '';
21+
this.type = '';
22+
this.succeeded = false;
23+
this.errorMessage = '';
2424
}
2525
}
2626

2727
export class FormValidationResult {
28-
succeeded : boolean;
29-
fieldErrors : Array<FieldValidationResult>;
30-
formGlobalErrors: Array<FieldValidationResult>;
28+
succeeded: boolean;
29+
fieldErrors: Array<FieldValidationResult>;
30+
formGlobalErrors: Array<FieldValidationResult>;
3131

32-
constructor() {
33-
this.succeeded = false;
34-
this.fieldErrors = [];
35-
}
32+
constructor() {
33+
this.succeeded = false;
34+
this.fieldErrors = [];
35+
}
3636
}

lib/src/entitiesMapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {} from 'core-js';
2-
import {FieldValidation, FieldValidationResult} from './entities';
1+
import { } from 'core-js';
2+
import { FieldValidation, FieldValidationResult } from './entities';
33

44
export class EntitiesMapper {
5-
public ExtractArrayValidationFnFromFieldValidationArray(validationsPerField : Array<FieldValidation>)
6-
: Array<(vm, value) => Promise<FieldValidationResult>> {
5+
public ExtractArrayValidationFnFromFieldValidationArray(validationsPerField: Array<FieldValidation>)
6+
: Array<(vm, value) => Promise<FieldValidationResult>> {
77
return validationsPerField.map(value => value.validationFn);
88
}
99
}

lib/src/fieldValidationEventFilter.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
1-
import {FieldValidation} from './entities';
1+
import { FieldValidation } from './entities';
22

33
class FieldValidationEventFilter {
44

5-
public filter(fieldValidations : Array<FieldValidation>, filter : any) : Array<FieldValidation> {
6-
let result = new Array<FieldValidation>();
5+
public filter(fieldValidations: Array<FieldValidation>, filter: any): Array<FieldValidation> {
6+
let result = new Array<FieldValidation>();
77

8-
if(filter) {
9-
result = fieldValidations.filter((element) => {
10-
return this.matchFilterOr(element, filter)
11-
});
12-
} else {
13-
result = fieldValidations;
14-
}
8+
if (filter) {
9+
result = fieldValidations.filter((element) => {
10+
return this.matchFilterOr(element, filter)
11+
});
12+
} else {
13+
result = fieldValidations;
14+
}
1515

16-
return result;
16+
return result;
1717
}
1818

1919
private matchFilterOr(itemFilter, globalFilter) {
20-
let result : boolean = false;
20+
let result: boolean = false;
2121

2222
for (var property in globalFilter) {
23-
if (this.propertyMatched(itemFilter, property, globalFilter)) {
24-
result = true;
25-
break;
26-
}
23+
if (this.propertyMatched(itemFilter, property, globalFilter)) {
24+
result = true;
25+
break;
26+
}
2727
}
2828

2929
return result;
3030
}
3131

32-
private propertyMatched(item : any, property : any, globalFilter : any) : boolean
33-
{
34-
return (globalFilter.hasOwnProperty(property) &&
35-
globalFilter[property] == item.filter[property]);
32+
private propertyMatched(item: any, property: any, globalFilter: any): boolean {
33+
return (globalFilter.hasOwnProperty(property) &&
34+
globalFilter[property] == item.filter[property]);
3635
}
3736
}
3837

lib/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { FormNameToFieldNameMapping, FormValidationResult, FieldValidationResult
22
import { BaseFormValidation } from './baseFormValidation';
33

44
export {
5-
FormNameToFieldNameMapping,
6-
FormValidationResult,
7-
FieldValidationResult,
8-
BaseFormValidation
5+
FormNameToFieldNameMapping,
6+
FormValidationResult,
7+
FieldValidationResult,
8+
BaseFormValidation
99
}
Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
1-
import {} from 'mocha';
1+
import { } from 'mocha';
22
import { expect } from 'chai';
3-
import {Promise} from 'core-js';
4-
import {FieldValidation, FieldValidationResult} from '../entities';
5-
import {entitiesMapper} from '../entitiesMapper';
3+
import { Promise } from 'core-js';
4+
import { FieldValidation, FieldValidationResult } from '../entities';
5+
import { entitiesMapper } from '../entitiesMapper';
66

77

88
describe('mapper ', () => {
99

10-
describe('when calling ExtractArrayValidationFnFromFieldValidationArray ', () => {
11-
it('should returns an empty array ' +
12-
'when passing an empty array as input parameter', () => {
13-
// Arrange
14-
const validationsPerField : Array<FieldValidation> = [];
10+
describe('when calling ExtractArrayValidationFnFromFieldValidationArray ', () => {
11+
it('should returns an empty array ' +
12+
'when passing an empty array as input parameter', () => {
13+
// Arrange
14+
const validationsPerField: Array<FieldValidation> = [];
1515

16-
//Act
17-
let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField);
16+
//Act
17+
let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField);
1818

19-
//Assert
20-
expect(result.length).to.be.equal(0);
21-
});
22-
});
19+
//Assert
20+
expect(result.length).to.be.equal(0);
21+
});
22+
});
2323

24-
describe('when calling ExtractArrayValidationFnFromFieldValidationArray ', () => {
25-
it('should returns an array with one element (a function) ' +
26-
'when passing an array with one element as input parameter', (done) => {
27-
// Arrange
28-
const validationsPerField : Array<FieldValidation> = [
29-
{
30-
validationFn : (vm, value)=> {
31-
const fieldValidationResult = new FieldValidationResult();
32-
fieldValidationResult.type = "test",
33-
fieldValidationResult.succeeded = true;
34-
fieldValidationResult.errorMessage = "error test";
35-
return Promise.resolve(fieldValidationResult);
36-
},
37-
filter : {OnChange: true}
38-
}
39-
];
24+
describe('when calling ExtractArrayValidationFnFromFieldValidationArray ', () => {
25+
it('should returns an array with one element (a function) ' +
26+
'when passing an array with one element as input parameter', (done) => {
27+
// Arrange
28+
const validationsPerField: Array<FieldValidation> = [
29+
{
30+
validationFn: (vm, value) => {
31+
const fieldValidationResult = new FieldValidationResult();
32+
fieldValidationResult.type = "test",
33+
fieldValidationResult.succeeded = true;
34+
fieldValidationResult.errorMessage = "error test";
35+
return Promise.resolve(fieldValidationResult);
36+
},
37+
filter: { OnChange: true }
38+
}
39+
];
4040

41-
//Act
42-
let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField);
41+
//Act
42+
let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField);
4343

44-
//Assert
45-
expect(result.length).to.be.equal(1);
46-
expect(result[0]).to.be.a('function');
47-
//expect(result[0](null, null).errorMessage)
48-
result[0](null, null).then((fieldValidationResult) => {
49-
// Assert
50-
expect(fieldValidationResult.errorMessage).to.be.equal("error test");
51-
done();
52-
});
44+
//Assert
45+
expect(result.length).to.be.equal(1);
46+
expect(result[0]).to.be.a('function');
47+
//expect(result[0](null, null).errorMessage)
48+
result[0](null, null).then((fieldValidationResult) => {
49+
// Assert
50+
expect(fieldValidationResult.errorMessage).to.be.equal("error test");
51+
done();
5352
});
54-
});
55-
56-
describe('when calling ExtractArrayValidationFnFromFieldValidationArray ', () => {
57-
it('should returns an array having two elements (two functions) ' +
58-
'when passing an array having two elements as input parameter', (done) => {
59-
// Arrange
60-
const validationsPerField : Array<FieldValidation> = [
61-
{
62-
validationFn : (vm, value)=> {
63-
const fieldValidationResult = new FieldValidationResult();
64-
fieldValidationResult.type = "test1",
65-
fieldValidationResult.succeeded = true;
66-
fieldValidationResult.errorMessage = "error test1";
67-
return Promise.resolve(fieldValidationResult);
68-
},
69-
filter : {OnChange: true}
70-
},
71-
{
72-
validationFn : (vm, value)=> {
73-
const fieldValidationResult = new FieldValidationResult();
74-
fieldValidationResult.type = "test2",
75-
fieldValidationResult.succeeded = true;
76-
fieldValidationResult.errorMessage = "error test2";
77-
return Promise.resolve(fieldValidationResult);
78-
},
79-
filter : {OnChange: true}
80-
}
81-
];
53+
});
54+
});
8255

83-
//Act
84-
let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField);
56+
describe('when calling ExtractArrayValidationFnFromFieldValidationArray ', () => {
57+
it('should returns an array having two elements (two functions) ' +
58+
'when passing an array having two elements as input parameter', (done) => {
59+
// Arrange
60+
const validationsPerField: Array<FieldValidation> = [
61+
{
62+
validationFn: (vm, value) => {
63+
const fieldValidationResult = new FieldValidationResult();
64+
fieldValidationResult.type = "test1",
65+
fieldValidationResult.succeeded = true;
66+
fieldValidationResult.errorMessage = "error test1";
67+
return Promise.resolve(fieldValidationResult);
68+
},
69+
filter: { OnChange: true }
70+
},
71+
{
72+
validationFn: (vm, value) => {
73+
const fieldValidationResult = new FieldValidationResult();
74+
fieldValidationResult.type = "test2",
75+
fieldValidationResult.succeeded = true;
76+
fieldValidationResult.errorMessage = "error test2";
77+
return Promise.resolve(fieldValidationResult);
78+
},
79+
filter: { OnChange: true }
80+
}
81+
];
8582

86-
//Assert
87-
expect(result.length).to.be.equal(2);
88-
expect(result[0]).to.be.a('function');
89-
expect(result[1]).to.be.a('function');
83+
//Act
84+
let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField);
9085

91-
result[0](null, null).then((fieldValidationResult) => {
92-
// Assert
93-
expect(fieldValidationResult.errorMessage).to.be.equal("error test1");
94-
done();
95-
});
86+
//Assert
87+
expect(result.length).to.be.equal(2);
88+
expect(result[0]).to.be.a('function');
89+
expect(result[1]).to.be.a('function');
9690

97-
result[1](null, null).then((fieldValidationResult) => {
98-
// Assert
99-
expect(fieldValidationResult.errorMessage).to.be.equal("error test2");
100-
done();
101-
});
91+
result[0](null, null).then((fieldValidationResult) => {
92+
// Assert
93+
expect(fieldValidationResult.errorMessage).to.be.equal("error test1");
94+
done();
95+
});
10296

97+
result[1](null, null).then((fieldValidationResult) => {
98+
// Assert
99+
expect(fieldValidationResult.errorMessage).to.be.equal("error test2");
100+
done();
103101
});
104-
});
102+
103+
});
104+
});
105105

106106
});

0 commit comments

Comments
 (0)