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

update to use new rest api

上级 eff96181
......@@ -8,79 +8,82 @@ import (
"time"
)
type ZtfRespTestCases struct {
Cases []ZtfCaseInModule `json:"testcases"`
}
type ZtfProduct struct {
Id string
Code string
Name string
Id int
//Code string
//Name string
Cases map[int]ZtfCaseInModule
Cases map[int]ZtfCaseInModule `json:"testcases"`
}
type ZtfModule struct {
Id string
Code string
Name string
Id int
Code string
Title string
Cases map[int]ZtfCaseInModule
}
type ZtfCaseInModule struct {
Id string
Id int
Title string
Product string
Module string
Product int
Module int
}
type ZtfSuite struct {
Id string
Id int
Code string
Name string
Product string
Product int
Cases map[int]ZtfCaseInSuite
}
type ZtfCaseInSuite struct {
Id string
Id int
Title string
Product string
Suite string
Module string
Product int
Suite int
Module int
}
type ZtfTask struct {
Id string
Id int
Code string
Name string
Product string
Project string
Product int
Project int
Runs map[int]ZtfCaseInTask
}
type ZtfCaseInTask struct {
Id string // runId in task
Id int // runId in task
Title string
Case string // real caseId
Product string
Module string
Case int // real caseId
Product int
Module int
}
type ZtfCaseNoStepArr struct {
Id string
Product string
Module string
Id int
Product int
Module int
Title string
Steps map[int]ZtfStep
}
type ZtfCase struct {
Id string
Product string
Module string
Id int
Product int
Module int
Title string
Steps map[int]ZtfStep
StepArr []ZtfStep `json tag -`
Title string
Steps []ZtfStep `json:"steps"`
}
type ZtfCaseWrapper struct {
From string
......
......@@ -42,20 +42,20 @@ func GenerateScript(cs commDomain.ZtfCase, langType string, independentFile bool
caseTitle := cs.Title
if byModule {
targetDir = filepath.Join(targetDir, moduleId)
targetDir = filepath.Join(targetDir, strconv.Itoa(moduleId))
}
fileUtils.MkDirIfNeeded(targetDir)
content := ""
isOldFormat := false
scriptFile := filepath.Join(targetDir, fmt.Sprintf("%s.%s", caseId, langUtils.LangMap[langType]["extName"]))
scriptFile := filepath.Join(targetDir, fmt.Sprintf("%d.%s", caseId, langUtils.LangMap[langType]["extName"]))
if fileUtils.FileExist(scriptFile) { // update title and steps
content = fileUtils.ReadFile(scriptFile)
isOldFormat = strings.Index(content, "[esac]") > -1
}
*caseIds = append(*caseIds, caseId)
*caseIds = append(*caseIds, strconv.Itoa(caseId))
info := make([]string, 0)
steps := make([]string, 0)
......@@ -69,12 +69,12 @@ func GenerateScript(cs commDomain.ZtfCase, langType string, independentFile bool
StepWidth := 20
stepDisplayMaxWidth := 0
computerTestStepWidth(cs.StepArr, &stepDisplayMaxWidth, StepWidth)
computerTestStepWidth(cs.Steps, &stepDisplayMaxWidth, StepWidth)
if isOldFormat {
generateTestStepAndScriptObsolete(cs.StepArr, &steps, &independentExpects, independentFile)
generateTestStepAndScriptObsolete(cs.Steps, &steps, &independentExpects, independentFile)
} else {
generateTestStepAndScript(cs.StepArr, &steps, &independentExpects, independentFile)
generateTestStepAndScript(cs.Steps, &steps, &independentExpects, independentFile)
}
info = append(info, strings.Join(steps, "\n"))
......
......@@ -54,8 +54,7 @@ func GetCasesByModule(productId int, moduleId int, projectPath, scriptDir string
testcases := ListCaseByModule(config.Url, productId, moduleId)
zentaoCaseIdMap := map[int]string{}
for _, tc := range testcases {
id, _ := strconv.Atoi(tc.Id)
zentaoCaseIdMap[id] = ""
zentaoCaseIdMap[tc.Id] = ""
}
//commonUtils.ChangeScriptForDebug(&projectPath)
......@@ -77,8 +76,7 @@ func GetCasesBySuite(productId int, suiteId int, projectPath, scriptDir string)
caseIdMap := map[int]string{}
for _, tc := range testcases {
id, _ := strconv.Atoi(tc.Id)
caseIdMap[id] = ""
caseIdMap[tc.Id] = ""
}
//commonUtils.ChangeScriptForDebug(&projectPath)
......@@ -100,8 +98,7 @@ func GetCasesByTask(productId int, taskId int, projectPath, scriptDir string) (c
caseIdMap := map[int]string{}
for _, tc := range testcases {
id, _ := strconv.Atoi(tc.Id)
caseIdMap[id] = ""
caseIdMap[tc.Id] = ""
}
//commonUtils.ChangeScriptForDebug(&projectPath)
......@@ -110,38 +107,28 @@ func GetCasesByTask(productId int, taskId int, projectPath, scriptDir string) (c
return
}
func ListCaseByProduct(baseUrl string, productId int) []commDomain.ZtfCase {
// $productID=productId, $branch = '', $browseType = 'byModule', $param=moduleId,
// $orderBy='id_desc', $recTotal=0, $recPerPage=10000, $pageID=1)
params := ""
if commConsts.RequestType == commConsts.PathInfo {
params = fmt.Sprintf("%d--byModule-all-id_asc-0-10000-1", productId)
} else {
params = fmt.Sprintf("productID=%d&branch=&browseType=byModule&param=0&orderBy=id_desc&recTotal=0&recPerPage=10000", productId)
}
func ListCaseByProduct(baseUrl string, productId int) (caseArr []commDomain.ZtfCase) {
uri := fmt.Sprintf("/products/%d/testcases", productId)
url := GenApiUrl(uri, nil, baseUrl)
url := baseUrl + GenApiUriOld("testcase", "browse", params)
dataStr, err := httpUtils.Get(url)
if err != nil {
return
}
if err == nil {
var product commDomain.ZtfProduct
json.Unmarshal(dataStr, &product)
caseArr := make([]commDomain.ZtfCase, 0)
for _, cs := range product.Cases {
caseId := cs.Id
var cases commDomain.ZtfRespTestCases
json.Unmarshal(dataStr, &cases)
csWithSteps := GetCaseById(baseUrl, caseId)
stepArr := genCaseSteps(csWithSteps)
caseArr = append(caseArr, commDomain.ZtfCase{Id: caseId, Product: cs.Product, Module: cs.Module,
Title: cs.Title, StepArr: stepArr})
}
for _, cs := range cases.Cases {
caseId := cs.Id
return caseArr
csWithSteps := GetCaseById(baseUrl, caseId)
stepArr := genCaseSteps(csWithSteps)
caseArr = append(caseArr, commDomain.ZtfCase{Id: caseId, Product: cs.Product, Module: cs.Module,
Title: cs.Title, Steps: stepArr})
}
return nil
return caseArr
}
func ListCaseByModule(baseUrl string, productId, moduleId int) []commDomain.ZtfCase {
......@@ -171,7 +158,7 @@ func ListCaseByModule(baseUrl string, productId, moduleId int) []commDomain.ZtfC
stepArr := genCaseSteps(csWithSteps)
caseArr = append(caseArr, commDomain.ZtfCase{Id: caseId, Product: cs.Product, Module: cs.Module,
Title: cs.Title, StepArr: stepArr})
Title: cs.Title, Steps: stepArr})
}
return caseArr
......@@ -205,7 +192,7 @@ func ListCaseBySuite(baseUrl string, productId, suiteId int) []commDomain.ZtfCas
stepArr := genCaseSteps(csWithSteps)
caseArr = append(caseArr, commDomain.ZtfCase{Id: caseId, Product: cs.Product, Module: cs.Module,
Title: cs.Title, StepArr: stepArr})
Title: cs.Title, Steps: stepArr})
}
return caseArr
......@@ -240,7 +227,7 @@ func ListCaseByTask(baseUrl string, productId, taskId int) []commDomain.ZtfCase
stepArr := genCaseSteps(csWithSteps)
caseArr = append(caseArr, commDomain.ZtfCase{Id: caseId, Product: cs.Product, Module: cs.Module,
Title: cs.Title, StepArr: stepArr})
Title: cs.Title, Steps: stepArr})
}
return caseArr
......@@ -265,8 +252,8 @@ func genCaseSteps(csWithSteps commDomain.ZtfCase) (ret []commDomain.ZtfStep) {
return
}
func GetCaseById(baseUrl string, caseId string) (cs commDomain.ZtfCase) {
uri := fmt.Sprintf("/testcases/%s", caseId)
func GetCaseById(baseUrl string, caseId int) (cs commDomain.ZtfCase) {
uri := fmt.Sprintf("/testcases/%d", caseId)
url := GenApiUrl(uri, nil, baseUrl)
bytes, err := httpUtils.Get(url)
......
......@@ -36,29 +36,10 @@ func GetConfig(baseUrl string) (err error) {
commConsts.RequestType = requestType
commConsts.RequestFix, _ = json.Get("requestFix").String()
// check site path by calling login interface
uri := ""
if commConsts.RequestType == commConsts.PathInfo {
uri = "user-login.json"
} else {
uri = "index.php?m=user&f=login&t=json"
}
url = baseUrl + uri
bytes, err = httpUtils.Get(url)
if err != nil {
return
}
return
}
func Login(config commDomain.ProjectConf) (err error) {
err = GetConfig(config.Url)
if err != nil {
logUtils.Infof(i118Utils.Sprintf("fail_to_login"))
return
}
url := GenApiUrl("tokens", nil, config.Url)
params := map[string]string{
......
......@@ -10,7 +10,6 @@ import (
serverDomain "github.com/aaronchen2k/deeptest/internal/server/modules/v1/domain"
"github.com/ajg/form"
"github.com/fatih/color"
"github.com/yosssi/gohtml"
"io/ioutil"
"net/http"
"regexp"
......@@ -35,12 +34,13 @@ func Get(url string) (ret []byte, err error) {
}
resp, err := client.Do(req)
defer resp.Body.Close()
if err != nil {
logUtils.Infof(color.RedString("get request failed, error: %s.", err.Error()))
return
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
ret, err = ioutil.ReadAll(resp.Body)
if err != nil {
logUtils.Infof(color.RedString("read response failed, error ", err.Error()))
return
......@@ -48,36 +48,7 @@ func Get(url string) (ret []byte, err error) {
if commConsts.Verbose {
logUtils.Infof(i118Utils.Sprintf("request_response"))
logUtils.Infof(logUtils.ConvertUnicode(bodyBytes))
}
defer resp.Body.Close()
var zentaoResp serverDomain.ZentaoResp
err = json.Unmarshal(bodyBytes, &zentaoResp)
if err != nil {
if strings.Index(string(bodyBytes), "<html>") > -1 {
if commConsts.Verbose {
logUtils.Errorf(i118Utils.Sprintf("request_response") + " HTML - " + gohtml.FormatWithLineNo(string(bodyBytes)))
}
return
} else {
if commConsts.Verbose {
logUtils.Infof(color.RedString("unmarshal response failed, error: %s.", err.Error()))
}
return
}
}
defer resp.Body.Close()
status := zentaoResp.Status
if status == "" { // 非嵌套结构
ret = bodyBytes
} else { // 嵌套结构
ret = []byte(zentaoResp.Data)
if status != "success" {
err = errors.New(zentaoResp.Data)
}
logUtils.Infof(logUtils.ConvertUnicode(ret))
}
return
......@@ -119,7 +90,8 @@ func Post(url string, data interface{}) (ret []byte, err error) {
return
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
ret, err = ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
logUtils.Infof(color.RedString("read response failed, error: %s.", err.Error()))
return
......@@ -127,13 +99,9 @@ func Post(url string, data interface{}) (ret []byte, err error) {
if commConsts.Verbose {
logUtils.Infof(i118Utils.Sprintf("request_response"))
logUtils.Infof(logUtils.ConvertUnicode(bodyBytes))
logUtils.Infof(logUtils.ConvertUnicode(ret))
}
defer resp.Body.Close()
ret, err = GetRespErr(bodyBytes, url)
return
}
......
......@@ -12,7 +12,6 @@ import (
logUtils "github.com/aaronchen2k/deeptest/internal/pkg/lib/log"
"github.com/fatih/color"
"path/filepath"
"strconv"
)
type SyncService struct {
......@@ -42,7 +41,7 @@ func (s *SyncService) SyncFromZentao(settings commDomain.SyncSettings, projectPa
cases, loginFail := s.TestCaseService.LoadTestCases(productId, moduleId, suiteId, taskId, projectPath)
if cases != nil && len(cases) > 0 {
productId, _ = strconv.Atoi(cases[0].Product)
productId = cases[0].Product
targetDir := fileUtils.AddPathSepIfNeeded(filepath.Join(projectPath, fmt.Sprintf("product%d", productId)))
count, err := s.TestScriptService.GenerateScripts(cases, lang, independentFile, byModule, targetDir)
......
......@@ -11,7 +11,6 @@
"svgo": "svgo -f src/assets/iconsvg --config=src/assets/iconsvg/svgo.yml"
},
"dependencies": {
"@highlightjs/vue-plugin": "2.0.1",
"@toast-ui/editor": "^2.5.3",
"ant-design-vue": "^2.2.8",
"axios": "^0.21.4",
......@@ -21,7 +20,6 @@
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"monaco-editor": "^0.25.2",
"monaco-editor-vue3": "^0.1.5",
"monaco-editor-webpack-plugin": "^6.0.0",
"neffos.js": "^0.1.25",
"nprogress": "^0.2.0",
......
<template>
<div class="monaco-editor-vue3" :style="style"></div>
</template>
<script>
import { defineComponent, computed, toRefs } from 'vue'
import * as monaco from 'monaco-editor'
export default defineComponent({
name: "MonacoEditor",
props: {
diffEditor: { type: Boolean, default: false },
width: {type: [String, Number], default: '100%'},
height: {type: [String, Number], default: '100%'},
original: String,
value: String,
language: {type: String, default: 'javascript'},
theme: {type: String, default: 'vs'},
options: {type: Object, default() {return {};}},
},
emits: [
'editorWillMount',
'editorDidMount',
'change'
],
setup(props){
const { width, height } = toRefs(props)
const style = computed(()=>{
const fixedWidth = width.value.toString().includes('%') ? width.value : `${width.value}px`
const fixedHeight = height.value.toString().includes('%')? height.value : `${height.value}px`
return {
width: fixedWidth,
height: fixedHeight,
'text-align': 'left'
}
})
return {
style
}
},
mounted() {
this.initMonaco()
},
beforeUnmount() {
this.editor && this.editor.dispose();
},
methods: {
initMonaco(){
this.$emit('editorWillMount', this.monaco)
const { value, language, theme, options } = this;
Object.assign(options, {scrollbar: {
useShadows: false,
verticalScrollbarSize: 6,
horizontalScrollbarSize: 6
}})
this.editor = monaco.editor[this.diffEditor ? 'createDiffEditor' : 'create'](this.$el, {
value: value,
language: language,
theme: theme,
...options
});
this.diffEditor && this._setModel(this.value, this.original);
// @event `change`
const editor = this._getEditor()
editor.onDidChangeModelContent(event => {
const value = editor.getValue()
if (this.value !== value) {
this.$emit('change', value, event)
}
})
this.$emit('editorDidMount', this.editor)
setTimeout(() => {
editor.getAction('editor.action.formatDocument').run()
}, 100)
},
_setModel(value, original) {
const { language } = this;
const originalModel = monaco.editor.createModel(original, language);
const modifiedModel = monaco.editor.createModel(value, language);
this.editor.setModel({
original: originalModel,
modified: modifiedModel
});
},
_setValue(value) {
let editor = this._getEditor();
if(editor) return editor.setValue(value);
},
_getValue() {
let editor = this._getEditor();
if(!editor) return '';
return editor.getValue();
},
_getEditor() {
if(!this.editor) return null;
return this.diffEditor ? this.editor.modifiedEditor : this.editor;
},
_setOriginal(){
const { original } = this.editor.getModel()
original.setValue(this.original)
}
},
watch: {
options: {
deep: true,
handler(options) {
this.editor.updateOptions(options);
}
},
value() {
this.value !== this._getValue() && this._setValue(this.value);
},
original() {
this._setOriginal()
},
language() {
if(!this.editor) return;
if(this.diffEditor){
const { original, modified } = this.editor.getModel();
monaco.editor.setModelLanguage(original, this.language);
monaco.editor.setModelLanguage(modified, this.language);
}else
monaco.editor.setModelLanguage(this.editor.getModel(), this.language);
},
theme() {
monaco.editor.setTheme(this.theme);
},
}
});
</script>
\ No newline at end of file
......@@ -38,4 +38,13 @@ export const AutoTestTools = [
'Appium',
'RobotFramework',
'Cypress',
]
\ No newline at end of file
]
export const MonacoOptions = {
colorDecorators: true,
lineHeight: 24,
tabSize: 2,
autoIndent: true,
formatOnPaste: true,
formatOnType: true
}
\ No newline at end of file
......@@ -50,6 +50,7 @@
class="editor"
:value="scriptCode"
:language="lang"
:options="editorOptions"
/>
</div>
</div>
......@@ -67,7 +68,8 @@ import {resizeWidth} from "@/utils/dom";
import {Empty, message, notification} from "ant-design-vue";
import {useI18n} from "vue-i18n";
import MonacoEditor from 'monaco-editor-vue3'
import {MonacoOptions} from "@/utils/const";
import MonacoEditor from "@/components/Editor/MonacoEditor.vue";
interface ListScriptPageSetupData {
t: (key: string | number) => string;
......@@ -75,9 +77,11 @@ interface ListScriptPageSetupData {
treeData: ComputedRef<any[]>;
replaceFields: any,
tree: Ref;
script: ComputedRef
scriptCode: Ref<string>;
lang: Ref<string>;
editorOptions: Ref
isExpand: Ref<boolean>;
expandNode: (expandedKeys: string[], e: any) => void;
......@@ -132,6 +136,7 @@ export default defineComponent({
let script = computed<any>(() => storeScript.state.script.detail);
let scriptCode = ref('')
let lang = ref('')
const editorOptions = ref(MonacoOptions)
onMounted(() => {
console.log('onMounted', tree)
......@@ -142,14 +147,8 @@ export default defineComponent({
console.log('expandNode', keys[0], e)
}
// let monacoInstance: any
// const disposeEditor = () => {
// console.log('disposeEditor')
// if (monacoInstance) monacoInstance.dispose();
// }
onUnmounted(() => {
console.log('onUnmounted', tree)
// disposeEditor()
})
const selectNode = (selectedKeys, e) => {
console.log('selectNode', e.selectedNodes)
......@@ -206,6 +205,7 @@ export default defineComponent({
script,
scriptCode,
lang,
editorOptions,
simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
}
}
......
......@@ -46,7 +46,6 @@ module.exports = {
},
chainWebpack(config) {
// 内置的 svg Rule 添加 exclude
config.module
.rule('svg')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册