提交 52b1a23b 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

load scripts by zentao modules

上级 b9bcbe49
......@@ -92,12 +92,12 @@ type ZtfCaseWrapper struct {
}
type ZtfStep struct {
Id string
Id int
Desc string
Expect string
Type string
Parent string
Parent int
Children []ZtfStep
Numb string
......
......@@ -2,6 +2,7 @@ package scriptHelper
import (
"encoding/json"
"fmt"
commConsts "github.com/easysoft/zentaoatf/internal/comm/consts"
commDomain "github.com/easysoft/zentaoatf/internal/comm/domain"
langHelper "github.com/easysoft/zentaoatf/internal/comm/helper/lang"
......@@ -95,13 +96,13 @@ func loadScriptNodesInDir(folder string, parent *serverDomain.TestAsset, level i
caseId, _ := strconv.Atoi(caseIdStr)
if scriptIdsFromZentao == nil || caseId < 1 { // not to filter
AddScript(childPath, caseId, parent)
AddScript(childPath, caseId, "", false, parent)
continue
}
_, ok := scriptIdsFromZentao[caseId]
if ok {
AddScript(childPath, caseId, parent)
AddScript(childPath, caseId, "", false, parent)
}
}
}
......@@ -155,31 +156,49 @@ func LoadScriptListInDir(path string, files *[]string, level int) error {
return nil
}
func AddScript(pth string, caseId int, parent *serverDomain.TestAsset) {
func AddScript(pth string, caseId int, caseNameInZentao string, showZentaoCaseWithNoScript bool, parent *serverDomain.TestAsset) {
title := caseNameInZentao
if pth != "" {
//title = fileUtils.GetFileName(pth)
} else {
pth = fmt.Sprintf("zentao-%d", caseId)
}
childScript := &serverDomain.TestAsset{
Type: commConsts.File,
CaseId: caseId,
WorkspaceId: parent.WorkspaceId,
WorkspaceType: parent.WorkspaceType,
Path: pth,
Title: title,
Slots: iris.Map{"icon": "icon"},
Checkable: true,
IsLeaf: true,
}
if showZentaoCaseWithNoScript {
parent.Children = append(parent.Children, childScript)
parent.ScriptCount += 1
return
}
regx := langHelper.GetSupportLanguageExtRegx()
pass, _ := regexp.MatchString("^*.\\."+regx+"$", pth)
langPass, _ := regexp.MatchString("^*.\\."+regx+"$", pth)
if pass {
pass = CheckFileIsScript(pth)
if pass {
childScript := &serverDomain.TestAsset{
Type: commConsts.File,
CaseId: caseId,
WorkspaceId: parent.WorkspaceId,
WorkspaceType: parent.WorkspaceType,
Path: pth,
Title: fileUtils.GetFileName(pth),
Slots: iris.Map{"icon": "icon"},
Checkable: true,
IsLeaf: true,
}
if !langPass {
return
}
parent.Children = append(parent.Children, childScript)
parent.ScriptCount += 1
}
contentOk := CheckFileIsScript(pth)
if !contentOk {
return
}
parent.Children = append(parent.Children, childScript)
parent.ScriptCount += 1
}
func AddDir(pth string, moduleName string, parent *serverDomain.TestAsset) (dirNode *serverDomain.TestAsset) {
nodeType := commConsts.Dir
......
......@@ -107,8 +107,8 @@ func generateTestStepAndScriptObsolete(testSteps []commDomain.ZtfStep, steps *[]
}
ts := testSteps[idx]
if ts.Parent == "0" && ts.Type != "group" { // flat step
currGroup = commDomain.ZtfStep{Id: "-1", Desc: "group", Children: make([]commDomain.ZtfStep, 0)}
if ts.Parent == 0 && ts.Type != "group" { // flat step
currGroup = commDomain.ZtfStep{Id: -1, Desc: "group", Children: make([]commDomain.ZtfStep, 0)}
currGroup.Children = append(currGroup.Children, ts)
idx++
......@@ -165,7 +165,7 @@ func generateTestStepAndScriptObsolete(testSteps []commDomain.ZtfStep, steps *[]
stepNumb := 1
// print nested steps, only one level
for _, group := range nestedSteps {
if group.Id == "-1" { // [group]
if group.Id == -1 { // [group]
*steps = append(*steps, fmt.Sprintf("\n[group]"))
for _, child := range group.Children {
......@@ -242,7 +242,7 @@ func generateTestStepAndScript(testSteps []commDomain.ZtfStep, steps *[]string,
func computerTestStepWidth(steps []commDomain.ZtfStep, stepSDisplayMaxWidth *int, stepWidth int) {
for _, ts := range steps {
length := len(ts.Id)
length := len(strconv.Itoa(ts.Id))
if length > *stepSDisplayMaxWidth {
*stepSDisplayMaxWidth = length
}
......
......@@ -86,19 +86,22 @@ func GetCaseById(baseUrl string, caseId int) (cs commDomain.ZtfCase) {
return
}
func LoadTestCasesAsTree(workspace model.Workspace, scriptIdsFromZentao map[int]string, productId int, config commDomain.WorkspaceConf) (
root serverDomain.TestAsset, err error) {
func LoadTestCasesInModuleTree(workspace model.Workspace, scriptIdsFromZentao map[int]string,
productId int, suiteId, taskId int, config commDomain.WorkspaceConf) (root serverDomain.TestAsset, err error) {
casesInDir, _ := scriptHelper.LoadScriptTreeByDir(workspace, scriptIdsFromZentao)
caseMapInDir := map[int]*serverDomain.TestAsset{}
genCaseMap(casesInDir, &caseMapInDir)
// scripts in workspace dir
scriptsInDir, _ := scriptHelper.LoadScriptTreeByDir(workspace, scriptIdsFromZentao)
scriptsMapInDir := map[int]*serverDomain.TestAsset{}
genScriptMap(scriptsInDir, &scriptsMapInDir)
casesFromZentao, err := LoadTestCases(productId, 0, 0, 0, config)
// cases in zentao by module
casesFromZentao, err := LoadTestCases(productId, 0, suiteId, taskId, config)
caseMapByModuleFromZentao := map[int][]commDomain.ZtfCase{}
for _, item := range casesFromZentao {
caseMapByModuleFromZentao[item.Module] = append(caseMapByModuleFromZentao[item.Module], item)
}
// modules in zentao
modules, err := LoadCaseModuleArr(uint(productId), config)
root = serverDomain.TestAsset{
......@@ -114,13 +117,13 @@ func LoadTestCasesAsTree(workspace model.Workspace, scriptIdsFromZentao map[int]
}
for _, item := range modules {
genModuleTreeWithCases(item, caseMapInDir, caseMapByModuleFromZentao, &root)
genModuleTreeWithCases(item, scriptsMapInDir, caseMapByModuleFromZentao, &root)
}
return
}
func genCaseMap(asset serverDomain.TestAsset, mp *map[int]*serverDomain.TestAsset) {
func genScriptMap(asset serverDomain.TestAsset, mp *map[int]*serverDomain.TestAsset) {
if asset.CaseId > 0 {
(*mp)[asset.CaseId] = &asset
}
......@@ -130,7 +133,7 @@ func genCaseMap(asset serverDomain.TestAsset, mp *map[int]*serverDomain.TestAsse
}
for _, child := range asset.Children {
genCaseMap(*child, mp)
genScriptMap(*child, mp)
}
return
......@@ -153,6 +156,7 @@ func genModuleTreeWithCases(moduleInterface interface{},
// add cases in module
for _, cs := range caseMapByModuleFromZentao[moduleId] {
caseId := cs.Id
caseNameInZentao := cs.Title
casePath := ""
// case info from dir
......@@ -161,7 +165,8 @@ func genModuleTreeWithCases(moduleInterface interface{},
casePath = casesMapInDir[caseId].Path
}
scriptHelper.AddScript(casePath, caseId, dirNode)
scriptHelper.AddScript(casePath, caseId, caseNameInZentao, true, dirNode)
logUtils.Infof("===", cs.Title)
}
if moduleMap["children"] == nil {
......
......@@ -10,6 +10,7 @@ import (
serverDomain "github.com/easysoft/zentaoatf/internal/server/modules/v1/domain"
"github.com/easysoft/zentaoatf/internal/server/modules/v1/service"
"github.com/kataras/iris/v12"
"strings"
)
type TestScriptCtrl struct {
......@@ -48,6 +49,11 @@ func (c *TestScriptCtrl) Get(ctx iris.Context) {
return
}
if strings.Index(scriptPath, "zentao") == 0 {
ctx.JSON(c.SuccessResp(""))
return
}
script, err := scriptHelper.GetScriptContent(scriptPath, workspaceId)
if err != nil {
ctx.JSON(c.ErrResp(commConsts.CommErr, err.Error()))
......
......@@ -45,7 +45,16 @@ func (s *TestScriptService) LoadTestScriptsBySiteProduct(
// for testing
site, _ := s.SiteService.Get(siteId)
config := configHelper.LoadBySite(site)
scriptsInDir, _ = zentaoHelper.LoadTestCasesAsTree(workspace, scriptIdsFromZentao, 1, config)
suiteId := 0
taskId := 0
if filerType == string(commConsts.FilterSuite) {
suiteId = filerValue
} else if filerType == string(commConsts.FilterTask) {
taskId = filerValue
}
scriptsInDir, _ = zentaoHelper.LoadTestCasesInModuleTree(workspace, scriptIdsFromZentao,
int(productId), suiteId, taskId, config)
} else {
scriptsInDir, _ = codeHelper.LoadCodeTree(workspace)
......
......@@ -55,7 +55,9 @@
@check="checkNode"
>
<template #title="slotProps">
{{slotProps.title !== 'all' ? slotProps.title : t('all')}}
<span :class="[{'no-script': noScript(slotProps.path)}]">
{{slotProps.title}}
</span>
</template>
</a-tree>
......@@ -433,6 +435,13 @@ export default defineComponent({
return arr
}
const noScript = (str) => {
if (str.indexOf('zentao') == 0) {
return true
}
return false
}
return {
t,
isWin,
......@@ -473,6 +482,7 @@ export default defineComponent({
fromVisible,
onSave,
onCancel,
noScript,
}
}
......@@ -493,6 +503,10 @@ export default defineComponent({
font-size: 16px;
}
}
.no-script {
color: #a9aeb4;
}
}
</style>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册