-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from formio/FIO-8645-required-validation-does…
…-not-trigger-with-valid-message FIO-8645: added tests and translations for validateRequiredDay
- Loading branch information
Showing
3 changed files
with
66 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/process/validation/rules/__tests__/validateRequiredDay.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {expect} from 'chai' | ||
import {FieldError} from 'error'; | ||
import {simpleDayField} from './fixtures/components'; | ||
import {generateProcessorContext} from "./fixtures/util"; | ||
import {validateRequiredDay} from '../validateRequiredDay' | ||
|
||
it('Validating a day component without data will return a requiredDayEmpty FieldError', async () => { | ||
const component = { | ||
...simpleDayField, | ||
fields: {day: {required: true}, month: {required: false}, year: {required: false}} | ||
}; | ||
const data = {} | ||
const context = generateProcessorContext(component, data); | ||
const result = await validateRequiredDay(context); | ||
expect(result).to.be.instanceOf(FieldError); | ||
expect(result?.errorKeyOrMessage).to.equal('requiredDayEmpty'); | ||
}); | ||
|
||
it('Validating a day component that requires day will return a FieldError if day is not given', async () => { | ||
const component = { | ||
...simpleDayField, | ||
fields: {day: {required: true}} | ||
} | ||
const data = {component: "01/00/2024"}; | ||
const context = generateProcessorContext(component, data); | ||
const result = await validateRequiredDay(context); | ||
expect(result).to.be.instanceOf(FieldError); | ||
expect(result?.errorKeyOrMessage).to.equal('requiredDayField'); | ||
}); | ||
|
||
it('Validating a day component that requires month will return a FieldError if month is not given', async () => { | ||
const component = { | ||
...simpleDayField, | ||
fields: {month: {required: true}} | ||
} | ||
const data = {component: "00/01/2024"}; | ||
const context = generateProcessorContext(component, data); | ||
const result = await validateRequiredDay(context); | ||
expect(result).to.be.instanceOf(FieldError); | ||
expect(result?.errorKeyOrMessage).to.equal('requiredMonthField'); | ||
}); | ||
|
||
it('Validating a day component that requires year will return a FieldError if year is not given', async () => { | ||
const component = { | ||
...simpleDayField, | ||
fields: {year: {required: true}} | ||
}; | ||
const data = {component: "01/01/0000"}; | ||
const context = generateProcessorContext(component, data); | ||
const result = await validateRequiredDay(context); | ||
expect(result).to.be.instanceOf(FieldError); | ||
expect(result?.errorKeyOrMessage).to.equal('requiredYearField'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters