|
1 | | -import {} from 'mocha'; |
| 1 | +import { } from 'mocha'; |
2 | 2 | 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'; |
6 | 6 |
|
7 | 7 |
|
8 | 8 | describe('mapper ', () => { |
9 | 9 |
|
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> = []; |
15 | 15 |
|
16 | | - //Act |
17 | | - let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField); |
| 16 | + //Act |
| 17 | + let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField); |
18 | 18 |
|
19 | | - //Assert |
20 | | - expect(result.length).to.be.equal(0); |
21 | | - }); |
22 | | - }); |
| 19 | + //Assert |
| 20 | + expect(result.length).to.be.equal(0); |
| 21 | + }); |
| 22 | + }); |
23 | 23 |
|
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 | + ]; |
40 | 40 |
|
41 | | - //Act |
42 | | - let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField); |
| 41 | + //Act |
| 42 | + let result = entitiesMapper.ExtractArrayValidationFnFromFieldValidationArray(validationsPerField); |
43 | 43 |
|
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(); |
53 | 52 | }); |
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 | + }); |
82 | 55 |
|
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 | + ]; |
85 | 82 |
|
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); |
90 | 85 |
|
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'); |
96 | 90 |
|
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 | + }); |
102 | 96 |
|
| 97 | + result[1](null, null).then((fieldValidationResult) => { |
| 98 | + // Assert |
| 99 | + expect(fieldValidationResult.errorMessage).to.be.equal("error test2"); |
| 100 | + done(); |
103 | 101 | }); |
104 | | - }); |
| 102 | + |
| 103 | + }); |
| 104 | + }); |
105 | 105 |
|
106 | 106 | }); |
0 commit comments