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

add textarea input for bug steps for user edit

上级 d4fbd987
......@@ -4,22 +4,16 @@ import (
"fmt"
"github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/service/script"
testingService "github.com/easysoft/zentaoatf/src/service/testing"
zentaoService "github.com/easysoft/zentaoatf/src/service/zentao"
"github.com/easysoft/zentaoatf/src/utils/common"
"github.com/easysoft/zentaoatf/src/utils/config"
constant "github.com/easysoft/zentaoatf/src/utils/const"
"github.com/easysoft/zentaoatf/src/utils/date"
"github.com/easysoft/zentaoatf/src/utils/file"
"github.com/easysoft/zentaoatf/src/utils/vari"
zentaoUtils "github.com/easysoft/zentaoatf/src/utils/zentao"
"os"
"strconv"
"strings"
"time"
)
func GenFromCmd(url string, entityType string, entityVal string, langType string, singleFile bool,
func GenerateScriptFromCmd(url string, entityType string, entityVal string, langType string, singleFile bool,
account string, password string) {
params := make(map[string]string)
......@@ -47,7 +41,7 @@ func GenFromCmd(url string, entityType string, entityVal string, langType string
}
if testcases != nil {
count, err := Generate(testcases, langType, singleFile, account, password)
count, err := scriptService.Generate(testcases, langType, singleFile, account, password)
if err == nil {
configUtils.SaveConfig("", url, params["entityType"], params["entityVal"],
productId, projectId, langType, singleFile,
......@@ -60,163 +54,3 @@ func GenFromCmd(url string, entityType string, entityVal string, langType string
}
}
}
func Generate(testcases []model.TestCase, langType string, singleFile bool,
account string, password string) (int, error) {
casePaths := make([]string, 0)
for _, cs := range testcases {
DealwithTestCase(cs, langType, singleFile, &casePaths)
}
testingService.GenSuite(casePaths)
return len(testcases), nil
}
func DealwithTestCase(cs model.TestCase, langType string, singleFile bool, casePaths *[]string) {
LangMap := scriptService.GetLangMap()
langs := ""
if LangMap[langType] == nil {
i := 0
for lang, _ := range LangMap {
if i > 0 {
langs += ", "
}
langs += lang
i++
}
fmt.Printf("only support languages %s \n", langs)
os.Exit(1)
}
caseId := cs.Id
caseInTaskId := cs.IdInTask
taskId := cs.TaskId
if caseInTaskId == "" {
caseInTaskId = "0"
}
caseTitle := cs.Title
scriptFile := fmt.Sprintf(constant.ScriptDir+"tc-%s.%s", caseId, LangMap[langType]["extName"])
if fileUtils.FileExist(scriptFile) {
scriptFile = fmt.Sprintf(constant.ScriptDir+"tc-%s.%s",
caseId+"-"+dateUtils.DateTimeStrLong(time.Now()), LangMap[langType]["extName"])
}
fileUtils.MkDirIfNeeded(vari.Prefer.WorkDir + constant.ScriptDir)
*casePaths = append(*casePaths, scriptFile)
scriptFullPath := vari.Prefer.WorkDir + scriptFile
steps := make([]string, 0)
expects := make([]string, 0)
srcCode := make([]string, 0)
steps = append(steps, "@开头的为含验证点的步骤")
temp := fmt.Sprintf("\n%sCODE: 此处编写操作步骤代码\n", LangMap[langType]["commentsTag"])
srcCode = append(srcCode, temp)
readme := zentaoUtils.ReadResData("res/template/readme.tpl") + "\n"
StepWidth := 20
stepDisplayMaxWidth := 0
ComputerTestStepWidth(cs.StepArr, &stepDisplayMaxWidth, StepWidth)
for _, ts := range cs.StepArr {
DealwithTestStep(ts, langType, StepWidth, &steps, &expects, &srcCode)
}
var expectsTxt string
if singleFile {
expectsTxt = strings.Join(expects, "\n")
} else {
expectFile := zentaoUtils.ScriptToExpectName(scriptFullPath)
expectsTxt = "@file\n"
fileUtils.WriteFile(expectFile, strings.Join(expects, "\n"))
}
path := fmt.Sprintf("res%stemplate%s", string(os.PathSeparator), string(os.PathSeparator))
template := zentaoUtils.ReadResData(path + langType + ".tpl")
content := fmt.Sprintf(template,
caseId, caseInTaskId, taskId, caseTitle,
strings.Join(steps, "\n"), expectsTxt,
readme,
strings.Join(srcCode, "\n"))
//fmt.Println(content)
fileUtils.WriteFile(scriptFullPath, content)
}
func ComputerTestStepWidth(steps []model.TestStep, stepSDisplayMaxWidth *int, stepWidth int) {
for _, ts := range steps {
length := len(ts.Id)
if length > *stepSDisplayMaxWidth {
*stepSDisplayMaxWidth = length
}
}
*stepSDisplayMaxWidth += stepWidth // prefix space and @step
}
func DealwithTestStep(ts model.TestStep, langType string, stepWidth int,
steps *[]string, expects *[]string, srcCode *[]string) {
LangMap := scriptService.GetLangMap()
isGroup := ts.Type == "group"
isCheckPoint := ts.Expect != ""
stepId := ts.Id
stepTitle := ts.Desc
stepExpect := ts.Expect
stepParent := ts.Parent
// 处理steps
preFixSpace := 3
if stepParent != "" && stepParent != "0" {
preFixSpace = 6
}
var stepType string
if isGroup {
stepType = "group"
} else {
stepType = "step"
}
stepIdent := stepType + stepId
if isCheckPoint {
stepIdent = "@" + stepIdent
}
postFixSpace := stepWidth - preFixSpace - len(stepIdent)
stepLine := fmt.Sprintf("%*s", preFixSpace, " ") + stepIdent
stepLine += fmt.Sprintf("%*s", postFixSpace, " ")
stepLine += stepTitle
*steps = append(*steps, stepLine)
// 处理expects
if isCheckPoint {
expectsLine := ""
expectsLine = "# " + stepIdent + " \n"
expectsLine += "CODE: " + "期望结果, 可以有多行\n"
*expects = append(*expects, expectsLine)
}
// 处理srcCode
if isCheckPoint {
codeLine := LangMap[langType]["printGrammar"]
codeLine += fmt.Sprintf(" %s %s: %s\n", LangMap[langType]["commentsTag"], stepIdent, stepExpect)
codeLine += LangMap[langType]["commentsTag"] + "CODE: 输出验证点实际结果\n"
*srcCode = append(*srcCode, codeLine)
}
}
......@@ -111,7 +111,7 @@ func main() {
genSet.Usage()
os.Exit(1)
} else {
action.GenFromCmd(zentaoUrl, entityType, entityVal, langType, singleFile, account, password)
action.GenerateScriptFromCmd(zentaoUrl, entityType, entityVal, langType, singleFile, account, password)
}
}
case "list":
......
......@@ -9,7 +9,7 @@ import (
func LoadTestAssets() ([]string, []string) {
config := config2.ReadCurrConfig()
ext := GetLangMap()[config.LangType]["extName"]
ext := GetSupportedScriptLang()[config.LangType]["extName"]
caseFiles := make([]string, 0)
suitesFiles := make([]string, 0)
......
package scriptService
import (
"fmt"
"github.com/easysoft/zentaoatf/src/model"
constant "github.com/easysoft/zentaoatf/src/utils/const"
dateUtils "github.com/easysoft/zentaoatf/src/utils/date"
fileUtils "github.com/easysoft/zentaoatf/src/utils/file"
"github.com/easysoft/zentaoatf/src/utils/vari"
zentaoUtils "github.com/easysoft/zentaoatf/src/utils/zentao"
"os"
"strings"
"time"
)
func Generate(testcases []model.TestCase, langType string, singleFile bool,
account string, password string) (int, error) {
casePaths := make([]string, 0)
for _, cs := range testcases {
GenerateTestCaseScrrpt(cs, langType, singleFile, &casePaths)
}
GenSuite(casePaths)
return len(testcases), nil
}
func GenerateTestCaseScrrpt(cs model.TestCase, langType string, singleFile bool, casePaths *[]string) {
LangMap := GetSupportedScriptLang()
langs := ""
if LangMap[langType] == nil {
i := 0
for lang, _ := range LangMap {
if i > 0 {
langs += ", "
}
langs += lang
i++
}
fmt.Printf("only support languages %s \n", langs)
os.Exit(1)
}
caseId := cs.Id
caseInTaskId := cs.IdInTask
taskId := cs.TaskId
if caseInTaskId == "" {
caseInTaskId = "0"
}
caseTitle := cs.Title
scriptFile := fmt.Sprintf(constant.ScriptDir+"tc-%s.%s", caseId, LangMap[langType]["extName"])
if fileUtils.FileExist(scriptFile) {
scriptFile = fmt.Sprintf(constant.ScriptDir+"tc-%s.%s",
caseId+"-"+dateUtils.DateTimeStrLong(time.Now()), LangMap[langType]["extName"])
}
fileUtils.MkDirIfNeeded(vari.Prefer.WorkDir + constant.ScriptDir)
*casePaths = append(*casePaths, scriptFile)
scriptFullPath := vari.Prefer.WorkDir + scriptFile
steps := make([]string, 0)
expects := make([]string, 0)
srcCode := make([]string, 0)
steps = append(steps, "@开头的为含验证点的步骤")
temp := fmt.Sprintf("\n%sCODE: 此处编写操作步骤代码\n", LangMap[langType]["commentsTag"])
srcCode = append(srcCode, temp)
readme := zentaoUtils.ReadResData("res/template/readme.tpl") + "\n"
StepWidth := 20
stepDisplayMaxWidth := 0
computerTestStepWidth(cs.StepArr, &stepDisplayMaxWidth, StepWidth)
for _, ts := range cs.StepArr {
GenerateTestStepScript(ts, langType, StepWidth, &steps, &expects, &srcCode)
}
var expectsTxt string
if singleFile {
expectsTxt = strings.Join(expects, "\n")
} else {
expectFile := zentaoUtils.ScriptToExpectName(scriptFullPath)
expectsTxt = "@file\n"
fileUtils.WriteFile(expectFile, strings.Join(expects, "\n"))
}
path := fmt.Sprintf("res%stemplate%s", string(os.PathSeparator), string(os.PathSeparator))
template := zentaoUtils.ReadResData(path + langType + ".tpl")
content := fmt.Sprintf(template,
caseId, caseInTaskId, taskId, caseTitle,
strings.Join(steps, "\n"), expectsTxt,
readme,
strings.Join(srcCode, "\n"))
//fmt.Println(content)
fileUtils.WriteFile(scriptFullPath, content)
}
func GenerateTestStepScript(ts model.TestStep, langType string, stepWidth int,
steps *[]string, expects *[]string, srcCode *[]string) {
LangMap := GetSupportedScriptLang()
isGroup := ts.Type == "group"
isCheckPoint := ts.Expect != ""
stepId := ts.Id
stepTitle := ts.Desc
stepExpect := ts.Expect
stepParent := ts.Parent
// 处理steps
preFixSpace := 3
if stepParent != "" && stepParent != "0" {
preFixSpace = 6
}
var stepType string
if isGroup {
stepType = "group"
} else {
stepType = "step"
}
stepIdent := stepType + stepId
if isCheckPoint {
stepIdent = "@" + stepIdent
}
postFixSpace := stepWidth - preFixSpace - len(stepIdent)
stepLine := fmt.Sprintf("%*s", preFixSpace, " ") + stepIdent
stepLine += fmt.Sprintf("%*s", postFixSpace, " ")
stepLine += stepTitle
*steps = append(*steps, stepLine)
// 处理expects
if isCheckPoint {
expectsLine := ""
expectsLine = "# " + stepIdent + " \n"
expectsLine += "CODE: " + "期望结果, 可以有多行\n"
*expects = append(*expects, expectsLine)
}
// 处理srcCode
if isCheckPoint {
codeLine := LangMap[langType]["printGrammar"]
codeLine += fmt.Sprintf(" %s %s: %s\n", LangMap[langType]["commentsTag"], stepIdent, stepExpect)
codeLine += LangMap[langType]["commentsTag"] + "CODE: 输出验证点实际结果\n"
*srcCode = append(*srcCode, codeLine)
}
}
func GenSuite(cases []string) {
str := strings.Join(cases, "\n")
fileUtils.WriteFile(vari.Prefer.WorkDir+constant.ScriptDir+"all."+constant.SuiteExt, str)
}
func computerTestStepWidth(steps []model.TestStep, stepSDisplayMaxWidth *int, stepWidth int) {
for _, ts := range steps {
length := len(ts.Id)
if length > *stepSDisplayMaxWidth {
*stepSDisplayMaxWidth = length
}
}
*stepSDisplayMaxWidth += stepWidth // prefix space and @step
}
......@@ -4,7 +4,7 @@ import "sync"
var LangMap map[string]map[string]string
func GetLangMap() map[string]map[string]string {
func GetSupportedScriptLang() map[string]map[string]string {
var once sync.Once
once.Do(func() {
LangMap = map[string]map[string]string{
......@@ -55,5 +55,5 @@ func GetLangMap() map[string]map[string]string {
}
func init() {
GetLangMap()
GetSupportedScriptLang()
}
......@@ -3,7 +3,7 @@ package testingService
import (
"github.com/easysoft/zentaoatf/src/model"
"github.com/easysoft/zentaoatf/src/utils/const"
i118Utils "github.com/easysoft/zentaoatf/src/utils/i118"
"github.com/easysoft/zentaoatf/src/utils/i118"
"github.com/easysoft/zentaoatf/src/utils/log"
"github.com/easysoft/zentaoatf/src/utils/string"
zentaoUtils "github.com/easysoft/zentaoatf/src/utils/zentao"
......
package testingService
import (
constant "github.com/easysoft/zentaoatf/src/utils/const"
"github.com/easysoft/zentaoatf/src/utils/file"
"github.com/easysoft/zentaoatf/src/utils/vari"
"strings"
)
func GenSuite(cases []string) {
str := strings.Join(cases, "\n")
fileUtils.WriteFile(vari.Prefer.WorkDir+constant.ScriptDir+"all."+constant.SuiteExt, str)
}
......@@ -2,8 +2,8 @@ package page
import (
"fmt"
"github.com/easysoft/zentaoatf/src/action"
"github.com/easysoft/zentaoatf/src/model"
scriptService "github.com/easysoft/zentaoatf/src/service/script"
zentaoService "github.com/easysoft/zentaoatf/src/service/zentao"
"github.com/easysoft/zentaoatf/src/ui"
"github.com/easysoft/zentaoatf/src/ui/widget"
......@@ -104,7 +104,7 @@ func InitImportPage() error {
submitInput := widget.NewButtonWidgetAutoWidth("submitInput", buttonX, 13, "Submit", ImportRequest)
ui.ViewMap["import"] = append(ui.ViewMap["import"], submitInput.Name())
ui.KeyBindsInput(ui.ViewMap["import"])
ui.AddEventForInputWidgets(ui.ViewMap["import"])
return nil
}
......@@ -162,7 +162,7 @@ func ImportRequest(g *gocui.Gui, v *gocui.View) error {
cases = zentaoService.ListCaseByTask(url, taskId)
}
count, err := action.Generate(cases, language, singleFile, account, password)
count, err := scriptService.Generate(cases, language, singleFile, account, password)
if err == nil {
configUtils.SaveConfig("", url, params["entityType"], params["entityVal"],
productIdInt, projectId, language, singleFile,
......
......@@ -51,7 +51,7 @@ func InitReportBugPage() error {
// steps
left = right + ui.Space
stepsWidth := pageWidth - left - ui.Space + x
stepsInput := widget.NewTextWidgetWithHeight("stepsInput", left, y, stepsWidth, pageHeight-2, bug.Steps)
stepsInput := widget.NewTextareaWidget("stepsInput", left, y, stepsWidth, pageHeight-2, bug.Steps)
stepsInput.Title = "Steps"
ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], stepsInput.Name())
......@@ -114,7 +114,7 @@ func InitReportBugPage() error {
buttonX+11, y, "Cancel", cancelReportBug)
ui.ViewMap["reportBug"] = append(ui.ViewMap["reportBug"], cancelReportBugInput.Name())
ui.KeyBindsInput(ui.ViewMap["reportBug"])
ui.AddEventForInputWidgets(ui.ViewMap["reportBug"])
return nil
}
......@@ -131,11 +131,11 @@ func reportBug(g *gocui.Gui, v *gocui.View) error {
title := strings.TrimSpace(titleView.Buffer())
stepsStr := strings.TrimSpace(stepsView.Buffer())
moduleStr := strings.TrimSpace(ui.GetSelectedLineVal(moduleView))
typeStr := strings.TrimSpace(ui.GetSelectedLineVal(typeView))
versionStr := strings.TrimSpace(ui.GetSelectedLineVal(versionView))
severityStr := strings.TrimSpace(ui.GetSelectedLineVal(severityView))
priorityStr := strings.TrimSpace(ui.GetSelectedLineVal(priorityView))
moduleStr := strings.TrimSpace(ui.GetSelectedRowVal(moduleView))
typeStr := strings.TrimSpace(ui.GetSelectedRowVal(typeView))
versionStr := strings.TrimSpace(ui.GetSelectedRowVal(versionView))
severityStr := strings.TrimSpace(ui.GetSelectedRowVal(severityView))
priorityStr := strings.TrimSpace(ui.GetSelectedRowVal(priorityView))
if title == "" {
v, _ := vari.Cui.View("reportBugMsg")
......@@ -166,7 +166,7 @@ func bugSelectFieldCheckEvent(filedValMap map[string]int) func(g *gocui.Gui, v *
g.SetCurrentView(name)
//line, _ := GetSelectedLine(v, ".*")
//line, _ := GetSelectedRow(v, ".*")
//line = strings.TrimSpace(line)
//
//zentaoUtils.SetBugField(name, line, filedValMap)
......
......@@ -38,7 +38,7 @@ func InitSwitchPage() error {
submitInput := widget.NewButtonWidgetAutoWidth("submitInput", buttonX, 4, "Switch", SwitchWorkDir)
ui.ViewMap["switch"] = append(ui.ViewMap["switch"], submitInput.Name())
ui.KeyBindsInput(ui.ViewMap["switch"])
ui.AddEventForInputWidgets(ui.ViewMap["switch"])
return nil
}
......
......@@ -40,8 +40,8 @@ func showRun(g *gocui.Gui, v *gocui.View) error {
ui.SupportScroll("panelCaseList")
ui.SupportScroll("panelCaseResult")
ui.SupportLineHighlight("panelResultList")
ui.SupportLineHighlight("panelCaseList")
ui.SupportRowHighlight("panelResultList")
ui.SupportRowHighlight("panelCaseList")
ui.AddLineSelectedEvent("panelResultList", selectResultEvent)
ui.AddLineSelectedEvent("panelCaseList", selectCaseEvent)
......@@ -61,7 +61,7 @@ func selectResultEvent(g *gocui.Gui, v *gocui.View) error {
v.Highlight = true
line, _ := ui.GetSelectedLine(v, ".*")
line := ui.GetSelectedRowVal(v)
vari.CurrResultDate = line
content := make([]string, 0)
......@@ -90,7 +90,7 @@ func selectResultEvent(g *gocui.Gui, v *gocui.View) error {
func selectCaseEvent(g *gocui.Gui, v *gocui.View) error {
v.Highlight = true
caseLine, _ := ui.GetSelectedLine(v, ".*")
caseLine := ui.GetSelectedRowVal(v)
caseIdStr := strings.Split(caseLine, "-")[0]
caseId, _ := strconv.Atoi(caseIdStr)
vari.CurrCaseId = caseId
......
......@@ -12,15 +12,14 @@ const (
Space = 2
)
func KeyBindsInput(arr []string) {
func AddEventForInputWidgets(arr []string) {
for _, v := range arr {
if IsInput(v) {
AddEventForInputWidth(v)
if isInput(v) {
vari.Cui.SetKeybinding(v, gocui.MouseLeft, gocui.ModNone, SetCurrView(v))
}
}
}
func IsInput(v string) bool {
func isInput(v string) bool {
return strings.Index(v, "Input") > -1
}
......@@ -95,7 +94,7 @@ func scrollAction(v *gocui.View, dy int, isSelectWidget bool) error {
return nil
}
func SupportLineHighlight(name string) error {
func SupportRowHighlight(name string) error {
v, _ := vari.Cui.View(name)
v.Wrap = true
......@@ -123,13 +122,6 @@ func SetCurrView(name string) func(g *gocui.Gui, v *gocui.View) error {
}
}
func AddEventForInputWidth(name string) error {
if err := vari.Cui.SetKeybinding(name, gocui.MouseLeft, gocui.ModNone, SetCurrView(name)); err != nil {
return err
}
return nil
}
func HighlightTab(view string, views []string) {
for _, name := range views {
v, _ := vari.Cui.View(name)
......@@ -146,7 +138,12 @@ func HighlightTab(view string, views []string) {
}
}
func GetSelectedLine(v *gocui.View, reg string) (string, error) {
func GetSelectedRowVal(v *gocui.View) string {
line, _ := getSelectedRow(v, ".*")
return line
}
func getSelectedRow(v *gocui.View, reg string) (string, error) {
var line string
var err error
......@@ -164,9 +161,3 @@ func GetSelectedLine(v *gocui.View, reg string) (string, error) {
return line, nil
}
func GetSelectedLineVal(v *gocui.View) string {
line, _ := GetSelectedLine(v, ".*")
return line
}
......@@ -49,7 +49,7 @@ func (w *SelectWidget) Layout() (*gocui.View, error) {
v, _ := vari.Cui.SetView(w.name, w.x, w.y, w.x+w.w, w.y+w.h)
v.Highlight = true
ui.SupportScroll(w.name)
ui.SupportLineHighlight(w.name)
ui.SupportRowHighlight(w.name)
v.Title = w.title
......@@ -62,7 +62,7 @@ func (w *SelectWidget) Layout() (*gocui.View, error) {
_, height := v.Size()
for true {
line, _ := ui.GetSelectedLine(v, ".*")
line := ui.GetSelectedRowVal(v)
if w.defaultt != "" {
if line == w.defaultt {
break
......
......@@ -27,7 +27,7 @@ func NewTextWidget(name string, x, y, w int, text string) *gocui.View {
return v
}
func NewTextWidgetWithHeight(name string, x, y, w, h int, text string) *gocui.View {
func NewTextareaWidget(name string, x, y, w, h int, text string) *gocui.View {
widget := TextWidget{name: name, x: x, y: y, w: w, h: h, text: text}
v, _ := widget.Layout()
return v
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册