Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyNikipelau committed May 17, 2024
1 parent d49a8c0 commit b81e754
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/process/validation/__tests__/multiple.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expect } from 'chai';
import { validationRules } from '..';
import { rules, serverRules } from '../rules';

const allRules = [...rules, ...serverRules];

const component = {
type: 'textfield',
key: 'multiple_textfield',
label: 'Multiple Textfield',
input: true,
multiple: true,
validate: {
required: true,
maxLength: 10,
minLength: 5,
pattern: '^[0-9]+$',
}
};

const context = {
component,
value: [],
path: 'multiple_textfield',
data: {multiple_textfield: []},
row: {multiple_textfield: []},
scope: {errors: []},
};

it('Validating required rule will work for multiple values component with no rows', async () => {
const fullValueRules = allRules.filter((rule) => rule.fullValue);
const rulesToValidate = validationRules(context, fullValueRules, undefined);
expect(rulesToValidate).to.not.have.length(0);
});

it('Validati olther rules will skip for multiple values component with no rows', async () => {
const otherRules = allRules.filter((rule) => !rule.fullValue);
const rulesToValidate = validationRules(context, otherRules, undefined);
expect(rulesToValidate).to.have.length(0);
});

0 comments on commit b81e754

Please sign in to comment.