Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond authored and lane-formio committed Apr 8, 2024
1 parent 1e224ee commit 88e86ad
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 12,112 deletions.
45 changes: 2 additions & 43 deletions src/process/validation/__tests__/Validator.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import get from 'lodash/get';
import { expect } from 'chai';
import { interpolateErrors, validateProcess } from '../index';
import { validateProcess } from '../index';
import { rules } from "../rules";
import { simpleForm } from './fixtures/forms';
import { ProcessorType, ValidationScope } from 'types';
import { FieldError, InterpolateErrorFn } from 'error';
import get from 'lodash/get';

it('Validator will throw the correct errors given a flat components array', async () => {
let errors: string[] = [];
Expand Down Expand Up @@ -37,43 +36,3 @@ it('Validator will throw the correct errors given a flat components array', asyn
}
expect(errors).to.have.length(6);
});

it('Validation errors (FieldErrors) should include the rule name mapping in the "validator" param', async () => {
const data = {
requiredField: '',
maximumWords: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
minimumWords: 'Hello',
email: 'brendanb',
url: 'htpigoogle',
inputMask: 'hello, world',
submit: false,
};
const result: Map<string, ReturnType<typeof interpolateErrors>> = new Map();
for (let component of simpleForm.components) {
const path = component.key;
const scope: ValidationScope = { errors: [] };
await validateProcess({
component,
scope,
data,
row: data,
path,
value: get(data, component.key),
processor: ProcessorType.Validate,
rules
});
result.set(path, interpolateErrors(scope.errors));
}
expect(result.get('requiredField')).to.have.length(1);
expect(result.get('requiredField')![0].context.validator).to.equal('required');
expect(result.get('maximumWords')).to.have.length(1);
expect(result.get('maximumWords')![0].context.validator).to.equal('maxWords');
expect(result.get('minimumWords')).to.have.length(1);
expect(result.get('minimumWords')![0].context.validator).to.equal('minWords');
expect(result.get('email')).to.have.length(1);
expect(result.get('email')![0].context.validator).to.equal('email');
expect(result.get('url')).to.have.length(1);
expect(result.get('url')![0].context.validator).to.equal('url');
expect(result.get('inputMask')).to.have.length(1);
expect(result.get('inputMask')![0].context.validator).to.equal('inputMask');
});
31 changes: 0 additions & 31 deletions src/process/validation/__tests__/fixtures/components.d.ts

This file was deleted.

196 changes: 0 additions & 196 deletions src/process/validation/__tests__/fixtures/components.js

This file was deleted.

Loading

0 comments on commit 88e86ad

Please sign in to comment.