diff --git a/packages/components/FormItem.vue b/packages/components/FormItem.vue index c6e4bdb3..099c82ef 100644 --- a/packages/components/FormItem.vue +++ b/packages/components/FormItem.vue @@ -6,7 +6,7 @@ { + it('linkage: satisfaction.value > 3 && improvementSuggestions hidden', async () => { + const wrapper = mount(formRender, { + props: { + schema + } + }) + await nextTick() + await flushPromises() + + await new Promise((resolve) => setTimeout(resolve, 100)) + + const satisfactionEl = wrapper.findAll('.Radio-satisfaction .el-radio__original') + + await satisfactionEl[0].setValue(true) + + await new Promise((resolve) => setTimeout(resolve, 100)) + + expect(wrapper.find('.TextArea-improvementSuggestions').exists()).toBe(false) + }) + + it('linkage: satisfaction.value < 3 && improvementSuggestions visible', async () => { + const wrapper = mount(formRender, { + props: { + schema + } + }) + await nextTick() + await flushPromises() + + await new Promise((resolve) => setTimeout(resolve, 100)) + + const satisfactionEl = wrapper.findAll('.Radio-satisfaction .el-radio__original') + + await satisfactionEl[satisfactionEl.length - 1].setValue(true) + + await new Promise((resolve) => setTimeout(resolve, 100)) + + expect(wrapper.find('.TextArea-improvementSuggestions').exists()).toBe(true) + }) +}) diff --git a/packages/config/template/index.ts b/packages/config/template/index.ts index 3d542411..0f341be6 100644 --- a/packages/config/template/index.ts +++ b/packages/config/template/index.ts @@ -1,17 +1,17 @@ -import login from './login' -import register from './register' -import article from './article' -import linkage1 from './linkage1' -import linkage2 from './linkage2' -import linkage3 from './linkage3' -import linkage4 from './linkage4' -import linkage5 from './linkage5' -import formList from './formList' -import MostTest from './300Test' -import nest from './nest' import bugGood from './bugGood' import satisfaction from './satisfaction' import type { TemplateData } from '@vue-form-craft/types' +import login from './login' +import register from './register' +import formList from './formList' +import article from './article' +// import linkage1 from './linkage1' +// import linkage2 from './linkage2' +// import linkage3 from './linkage3' +// import linkage4 from './linkage4' +// import MostTest from './300Test' +// import nest from './nest' + export default [ { name: '登陆账号', schema: login, id: 'login' }, @@ -20,11 +20,10 @@ export default [ { name: '用户满意度调查', schema: satisfaction, id: 'satisfaction' }, { name: '写文章', schema: article, id: 'article' }, { name: '自增组件', schema: formList, id: 'formList' }, - { name: '联动案例1', schema: linkage1, id: 'linkage1' }, - { name: '联动案例2', schema: linkage2, id: 'linkage2' }, - { name: '联动案例3', schema: linkage3, id: 'linkage3' }, - { name: '联动案例4', schema: linkage4, id: 'linkage4' }, - { name: '联动案例5', schema: linkage5, id: 'linkage5' }, - { name: '大量表单项测试', schema: MostTest, id: 'MostTest' }, - { name: '容器嵌套', schema: nest, id: '容器嵌套' } + // { name: '联动案例1', schema: linkage1, id: 'linkage1' }, + // { name: '联动案例2', schema: linkage2, id: 'linkage2' }, + // { name: '联动案例3', schema: linkage3, id: 'linkage3' }, + // { name: '联动案例4', schema: linkage4, id: 'linkage4' }, + // { name: '大量表单项测试', schema: MostTest, id: 'MostTest' }, + // { name: '容器嵌套', schema: nest, id: '容器嵌套' } ] satisfies TemplateData diff --git a/packages/config/template/linkage5.ts b/packages/config/template/linkage5.ts deleted file mode 100644 index 7648b903..00000000 --- a/packages/config/template/linkage5.ts +++ /dev/null @@ -1,55 +0,0 @@ -import type { FormSchema } from "@vue-form-craft/types"; - -export default { - labelWidth: 150, - labelAlign: 'right', - size: 'default', - items: [ - { - label: '单选框组', - component: 'Radio', - props: { - mode: 'static', - options: [ - { - label: '选项1', - value: '1', - vv: '选1' - }, - { - label: '选项2', - value: '2', - vv: '选2' - }, - { - label: '选项3', - value: '3', - vv: '选3' - } - ], - labelKey: 'label', - valueKey: 'value', - optionType: 'circle', - direction: 'horizontal', - space: 20 - }, - designKey: 'design-ajDw', - name: 'A001', - change: [ - { - target: 'A002', - value: '{{ $selectData.A001.vv }}' - } - ] - }, - { - label: '单行文本', - component: 'Input', - props: { - placeholder: '请输入文本' - }, - designKey: 'design-WiKD', - name: 'A002' - } - ] -} satisfies FormSchema diff --git a/packages/config/template/satisfaction.ts b/packages/config/template/satisfaction.ts index 4b7f713e..524b9726 100644 --- a/packages/config/template/satisfaction.ts +++ b/packages/config/template/satisfaction.ts @@ -59,23 +59,23 @@ export default { options: [ { label: '非常满意', - value: 4 + value: 5 }, { label: '满意', - value: 3 + value: 4 }, { label: '一般', - value: 2 + value: 3 }, { label: '不满意', - value: 1 + value: 2 }, { label: '非常不满意', - value: 0 + value: 1 } ], labelKey: 'label', @@ -101,7 +101,7 @@ export default { }, designKey: 'form-improvementSuggestions', name: 'improvementSuggestions', - hidden: '{{ !$values.satisfaction || $values.satisfaction > 2 }}' + hidden: '{{ !$values.satisfaction || $values.satisfaction > 3 }}' }, { label: '联系方式', diff --git a/packages/config/vitest.config.ts b/packages/config/vitest.config.ts new file mode 100644 index 00000000..83a343d1 --- /dev/null +++ b/packages/config/vitest.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from 'vitest/config' +import rootConfig from '../../vitest.config' + +export default defineConfig({ + ...rootConfig +}) diff --git a/packages/form-render/__tests__/attrs.test.ts b/packages/form-render/__tests__/attrs.test.ts index cc3f36b1..0629be89 100644 --- a/packages/form-render/__tests__/attrs.test.ts +++ b/packages/form-render/__tests__/attrs.test.ts @@ -1,17 +1,11 @@ -import { mount, config, flushPromises } from '@vue/test-utils' +import { mount, flushPromises } from '@vue/test-utils' import { describe, it, expect } from 'vitest' -import ElementPlus from 'element-plus' import FormRender from '@vue-form-craft/form-render' import type { FormSchema } from '@vue-form-craft/types' -import { $options } from '@vue-form-craft/config' import { nextTick } from 'vue' +import { configTest } from '@vue-form-craft/utils' -config.global.plugins = [ElementPlus] -config.global.provide = { - [$options]: { - lang: 'zh' - } -} +configTest() const schema = { labelWidth: 150, @@ -114,7 +108,7 @@ describe('FormRender Attrs', () => { await wrapper.find('[name="password"]').setValue('991015') await wrapper.find('button[name="submit-btn"]').trigger('click') await flushPromises() - await nextTick(); + await nextTick() expect(wrapper.emitted()).toHaveProperty('finish') // 提交且校验成功 事件 // 重置按钮点击 diff --git a/packages/form-render/__tests__/schema.test.ts b/packages/form-render/__tests__/schema.test.ts index f77a66c5..3881aab0 100644 --- a/packages/form-render/__tests__/schema.test.ts +++ b/packages/form-render/__tests__/schema.test.ts @@ -1,17 +1,11 @@ -import { mount, config, flushPromises } from '@vue/test-utils' +import { mount, flushPromises } from '@vue/test-utils' import { describe, it, expect } from 'vitest' -import ElementPlus from 'element-plus' import FormRender from '@vue-form-craft/form-render' import type { FormSchema } from '@vue-form-craft/types' -import { $options } from '@vue-form-craft/config' -import { nextTick, ref } from 'vue' +import { ref } from 'vue' +import { configTest } from '@vue-form-craft/utils' -config.global.plugins = [ElementPlus] -config.global.provide = { - [$options]: { - lang: 'zh' - } -} +configTest() describe('FormRender Schema Test', () => { it('label', async () => { diff --git a/packages/utils/configTest.ts b/packages/utils/configTest.ts new file mode 100644 index 00000000..b9d5de9a --- /dev/null +++ b/packages/utils/configTest.ts @@ -0,0 +1,12 @@ +import { config } from '@vue/test-utils' +import ElementPlus from 'element-plus' +import { $options } from '@vue-form-craft/config' + +export default () => { + config.global.plugins = [ElementPlus] + config.global.provide = { + [$options]: { + lang: 'zh' + } + } +} diff --git a/packages/utils/index.ts b/packages/utils/index.ts index 59460f02..94c95f8b 100644 --- a/packages/utils/index.ts +++ b/packages/utils/index.ts @@ -5,5 +5,6 @@ export { default as getDataByPath } from './getDataByPath' export { default as setDataByPath } from './setDataByPath' export { default as isRegexString } from './isRegexString' export { default as recursionDelete } from './recursionDelete' +export { default as configTest } from './configTest' export { default as ns } from './ns' export * from './designUtils' \ No newline at end of file