refactor: usage of useForm
hook from react-component-form
This commit is contained in:
@ -1,71 +0,0 @@
|
||||
import type { ErrorObject } from 'ajv'
|
||||
|
||||
import { getErrorTranslationKey } from '../../../../hooks/useForm/getErrorTranslationKey'
|
||||
|
||||
const errorObject: ErrorObject = {
|
||||
instancePath: '/path',
|
||||
keyword: 'keyword',
|
||||
params: {},
|
||||
schemaPath: '/path'
|
||||
}
|
||||
|
||||
describe('hooks/useForm/getErrorTranslationKey', () => {
|
||||
it('returns `errors:invalid` with unknown keyword', () => {
|
||||
expect(
|
||||
getErrorTranslationKey({
|
||||
...errorObject,
|
||||
keyword: 'unknownkeyword'
|
||||
})
|
||||
).equal('errors:invalid')
|
||||
})
|
||||
|
||||
it('returns `errors:invalid` with format != email', () => {
|
||||
expect(
|
||||
getErrorTranslationKey({
|
||||
...errorObject,
|
||||
keyword: 'format',
|
||||
params: { format: 'email' }
|
||||
})
|
||||
).equal('errors:email')
|
||||
})
|
||||
|
||||
it('returns `errors:email` with format = email', () => {
|
||||
expect(
|
||||
getErrorTranslationKey({
|
||||
...errorObject,
|
||||
keyword: 'format',
|
||||
params: { format: 'email' }
|
||||
})
|
||||
).equal('errors:email')
|
||||
})
|
||||
|
||||
it('returns `errors:required` with minLength and limit = 1', () => {
|
||||
expect(
|
||||
getErrorTranslationKey({
|
||||
...errorObject,
|
||||
keyword: 'minLength',
|
||||
params: { limit: 1 }
|
||||
})
|
||||
).equal('errors:required')
|
||||
})
|
||||
|
||||
it('returns `errors:minLength` with minLength and limit > 1', () => {
|
||||
expect(
|
||||
getErrorTranslationKey({
|
||||
...errorObject,
|
||||
keyword: 'minLength',
|
||||
params: { limit: 5 }
|
||||
})
|
||||
).equal('errors:minLength')
|
||||
})
|
||||
|
||||
it('returns `errors:maxLength` with maxLength', () => {
|
||||
expect(
|
||||
getErrorTranslationKey({
|
||||
...errorObject,
|
||||
keyword: 'maxLength',
|
||||
params: { limit: 5 }
|
||||
})
|
||||
).equal('errors:maxLength')
|
||||
})
|
||||
})
|
@ -1,22 +0,0 @@
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
import { handleCheckboxBoolean } from '../../../../hooks/useForm/handleCheckboxBoolean'
|
||||
|
||||
const schema = Type.Object({
|
||||
myBoolean: Type.Boolean(),
|
||||
myString: Type.String()
|
||||
})
|
||||
|
||||
describe('hooks/useForm/handleCheckboxBoolean', () => {
|
||||
it('should convert all checkbox property to boolean', () => {
|
||||
const object = {
|
||||
myBoolean: 'on',
|
||||
myString: 'on'
|
||||
}
|
||||
const result = handleCheckboxBoolean(object, schema)
|
||||
expect(result).deep.equal({
|
||||
myBoolean: true,
|
||||
myString: 'on'
|
||||
})
|
||||
})
|
||||
})
|
@ -1,20 +0,0 @@
|
||||
import { replaceEmptyStringInObjectToNull } from '../../../../hooks/useForm/replaceEmptyStringInObjectToNull'
|
||||
|
||||
describe('hooks/useForm/replaceEmptyStringInObjectToNull', () => {
|
||||
it('should replace empty string in object to null except for required properties', () => {
|
||||
expect(
|
||||
replaceEmptyStringInObjectToNull(
|
||||
{
|
||||
foo: '',
|
||||
bar: 'bar',
|
||||
baz: ''
|
||||
},
|
||||
['baz']
|
||||
)
|
||||
).deep.equal({
|
||||
foo: null,
|
||||
bar: 'bar',
|
||||
baz: ''
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user