Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show executeTime and passRate in autotest-plan list #1684

Merged
merged 2 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions apistructs/testplan_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ import (
"github.com/pkg/errors"
)

// TODO: change name to AutoTestPlan
// TestPlanV2 testplan
type TestPlanV2 struct {
ZLValien marked this conversation as resolved.
Show resolved Hide resolved
ID uint64 `json:"id"`
Name string `json:"name"`
Desc string `json:"desc"`
ProjectID uint64 `json:"project"`
SpaceID uint64 `json:"spaceID"`
SpaceName string `json:"spaceName"`
Creator string `json:"creator"`
Owners []string `json:"owners"`
Updater string `json:"updater"`
Steps []*TestPlanV2Step `json:"steps"`
CreateAt *time.Time `json:"createAt"`
UpdateAt *time.Time `json:"updateAt"`
IsArchived bool `json:"isArchived"`
ID uint64 `json:"id"`
Name string `json:"name"`
Desc string `json:"desc"`
ProjectID uint64 `json:"project"`
SpaceID uint64 `json:"spaceID"`
SpaceName string `json:"spaceName"`
Creator string `json:"creator"`
Owners []string `json:"owners"`
Updater string `json:"updater"`
Steps []*TestPlanV2Step `json:"steps"`
CreateAt *time.Time `json:"createAt"`
UpdateAt *time.Time `json:"updateAt"`
IsArchived bool `json:"isArchived"`
PassRate float64 `json:"passRate"`
ExecuteTime *time.Time `json:"executeTime"`
}

