diff --git a/packages/hooks/use-logic/index.js b/packages/hooks/use-logic/index.js index aecff19..2efd72b 100644 --- a/packages/hooks/use-logic/index.js +++ b/packages/hooks/use-logic/index.js @@ -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) => { diff --git a/test/logic/validator/Subform.test.js b/test/logic/validator/Subform.test.js new file mode 100644 index 0000000..33ea604 --- /dev/null +++ b/test/logic/validator/Subform.test.js @@ -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() + }) +})