fix: validation is missing on the testsuite creation UI (#126)
This commit is contained in:
parent
581b6527ae
commit
7bd43cc4a5
|
@ -2,7 +2,7 @@
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { reactive, ref, watch } from 'vue'
|
import { reactive, ref, watch } from 'vue'
|
||||||
import { Edit } from '@element-plus/icons-vue'
|
import { Edit } from '@element-plus/icons-vue'
|
||||||
import type { FormInstance } from 'element-plus'
|
import type { FormInstance, FormRules } from 'element-plus'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -62,6 +62,12 @@ const testCaseForm = reactive({
|
||||||
name: "",
|
name: "",
|
||||||
api: "",
|
api: "",
|
||||||
})
|
})
|
||||||
|
const rules = reactive<FormRules<Suite>>({
|
||||||
|
name: [
|
||||||
|
{ required: true, message: 'Please input TestCase name', trigger: 'blur' },
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
function openNewTestCaseDialog() {
|
function openNewTestCaseDialog() {
|
||||||
loadTestSuites()
|
loadTestSuites()
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
|
@ -80,32 +86,36 @@ function loadTestSuites() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const submitForm = (formEl: FormInstance | undefined) => {
|
const submitForm = async (formEl: FormInstance | undefined) => {
|
||||||
if (!formEl) return
|
if (!formEl) return
|
||||||
suiteCreatingLoading.value = true
|
await formEl.validate((valid: boolean, fields) => {
|
||||||
|
if (valid) {
|
||||||
|
suiteCreatingLoading.value = true
|
||||||
|
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
suiteName: testCaseForm.suiteName,
|
suiteName: testCaseForm.suiteName,
|
||||||
data: {
|
data: {
|
||||||
name: testCaseForm.name,
|
name: testCaseForm.name,
|
||||||
request: {
|
request: {
|
||||||
api: testCaseForm.api,
|
api: testCaseForm.api,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch('/server.Runner/CreateTestCase', requestOptions)
|
fetch('/server.Runner/CreateTestCase', requestOptions)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
suiteCreatingLoading.value = false
|
suiteCreatingLoading.value = false
|
||||||
emit('updated', 'hello from child')
|
emit('updated', 'hello from child')
|
||||||
});
|
});
|
||||||
|
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function del() {
|
function del() {
|
||||||
|
@ -147,6 +157,8 @@ const testSuiteList = ref([])
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-form
|
<el-form
|
||||||
|
:rules="rules"
|
||||||
|
:model="testCaseForm"
|
||||||
ref="testcaseFormRef"
|
ref="testcaseFormRef"
|
||||||
status-icon
|
status-icon
|
||||||
label-width="120px"
|
label-width="120px"
|
||||||
|
|
|
@ -112,14 +112,16 @@ func (l *fileLoader) CreateSuite(name, api string) (err error) {
|
||||||
l.parent = path.Dir(absPath)
|
l.parent = path.Dir(absPath)
|
||||||
}
|
}
|
||||||
newSuiteFile := path.Join(l.parent, fmt.Sprintf("%s.yaml", name))
|
newSuiteFile := path.Join(l.parent, fmt.Sprintf("%s.yaml", name))
|
||||||
fmt.Println("new suite file:", newSuiteFile)
|
if newSuiteFile, err = filepath.Abs(newSuiteFile); err == nil {
|
||||||
|
fmt.Println("new suite file:", newSuiteFile)
|
||||||
|
|
||||||
suite := &TestSuite{
|
suite := &TestSuite{
|
||||||
Name: name,
|
Name: name,
|
||||||
API: api,
|
API: api,
|
||||||
}
|
}
|
||||||
if err = SaveTestSuiteToFile(suite, newSuiteFile); err == nil {
|
if err = SaveTestSuiteToFile(suite, newSuiteFile); err == nil {
|
||||||
l.Put(newSuiteFile)
|
l.Put(newSuiteFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue