feat(测试跟踪): 功能用例回收站关联版本的改动

This commit is contained in:
zhangdahai112 2022-01-18 20:16:45 +08:00 committed by song-tianyang
parent 0d05cd92d9
commit 27a30ab61b
9 changed files with 81 additions and 24 deletions

View File

@ -1,7 +1,5 @@
package io.metersphere.api.dto.automation;
import org.junit.internal.runners.statements.Fail;
public enum ScenarioStatus {
Saved, Success, Error, Timeout, Fail, Trash, Underway
}

View File

@ -134,4 +134,6 @@ public interface ExtTestCaseMapper {
String getLastExecStatusById(String id);
int countByWorkSpaceId(String workSpaceId);
long trashCount(@Param("projectId") String projectId);
}

View File

@ -865,7 +865,7 @@
status = original_status,
delete_user_id = null,
delete_time = null
where id in
where ref_id in
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
</foreach>
@ -898,4 +898,14 @@
and status != 'Trash'
</select>
<select id="trashCount" resultType="java.lang.Long">
SELECT
count(DISTINCT ref_id)
FROM
test_case
WHERE
project_id = #{projectId}
AND STATUS = 'Trash'
</select>
</mapper>

View File

@ -244,7 +244,7 @@ public class TestCaseController {
@MsAuditLog(module = "track_test_case", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#testCaseId)", msClass = TestCaseService.class)
public int deleteTestCase(@PathVariable String testCaseId) {
checkPermissionService.checkTestCaseOwner(testCaseId);
return testCaseService.deleteTestCase(testCaseId);
return testCaseService.deleteTestCaseBySameVersion(testCaseId);
}
@PostMapping("/deleteToGc/{testCaseId}")

View File

@ -774,9 +774,7 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
}
public long trashCount(String projectId) {
TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andProjectIdEqualTo(projectId).andStatusEqualTo("Trash");
return testCaseMapper.countByExample(testCaseExample);
return extTestCaseMapper.trashCount(projectId);
}
public void minderEdit(TestCaseMinderEditRequest request) {

View File

@ -9,6 +9,7 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.api.dto.automation.ScenarioStatus;
import io.metersphere.api.dto.definition.ApiTestCaseDTO;
import io.metersphere.api.dto.definition.ApiTestCaseRequest;
import io.metersphere.api.service.ApiAutomationService;
@ -491,6 +492,24 @@ public class TestCaseService {
return testCaseMapper.deleteByPrimaryKey(testCaseId);
}
public int deleteTestCaseBySameVersion(String testCaseId) {
TestCase testCase = testCaseMapper.selectByPrimaryKey(testCaseId);
if (testCase == null) {
return 0;
}
if (StringUtils.isNotBlank(testCase.getRefId())) {
TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andRefIdEqualTo(testCase.getRefId());
// 因为删除
List<String> sameVersionIds = testCaseMapper.selectByExample(testCaseExample).stream().map(TestCase::getId).collect(Collectors.toList());
AtomicInteger integer = new AtomicInteger(0);
sameVersionIds.forEach(id -> integer.getAndAdd(deleteTestCase(id)));
return integer.get();
} else {
return deleteTestCase(testCaseId);
}
}
private void deleteFollows(String testCaseId) {
TestCaseFollowExample example = new TestCaseFollowExample();
example.createCriteria().andCaseIdEqualTo(testCaseId);
@ -2082,8 +2101,14 @@ public class TestCaseService {
//检查原来模块是否还在
example = new TestCaseExample();
// 关联版本之后必须查询每一个数据的所有版本依次还原
example.createCriteria().andIdIn(request.getIds());
List<TestCase> reductionCaseList = testCaseMapper.selectByExample(example);
List<String> refIds = reductionCaseList.stream().map(TestCase::getRefId).collect(Collectors.toList());
example.clear();
example.createCriteria().andRefIdIn(refIds);
reductionCaseList = testCaseMapper.selectByExample(example);
request.setIds(reductionCaseList.stream().map(TestCase::getId).collect(Collectors.toList()));
Map<String, List<TestCase>> nodeMap = reductionCaseList.stream().collect(Collectors.groupingBy(TestCase::getNodeId));
for (Map.Entry<String, List<TestCase>> entry : nodeMap.entrySet()) {
String nodeId = entry.getKey();
@ -2383,6 +2408,13 @@ public class TestCaseService {
}
QueryTestCaseRequest request = new QueryTestCaseRequest();
request.setRefId(testCase.getRefId());
if (ScenarioStatus.Trash.name().equalsIgnoreCase(testCase.getStatus())) {
request.setFilters(new HashMap<String, List<String>>() {{
put("status", new ArrayList() {{
add(ScenarioStatus.Trash.name());
}});
}});
}
return this.listTestCase(request);
}

View File

@ -24,22 +24,29 @@
<ms-main-container>
<el-tabs v-model="activeName" @tab-click="addTab" @tab-remove="closeConfirm">
<el-tab-pane name="trash" v-if="trashEnable" :label="$t('commons.trash')">
<test-case-list
:checkRedirectID="checkRedirectID"
:isRedirectEdit="isRedirectEdit"
:tree-nodes="treeNodes"
:trash-enable="true"
@refreshTable="refresh"
@testCaseEdit="editTestCase"
@testCaseCopy="copyTestCase"
@testCaseDetail="showTestCaseDetail"
@getTrashList="getTrashList"
@getPublicList="getPublicList"
@refresh="refresh"
@refreshAll="refreshAll"
@setCondition="setCondition"
ref="testCaseTrashList">
</test-case-list>
<ms-tab-button
:isShowChangeButton="false">
<template v-slot:version>
<version-select v-xpack :project-id="projectId" @changeVersion="changeTrashVersion" margin-left="-10"/>
</template>
<test-case-list
:checkRedirectID="checkRedirectID"
:isRedirectEdit="isRedirectEdit"
:tree-nodes="treeNodes"
:trash-enable="true"
:current-version="currentTrashVersion"
@refreshTable="refresh"
@testCaseEdit="editTestCase"
@testCaseCopy="copyTestCase"
@testCaseDetail="showTestCaseDetail"
@getTrashList="getTrashList"
@getPublicList="getPublicList"
@refresh="refresh"
@refreshAll="refreshAll"
@setCondition="setCondition"
ref="testCaseTrashList">
</test-case-list>
</ms-tab-button>
</el-tab-pane>
<el-tab-pane name="public" v-if="publicEnable" :label="$t('project.case_public')">
<test-case-list
@ -230,6 +237,7 @@ export default {
publicTotal: 0,
tmpPath: null,
currentVersion: null,
currentTrashVersion: null,
};
},
mounted() {
@ -635,6 +643,9 @@ export default {
changeVersion(currentVersion) {
this.currentVersion = currentVersion || null;
},
changeTrashVersion(currentVersion) {
this.currentTrashVersion = currentVersion || null;
},
checkout(testCase, item) {
Object.assign(item.testCaseInfo, testCase)
// copy

View File

@ -540,6 +540,7 @@ export default {
this.$emit('testCaseEdit', testCase);
});
}
this.getVersionOptions();
},
activated() {
this.getTemplateField();
@ -728,7 +729,12 @@ export default {
this.condition.filters.priority = this.condition.filters['用例等级'];
this.condition.filters.status = this.condition.filters['用例状态'];
if (this.trashEnable) {
//
let versionIds = this.condition.filters.version_id;
this.condition.filters = {status: ["Trash"]};
if (versionIds) {
this.condition.filters.version_id = versionIds;
}
}
if (this.projectId) {
this.condition.projectId = this.projectId;

@ -1 +1 @@
Subproject commit 07b1946ae7473daf4f116deafd7af9d1a90aa199
Subproject commit 964acf775191a3243b1da5225352da8c1d998235