// TestPlanV2CreateRequest testplan v2 create request
Expand Down Expand Up @@ -106,6 +109,10 @@ type TestPlanV2PagingRequest struct {
PageNo uint64 `schema:"pageNo"`
// +optional default 20
PageSize uint64 `schema:"pageSize"`
// +optional
OrderBy string `schema:"orderBy"`
// +optional order ascend
Asc bool `schema:"asc"`
// ids
IDs []uint64

Expand All @@ -117,6 +124,7 @@ func (tpr *TestPlanV2PagingRequest) UrlQueryString() map[string][]string {
query["pageNo"] = []string{strconv.FormatInt(int64(tpr.PageNo), 10)}
query["pageSize"] = []string{strconv.FormatInt(int64(tpr.PageSize), 10)}
query["projectID"] = []string{strconv.FormatInt(int64(tpr.ProjectID), 10)}
query["asc"] = []string{strconv.FormatBool(tpr.Asc)}
if tpr.Name != "" {
query["name"] = []string{tpr.Name}
}
Expand All @@ -135,6 +143,9 @@ func (tpr *TestPlanV2PagingRequest) UrlQueryString() map[string][]string {
if tpr.IsArchived != nil {
query["isArchived"] = []string{strconv.FormatBool(*tpr.IsArchived)}
}
if tpr.OrderBy != "" {
query["orderBy"] = []string{tpr.OrderBy}
}

return query
}
Expand Down
74 changes: 46 additions & 28 deletions modules/dop/dao/testplan_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package dao

import (
"time"

"github.com/jinzhu/gorm"
"github.com/pkg/errors"

Expand All @@ -26,13 +28,15 @@ import (
// TestPlanV2 测试计划V2
type TestPlanV2 struct {
dbengine.BaseModel
Name string
Desc string
CreatorID string
UpdaterID string
ProjectID uint64
SpaceID uint64
IsArchived bool
Name string
Desc string
CreatorID string
UpdaterID string
ProjectID uint64
SpaceID uint64
IsArchived bool
PassRate float64
ExecuteTime time.Time
}

// TableName table name
Expand All @@ -43,16 +47,18 @@ func (TestPlanV2) TableName() string {
// Convert2DTO convert DAO to DTO
func (tp *TestPlanV2) Convert2DTO() apistructs.TestPlanV2 {
return apistructs.TestPlanV2{
ID: tp.ID,
Name: tp.Name,
Desc: tp.Desc,
ProjectID: tp.ProjectID,
SpaceID: tp.SpaceID,
Creator: tp.CreatorID,
Updater: tp.UpdaterID,
Steps: []*apistructs.TestPlanV2Step{},
CreateAt: &tp.CreatedAt,
UpdateAt: &tp.UpdatedAt,
ID: tp.ID,
Name: tp.Name,
Desc: tp.Desc,
ProjectID: tp.ProjectID,
SpaceID: tp.SpaceID,
Creator: tp.CreatorID,
Updater: tp.UpdaterID,
Steps: []*apistructs.TestPlanV2Step{},
CreateAt: &tp.CreatedAt,
UpdateAt: &tp.UpdatedAt,
PassRate: tp.PassRate,
ExecuteTime: &tp.ExecuteTime,
}
}

Expand All @@ -65,16 +71,18 @@ type TestPlanV2Join struct {
// Convert2DTO convert DAO to DTO
func (tp *TestPlanV2Join) Convert2DTO() *apistructs.TestPlanV2 {
return &apistructs.TestPlanV2{
ID: tp.ID,
Name: tp.Name,
Desc: tp.Desc,
ProjectID: tp.ProjectID,
SpaceID: tp.SpaceID,
SpaceName: tp.SpaceName,
Creator: tp.CreatorID,
Updater: tp.UpdaterID,
Steps: []*apistructs.TestPlanV2Step{},
IsArchived: tp.IsArchived,
ID: tp.ID,
Name: tp.Name,
Desc: tp.Desc,
ProjectID: tp.ProjectID,
SpaceID: tp.SpaceID,
SpaceName: tp.SpaceName,
Creator: tp.CreatorID,
Updater: tp.UpdaterID,
Steps: []*apistructs.TestPlanV2Step{},
IsArchived: tp.IsArchived,
PassRate: tp.PassRate,
ExecuteTime: &tp.ExecuteTime,
}
}

Expand Down Expand Up @@ -121,6 +129,7 @@ func (client *DBClient) PagingTestPlanV2(req *apistructs.TestPlanV2PagingRequest
db := client.Table("dice_autotest_plan").Select("dice_autotest_plan.id, dice_autotest_plan.created_at, "+
"dice_autotest_plan.updated_at, dice_autotest_plan.name, dice_autotest_plan.desc, dice_autotest_plan.creator_id, "+
"dice_autotest_plan.updater_id, "+"dice_autotest_plan.project_id, dice_autotest_plan.space_id, "+
"dice_autotest_plan.pass_rate, "+"dice_autotest_plan.execute_time, "+
"dice_autotest_space.name as space_name, "+"dice_autotest_plan.is_archived").
Joins("inner join dice_autotest_space on dice_autotest_plan.space_id = dice_autotest_space.id").
Where("dice_autotest_plan.project_id = ?", req.ProjectID)
Expand All @@ -144,7 +153,16 @@ func (client *DBClient) PagingTestPlanV2(req *apistructs.TestPlanV2PagingRequest
db = db.Where("is_archived = ?", req.IsArchived)
}

if err := db.Order("created_at DESC").Offset((req.PageNo - 1) * req.PageSize).Limit(req.PageSize).Find(&testPlanJoins).Offset(0).Limit(-1).
orderStr := "created_at DESC"
if req.OrderBy != "" {
if req.Asc == true {
orderStr = req.OrderBy + " ASC, " + orderStr
} else {
orderStr = req.OrderBy + " DESC, " + orderStr
}
}

if err := db.Order(orderStr).Offset((req.PageNo - 1) * req.PageSize).Limit(req.PageSize).Find(&testPlanJoins).Offset(0).Limit(-1).
Count(&total).Error; err != nil {
return 0, nil, nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ func RenderCreator() protocol.CompRender {

type TableItem struct {
//Assignee map[string]string `json:"assignee"`
Id uint64 `json:"id"`
Name string `json:"name"`
Owners map[string]interface{} `json:"owners"`
TestSpace string `json:"testSpace"`
Operate Operate `json:"operate"`
Id uint64 `json:"id"`
Name string `json:"name"`
Owners map[string]interface{} `json:"owners"`
TestSpace string `json:"testSpace"`
Operate Operate `json:"operate"`
PassRate PassRate `json:"passRate"`
ExecuteTime string `json:"executeTime"`
}

type PassRate struct {
RenderType string `json:"renderType"`
Value float64 `json:"value"`
}

type Operate struct {
Expand All @@ -54,6 +61,16 @@ type OperationData struct {
} `json:"meta"`
}

type SortData struct {
Field string `json:"field"`
Order string `json:"order"`
}

const (
OrderAscend string = "ascend"
OrderDescend string = "descend"
)

func (tpmt *TestPlanManageTable) Render(ctx context.Context, c *apistructs.Component, scenario apistructs.ComponentProtocolScenario, event apistructs.ComponentEvent, gs *apistructs.GlobalStateData) error {
bdl := ctx.Value(protocol.GlobalInnerKeyCtxBundle.String()).(protocol.ContextBundle)
projectIDStr := fmt.Sprintf("%v", bdl.InParams["projectId"])
Expand Down Expand Up @@ -145,6 +162,11 @@ func (tpmt *TestPlanManageTable) Render(ctx context.Context, c *apistructs.Compo
}
cond.IsArchived = &isArchive
}
// orderBy and ASC
err = convertSortData(&cond, c)
if err != nil {
return err
}

r, err := bdl.Bdl.PagingTestPlansV2(cond)
if err != nil {
Expand All @@ -166,6 +188,11 @@ func (tpmt *TestPlanManageTable) Render(ctx context.Context, c *apistructs.Compo
RenderType: "tableOperation",
Operations: map[string]interface{}{},
},
PassRate: PassRate{
RenderType: "progress",
Value: data.PassRate,
},
ExecuteTime: data.ExecuteTime.Format("2006-01-02 15:04:05"),
}
if data.IsArchived == true {
item.Operate.Operations["archive"] = map[string]interface{}{
Expand Down Expand Up @@ -206,6 +233,36 @@ func (tpmt *TestPlanManageTable) Render(ctx context.Context, c *apistructs.Compo
return nil
}

func convertSortData(req *apistructs.TestPlanV2PagingRequest, c *apistructs.Component) error {
if _, ok := c.State["sorterData"]; !ok {
return nil
}
var sortData SortData
sortDataByte, err := json.Marshal(c.State["sorterData"])
if err != nil {
return err
}
err = json.Unmarshal(sortDataByte, &sortData)
if err != nil {
return err
}

if sortData.Field == "passRate" {
sortData.Field = "pass_rate"
} else if sortData.Field == "executeTime" {
sortData.Field = "execute_time"
}

req.OrderBy = sortData.Field
if sortData.Order == OrderAscend {
req.Asc = true
} else if sortData.Order == OrderDescend {
req.Asc = false
}

return nil
}

// TODO:
// 1.创建更新完测试计划,要返回更新后的数据 (组件数据传递)
// 2.分页
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package table

import (
"testing"

"github.com/alecthomas/assert"

"github.com/erda-project/erda/apistructs"
)

func Test_ConvertSortData(t *testing.T) {
req := apistructs.TestPlanV2PagingRequest{}
c := &apistructs.Component{
State: map[string]interface{}{
"sorterData": SortData{
Field: "passRate",
Order: OrderAscend,
},
},
}
err := convertSortData(&req, c)
assert.NoError(t, err)
want := apistructs.TestPlanV2PagingRequest{
OrderBy: "pass_rate",
Asc: true,
}
assert.Equal(t, want, req)

c = &apistructs.Component{
State: map[string]interface{}{
"sorterData": SortData{
Field: "executeTime",
Order: OrderDescend,
},
},
}
err = convertSortData(&req, c)
assert.NoError(t, err)
want = apistructs.TestPlanV2PagingRequest{
OrderBy: "execute_time",
Asc: false,
}
assert.Equal(t, want, req)
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ rendering:
- name: "addTest"
value: "{{ addButton.addTest }}"
# 组件
#TODO: add i18n
components:
autoTestPlan:
type: "Container"
Expand Down Expand Up @@ -75,6 +76,9 @@ components:
key: "goto"
target: "project_test_autoTestPlanDetail"
jumpOut: false
changeSort:
key: "changeSort"
reload: true
props:
rowKey: "id"
columns:
Expand All @@ -86,6 +90,14 @@ components:
dataIndex: "testSpace"
- title: "负责人"
dataIndex: "owners"
- title: "最近执行通过率"
ZLValien marked this conversation as resolved.
Show resolved Hide resolved
dataIndex: "passRate"
width: 180
sorter: true
- title: "最近执行时间"
dataIndex: "executeTime"
width: 180
sorter: true
- title: "操作"
dataIndex: "operate"
width: 150
Expand Down