|
| 1 | +import get from 'lodash/get'; |
1 | 2 | import { expect } from 'chai';
|
2 |
| -import { interpolateErrors, validateProcess } from '../index'; |
| 3 | +import { validateProcess } from '../index'; |
3 | 4 | import { rules } from "../rules";
|
4 | 5 | import { simpleForm } from './fixtures/forms';
|
5 | 6 | import { ProcessorType, ValidationScope } from 'types';
|
6 |
| -import { FieldError, InterpolateErrorFn } from 'error'; |
7 |
| -import get from 'lodash/get'; |
8 | 7 |
|
9 | 8 | it('Validator will throw the correct errors given a flat components array', async () => {
|
10 | 9 | let errors: string[] = [];
|
@@ -37,43 +36,3 @@ it('Validator will throw the correct errors given a flat components array', asyn
|
37 | 36 | }
|
38 | 37 | expect(errors).to.have.length(6);
|
39 | 38 | });
|
40 |
| - |
41 |
| -it('Validation errors (FieldErrors) should include the rule name mapping in the "validator" param', async () => { |
42 |
| - const data = { |
43 |
| - requiredField: '', |
44 |
| - maximumWords: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', |
45 |
| - minimumWords: 'Hello', |
46 |
| - email: 'brendanb', |
47 |
| - url: 'htpigoogle', |
48 |
| - inputMask: 'hello, world', |
49 |
| - submit: false, |
50 |
| - }; |
51 |
| - const result: Map<string, ReturnType<typeof interpolateErrors>> = new Map(); |
52 |
| - for (let component of simpleForm.components) { |
53 |
| - const path = component.key; |
54 |
| - const scope: ValidationScope = { errors: [] }; |
55 |
| - await validateProcess({ |
56 |
| - component, |
57 |
| - scope, |
58 |
| - data, |
59 |
| - row: data, |
60 |
| - path, |
61 |
| - value: get(data, component.key), |
62 |
| - processor: ProcessorType.Validate, |
63 |
| - rules |
64 |
| - }); |
65 |
| - result.set(path, interpolateErrors(scope.errors)); |
66 |
| - } |
67 |
| - expect(result.get('requiredField')).to.have.length(1); |
68 |
| - expect(result.get('requiredField')![0].context.validator).to.equal('required'); |
69 |
| - expect(result.get('maximumWords')).to.have.length(1); |
70 |
| - expect(result.get('maximumWords')![0].context.validator).to.equal('maxWords'); |
71 |
| - expect(result.get('minimumWords')).to.have.length(1); |
72 |
| - expect(result.get('minimumWords')![0].context.validator).to.equal('minWords'); |
73 |
| - expect(result.get('email')).to.have.length(1); |
74 |
| - expect(result.get('email')![0].context.validator).to.equal('email'); |
75 |
| - expect(result.get('url')).to.have.length(1); |
76 |
| - expect(result.get('url')![0].context.validator).to.equal('url'); |
77 |
| - expect(result.get('inputMask')).to.have.length(1); |
78 |
| - expect(result.get('inputMask')![0].context.validator).to.equal('inputMask'); |
79 |
| -}); |
0 commit comments