Skip to content

Commit

Permalink
feat: some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Liberty-liu committed May 17, 2023
1 parent 25f446d commit 322b7f2
Show file tree
Hide file tree
Showing 74 changed files with 4,263 additions and 713 deletions.
38 changes: 20 additions & 18 deletions examples/views/formEditor/actionEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,26 @@ const getObjData = async () => {
}
}
const handleListener = async ({ type, data }) => {
if (type === 'submit') {
loading.value = true
try {
const postData = {
content: data
}
await hooks.useFetch(`${uri.obj}/${route.params.objid}/action${isEdit ? `/${route.params.actionid}` : '/create'}`, {
method: isEdit ? 'put' : 'post',
data: postData
})
ElMessage({
message: 'save successfully.',
type: 'success'
})
} finally {
loading.value = false
}
}
console.log(type)
console.log(data)
// if (type === 'submit') {
// loading.value = true
// try {
// const postData = {
// content: data
// }
// await hooks.useFetch(`${uri.obj}/${route.params.objid}/action${isEdit ? `/${route.params.actionid}` : '/create'}`, {
// method: isEdit ? 'put' : 'post',
// data: postData
// })
// ElMessage({
// message: 'save successfully.',
// type: 'success'
// })
// } finally {
// loading.value = false
// }
// }
}
onMounted(() => {
getObjData()
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
"lint-fix": "eslint --fix . --ext .js,.jsx,.vue",
"prepare": "husky install",
"init": "node ./server/db/generateDatabase.js && mkdir uploads",
"test": "vitest",
"coverage": "vitest run --coverage"
"test": "vitest"
},
"dependencies": {
"@vant/area-data": "^1.4.0",
Expand All @@ -47,9 +46,11 @@
"@vuelidate/validators": "^2.0.0",
"async": "^3.2.4",
"axios": "^1.2.2",
"canvas": "^2.11.2",
"dayjs": "^1.11.7",
"element-plus": "^2.2.28",
"everright-filter": "^0.0.21",
"hyperform": "^0.12.1",
"jsdom": "^22.0.0",
"jss": "^10.9.2",
"jss-preset-default": "^10.9.2",
Expand Down Expand Up @@ -89,6 +90,7 @@
"husky": "^8.0.3",
"lint-staged": "^13.1.2",
"nodemon": "^2.0.21",
"resize-observer-polyfill": "^1.5.1",
"sass": "^1.58.3",
"vite": "^3.2.5",
"vite-plugin-eslint": "^1.8.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/formEditor/components/CompleteButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ const handleClick = async (type) => {
console.log(e)
}
}
const dataset = process.env.NODE_ENV === 'test' ? { 'data-test': 'er-complete-button' } : {}
</script>
<template>
<div>
<div v-bind="dataset">
<div v-if="isPc" style="text-align: center;">
<el-button @click="handleClick" :color="state.config[state.platform].completeButton.backgroundColor" type="primary">
<span :style="{color: state.config[state.platform].completeButton.color }">{{ state.config[state.platform].completeButton.text }}</span>
Expand Down
12 changes: 10 additions & 2 deletions packages/formEditor/components/Layout/DragGable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,17 @@ export default defineComponent({
if (unref(isEditModel) || _.get(state.fieldsLogicState.get(element), 'visibility', undefined) !== 0) {
const typeProps = hooks.useProps(state, element, unref(isPc))
TypeComponent = load.findComponent('FormTypes', element.type)
const params = {
data: element,
parent: props.data
}
if (process.env.NODE_ENV === 'test') {
params['data-field-id'] = `${element.id}`
}
if (unref(isPc)) {
node = (
<Selection hasWidthScale hasCopy hasDel hasDrag hasMask data={element} parent={props.data}>
// <Selection hasWidthScale hasCopy hasDel hasDrag hasMask data={element} parent={props.data}>
<Selection hasWidthScale hasCopy hasDel hasDrag hasMask { ...params }>
{
element.type !== 'divider'
? (<el-form-item
Expand All @@ -164,7 +172,7 @@ export default defineComponent({
)
} else {
node = (
<Selection hasWidthScale hasCopy hasDel hasDrag hasMask data={element} parent={props.data}>
<Selection hasWidthScale hasCopy hasDel hasDrag hasMask { ...params }>
<TypeComponent data={element} params={typeProps.value}></TypeComponent>
</Selection>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const tabs = ref([
ifRefs: [],
thenRefs: []
}
// 暂时放弃,后期来做
// {
// label: '校验',
// value: 'validation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,122 +4,6 @@ const generateIfFilterOptionsData = (activeTab, fields) => {
options: [
],
operators: {
Text: [
{
label: '等于',
value: 'equal',
style: 'noop'
},
// {
// label: '等于其中之一',
// value: 'one_of',
// style: 'tags'
// },
{
label: '不等于',
value: 'not_equal',
style: 'noop'
},
{
label: '包含',
value: 'contains',
style: 'tags'
},
{
label: '不包含',
value: 'not_contain',
style: 'tags'
},
{
label: '为空',
value: 'empty',
style: 'none'
},
{
label: '不为空',
value: 'not_empty',
style: 'none'
}
],
Number: [
{
label: '等于',
value: 'equal',
style: 'noop'
},
{
label: '不等于',
value: 'not_equal',
style: 'noop'
},
{
label: '大于',
value: 'greater_than',
style: 'noop'
},
{
label: '大于等于',
value: 'greater_than_equal',
style: 'noop'
},
{
label: '小于',
value: 'less_than',
style: 'noop'
},
{
label: '小于等于',
value: 'less_than_equal',
style: 'noop'
},
{
label: '区间',
value: 'between',
style: 'range'
},
{
label: '为空',
value: 'empty',
style: 'none'
},
{
label: '不为空',
value: 'not_empty',
style: 'none'
}
],
Region: [
{
label: '等于其中之一',
value: 'one_of',
style: 'tags'
},
{
label: '不等于其中之一',
value: 'not_one_of',
style: 'tags'
},
{
label: '属于其中之一',
value: 'belong_one_of',
style: 'tags'
},
{
label: '不属于其中之一',
value: 'not_belong_one_of',
style: 'tags'
},
{
label: '为空',
value: 'empty',
style: 'none'
},
{
label: '不为空',
value: 'not_empty',
style: 'none'
}
]
}
}
fields.forEach((node) => {
Expand Down Expand Up @@ -262,6 +146,132 @@ const generateIfFilterOptionsData = (activeTab, fields) => {
}
break
}
if (!result.operators[filterNode.operatorKey]) {
switch (filterNode.operatorKey) {
case 'Text':
result.operators.Text = [
{
label: '等于',
value: 'equal',
style: 'noop'
},
// {
// label: '等于其中之一',
// value: 'one_of',
// style: 'tags'
// },
{
label: '不等于',
value: 'not_equal',
style: 'noop'
},
{
label: '包含',
value: 'contains',
style: 'tags'
},
{
label: '不包含',
value: 'not_contain',
style: 'tags'
},
{
label: '为空',
value: 'empty',
style: 'none'
},
{
label: '不为空',
value: 'not_empty',
style: 'none'
}
]
break
case 'Number':
result.operators.Number = [
{
label: '等于',
value: 'equal',
style: 'noop'
},
{
label: '不等于',
value: 'not_equal',
style: 'noop'
},
{
label: '大于',
value: 'greater_than',
style: 'noop'
},
{
label: '大于等于',
value: 'greater_than_equal',
style: 'noop'
},
{
label: '小于',
value: 'less_than',
style: 'noop'
},
{
label: '小于等于',
value: 'less_than_equal',
style: 'noop'
},
{
label: '区间',
value: 'between',
style: 'range'
},
{
label: '为空',
value: 'empty',
style: 'none'
},
{
label: '不为空',
value: 'not_empty',
style: 'none'
}
]
break
case 'Region':
result.operators.Number = [
{
label: '等于其中之一',
value: 'one_of',
style: 'tags'
},
{
label: '不等于其中之一',
value: 'not_one_of',
style: 'tags'
},
{
label: '属于其中之一',
value: 'belong_one_of',
style: 'tags'
},
{
label: '不属于其中之一',
value: 'not_belong_one_of',
style: 'tags'
},
{
label: '为空',
value: 'empty',
style: 'none'
},
{
label: '不为空',
value: 'not_empty',
style: 'none'
}
]
break
}
}
result.options.push(filterNode)
})
return result
Expand Down
Loading

0 comments on commit 322b7f2

Please sign in to comment.