-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(validation): wrong condition for required field (#99)
- Loading branch information
Showing
2 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
libs/form-builder/src/lib/utils/__tests__/error.util.spec.js
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,65 @@ | ||
import { isStepInError } from '../error.util.ts'; | ||
|
||
describe('isStepInError', () => { | ||
let schema; | ||
let errors; | ||
let fieldsToCheckByStep; | ||
let dirtyFields; | ||
let defaultValues; | ||
|
||
beforeEach(() => { | ||
schema = { | ||
fields: { | ||
myField: { | ||
id: 'myField', | ||
type: 'text', | ||
validation: { | ||
required: { | ||
value: false, | ||
key: 'required', | ||
message: 'please fill this field', | ||
}, | ||
}, | ||
}, | ||
}, | ||
stepsById: ['step1'], | ||
steps: { | ||
step1: { | ||
id: 'step1', | ||
fieldsById: ['myField'], | ||
submit: { label: 'submit' }, | ||
}, | ||
}, | ||
}; | ||
errors = {}; | ||
fieldsToCheckByStep = ['myField']; | ||
dirtyFields = {}; | ||
defaultValues = {}; | ||
}); | ||
|
||
it('should return false if the field is empty and not required', () => { | ||
const isInError = isStepInError({ | ||
schema, | ||
errors, | ||
fieldsToCheckByStep, | ||
dirtyFields, | ||
defaultValues, | ||
}); | ||
|
||
expect(isInError).toBe(false); | ||
}); | ||
|
||
it('should return true if the field is empty and required', () => { | ||
schema.fields.myField.validation.required.value = true; | ||
|
||
const isInError = isStepInError({ | ||
schema, | ||
errors, | ||
fieldsToCheckByStep, | ||
dirtyFields, | ||
defaultValues, | ||
}); | ||
|
||
expect(isInError).toBe(true); | ||
}); | ||
}); |
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