Skip to content

Commit

Permalink
test(subform): validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Liberty-liu committed Sep 11, 2023
1 parent 2ea2a74 commit 0f661bc
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/hooks/use-logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ const listenEvent = (state) => {
subform.options.defaultValue = utils.getSubFormValues(subform)
}, {
immediate: true,
deep: true
deep: true,
flush: 'sync'
})
})
watch(() => targetFields.map(e => e.options.defaultValue), (values) => {
Expand Down
69 changes: 69 additions & 0 deletions test/logic/validator/Subform.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { describe, assert, expect, test, beforeAll } from 'vitest'
import { validator } from '@ER/hooks/use-logic'
import _ from 'lodash-es'
import erGeneratorData from '@ER/formEditor/generatorData.js'
import * as erComponentsConfig from '@ER/formEditor/componentsConfig.js'
describe('Subform', () => {
let field = {}
beforeAll(() => {
field = erGeneratorData(_.cloneDeep(erComponentsConfig.fieldsConfig[2].list[5]), true, 'en')
})
test('empty', () => {
expect(
validator({
operator: 'empty'
},
'',
field)).toBeTruthy()
expect(
validator({
operator: 'empty'
},
undefined,
field)).toBeTruthy()
expect(
validator({
operator: 'empty'
},
null,
field)).toBeTruthy()
expect(
validator({
operator: 'empty'
},
[],
field)).toBeTruthy()
expect(
validator({
operator: 'empty'
},
[{}],
field)).toBeFalsy()
})
test('not_empty', () => {
expect(
validator({
operator: 'not_empty'
},
'',
field)).toBeFalsy()
expect(
validator({
operator: 'not_empty'
},
undefined,
field)).toBeFalsy()
expect(
validator({
operator: 'not_empty'
},
null,
field)).toBeFalsy()
expect(
validator({
operator: 'not_empty'
},
[{}],
field)).toBeTruthy()
})
})

0 comments on commit 0f661bc

Please sign in to comment.