Skip to content

Commit

Permalink
feat test
Browse files Browse the repository at this point in the history
  • Loading branch information
v_huyilin committed Nov 28, 2024
1 parent 9193f9a commit 0920773
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 100 deletions.
2 changes: 1 addition & 1 deletion packages/components/FormItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<el-form-item
v-else
:class="[ns('form-item'), thisProps.class]"
:class="[ns('form-item'), thisProps.class, `${component}-${name}`]"
:style="style"
:key="name"
:prop="name"
Expand Down
50 changes: 50 additions & 0 deletions packages/config/template/__test__/satisfaction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect, describe, it } from 'vitest'
import { configTest } from '@vue-form-craft/utils'
import { flushPromises, mount } from '@vue/test-utils'
import formRender from '@vue-form-craft/form-render'
import schema from '../satisfaction'
import { nextTick } from 'vue'

configTest()

describe('template satisfaction', async () => {
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)
})
})
35 changes: 17 additions & 18 deletions packages/config/template/index.ts
Original file line number Diff line number Diff line change
@@ -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' },
Expand All @@ -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
55 changes: 0 additions & 55 deletions packages/config/template/linkage5.ts

This file was deleted.

12 changes: 6 additions & 6 deletions packages/config/template/satisfaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -101,7 +101,7 @@ export default {
},
designKey: 'form-improvementSuggestions',
name: 'improvementSuggestions',
hidden: '{{ !$values.satisfaction || $values.satisfaction > 2 }}'
hidden: '{{ !$values.satisfaction || $values.satisfaction > 3 }}'
},
{
label: '联系方式',
Expand Down
6 changes: 6 additions & 0 deletions packages/config/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'vitest/config'
import rootConfig from '../../vitest.config'

export default defineConfig({
...rootConfig
})
14 changes: 4 additions & 10 deletions packages/form-render/__tests__/attrs.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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') // 提交且校验成功 事件

// 重置按钮点击
Expand Down
14 changes: 4 additions & 10 deletions packages/form-render/__tests__/schema.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/utils/configTest.ts
Original file line number Diff line number Diff line change
@@ -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'
}
}
}
1 change: 1 addition & 0 deletions packages/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 0920773

Please sign in to comment.