fix: 测试计划,关联测试跳转问题,新建用例-编辑,无法给用例添加测试步骤,执行用例的时候,应允许编辑备注和附件,以及评论

This commit is contained in:
wenyann 2021-04-08 11:43:14 +08:00 committed by 刘瑞斌
parent 437c1e28bd
commit 491dd7fc27
5 changed files with 198 additions and 25 deletions

View File

@ -128,6 +128,12 @@ public class TestCaseController {
return testCaseService.edit(request, files);
}
@PostMapping(value = "/edit/testPlan", consumes = {"multipart/form-data"})
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public String editTestCaseByTestPlan(@RequestPart("request") EditTestCaseRequest request, @RequestPart(value = "file") List<MultipartFile> files) {
return testCaseService.editTestCase(request, files);
}
@PostMapping("/delete/{testCaseId}")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public int deleteTestCase(@PathVariable String testCaseId) {

View File

@ -91,7 +91,6 @@ public class TestCaseService {
TestCaseFileMapper testCaseFileMapper;
@Resource
TestCaseTestMapper testCaseTestMapper;
private void setNode(TestCaseWithBLOBs testCase){
if (StringUtils.isEmpty(testCase.getNodeId()) || "default-module".equals(testCase.getNodeId())) {
TestCaseNodeExample example = new TestCaseNodeExample();
@ -131,7 +130,6 @@ public class TestCaseService {
public int editTestCase(TestCaseWithBLOBs testCase) {
testCase.setUpdateTime(System.currentTimeMillis());
checkTestCaseExist(testCase);
return testCaseMapper.updateByPrimaryKeySelective(testCase);
}
@ -842,6 +840,44 @@ public class TestCaseService {
return request.getId();
}
public String editTestCase(EditTestCaseRequest request, List<MultipartFile> files) {
String testCaseId = testPlanTestCaseMapper.selectByPrimaryKey(request.getId()).getCaseId();
request.setId(testCaseId);
TestCaseWithBLOBs testCaseWithBLOBs = testCaseMapper.selectByPrimaryKey(testCaseId);
if (testCaseWithBLOBs == null) {
MSException.throwException(Translator.get("edit_load_test_not_found") + request.getId());
}
testCaseWithBLOBs.setRemark(request.getRemark());
// 新选择了一个文件删除原来的文件
List<FileMetadata> updatedFiles = request.getUpdatedFileList();
List<FileMetadata> originFiles = fileService.getFileMetadataByCaseId(testCaseId);
List<String> updatedFileIds = updatedFiles.stream().map(FileMetadata::getId).collect(Collectors.toList());
List<String> originFileIds = originFiles.stream().map(FileMetadata::getId).collect(Collectors.toList());
// 相减
List<String> deleteFileIds = ListUtils.subtract(originFileIds, updatedFileIds);
fileService.deleteFileRelatedByIds(deleteFileIds);
if (!CollectionUtils.isEmpty(deleteFileIds)) {
TestCaseFileExample testCaseFileExample = new TestCaseFileExample();
testCaseFileExample.createCriteria().andFileIdIn(deleteFileIds);
testCaseFileMapper.deleteByExample(testCaseFileExample);
}
if (files != null) {
files.forEach(file -> {
final FileMetadata fileMetadata = fileService.saveFile(file, testCaseWithBLOBs.getProjectId());
TestCaseFile testCaseFile = new TestCaseFile();
testCaseFile.setFileId(fileMetadata.getId());
testCaseFile.setCaseId(testCaseId);
testCaseFileMapper.insert(testCaseFile);
});
}
this.setNode(request);
editTestCase(request);
return request.getId();
}
public List<TestCaseDTO> listTestCaseIds(QueryTestCaseRequest request) {
List<OrderRequest> orderList = ServiceUtils.getDefaultOrder(request.getOrders());
OrderRequest order = new OrderRequest();

View File

@ -221,6 +221,10 @@
}
},
created() {
let dataRange = this.$route.params.dataSelectRange;
if (dataRange.length > 0) {
this.activeDom = 'middle';
}
if (this.activeDom === 'left') {
getLabel(this, API_LIST);
} else if (this.activeDom === 'right') {

View File

@ -661,7 +661,11 @@ export default {
Object.assign(tmp, testCase);
tmp.steps = JSON.parse(testCase.steps);
if (tmp.steps == null) {
tmp.steps = []
tmp.steps = [{
num: 1,
desc: '',
result: ''
}];
}
tmp.tags = JSON.parse(tmp.tags);
Object.assign(this.form, tmp);

View File

@ -291,31 +291,46 @@
</el-row>
<el-row>
<el-col :span="15" :offset="1">
<el-col :span="20" :offset="1">
<!-- <div>
<span class="cast_label">{{ $t('commons.remark') }}</span>
<span v-if="testCase.remark == null || testCase.remark === ''"
style="color: darkgrey">{{ $t('commons.not_filled') }}</span>
</div>-->
<span class="cast_label">{{ $t('commons.remark') }}</span>
<div>
<span class="cast_label">{{ $t('commons.remark') }}</span>
<span v-if="testCase.remark == null || testCase.remark === ''"
style="color: darkgrey">{{ $t('commons.not_filled') }}</span>
</div>
<div>
<el-input :rows="3"
<el-input v-model="testCase.remark"
:autosize="{ minRows: 2, maxRows: 4}"
type="textarea"
v-if="testCase.remark"
disabled
v-model="testCase.remark"></el-input>
:rows="3"
:placeholder="$t('commons.input_content')"></el-input>
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="15" :offset="1">
<div>
<span class="cast_label">{{ $t('test_track.case.attachment') }}:</span>
</div>
<el-col :span="20" :offset="1">
<span class="cast_label">{{ $t('test_track.case.attachment') }}</span>
<el-upload
accept=".jpg,.jpeg,.png,.xlsx,.doc,.pdf,.docx"
action=""
:show-file-list="false"
:before-upload="beforeUpload"
:http-request="handleUpload"
:on-exceed="handleExceed"
multiple
:limit="8"
:file-list="fileList">
<el-button icon="el-icon-plus" size="mini"></el-button>
<span slot="tip" class="el-upload__tip"> {{ $t('test_track.case.upload_tip') }} </span>
</el-upload>
</el-col>
</el-row>
<el-row>
<el-col :span="20" :offset="1">
<div>
<test-case-attachment :table-data="tableData"
:read-only="isReadOnly"
:is-delete="false"
:is-delete="true"
@handleDelete="handleDelete"
/>
</div>
@ -327,7 +342,16 @@
</el-card>
</el-col>
<el-col :span="7">
<case-comment :case-id="testCase ? testCase.caseId : ''" class="comment-card"/>
<el-card class="comment-card">
<template slot="header">
<span style="font-size: 15px; color: #1E90FF">{{ $t('test_track.review.comment') }}</span>
<i class="el-icon-refresh" @click="getComments(testCase)"
style="margin-left:10px;font-size: 14px; cursor: pointer"/>
</template>
<review-comment :comments="comments" :case-id="testCase.caseId" :review-id="testCase.reviewId"
@getComments="getComments"/>
</el-card>
<!-- <case-comment :case-id="testCase ? testCase.caseId : ''" class="comment-card"/>-->
</el-col>
@ -353,10 +377,12 @@ import {getUUID, listenGoBack, removeGoBackListener} from "@/common/js/utils";
import TestCaseAttachment from "@/business/components/track/case/components/TestCaseAttachment";
import CaseComment from "@/business/components/track/case/components/CaseComment";
import MsPreviousNextButton from "../../../../../common/components/MsPreviousNextButton";
import ReviewComment from "@/business/components/track/review/commom/ReviewComment";
export default {
name: "FunctionalTestCaseEdit",
components: {
ReviewComment,
MsPreviousNextButton,
CaseComment,
PerformanceTestResult,
@ -391,6 +417,9 @@ export default {
hasTapdId: false,
hasZentaoId: false,
tableData: [],
fileList: [],
uploadList: [],
comments: [],
};
},
props: {
@ -405,7 +434,55 @@ export default {
default: false
}
},
computed: {
projectId() {
return this.$store.state.projectId;
},
},
methods: {
getComments(testCase) {
let id = '';
if (testCase) {
id = testCase.caseId;
} else {
id = this.testCase.caseId;
}
this.result = this.$get('/test/case/comment/list/' + id, res => {
this.comments = res.data;
})
},
fileValidator(file) {
/// todo:
return file.size > 0;
},
handleExceed() {
this.$error(this.$t('load_test.file_size_limit'));
},
beforeUpload(file) {
if (!this.fileValidator(file)) {
/// todo:
return false;
}
if (this.tableData.filter(f => f.name === file.name).length > 0) {
this.$error(this.$t('load_test.delete_file') + ', name: ' + file.name);
return false;
}
let type = file.name.substring(file.name.lastIndexOf(".") + 1);
this.tableData.push({
name: file.name,
size: file.size + ' Bytes', /// todo: ByteKBMB
type: type.toUpperCase(),
updateTime: new Date().getTime(),
});
return true;
},
handleUpload(uploadResources) {
this.uploadList.push(uploadResources.file);
},
handleClose() {
removeGoBackListener(this.handleClose);
this.showDialog = false;
@ -420,12 +497,38 @@ export default {
this.testCase.status = status;
this.saveCase();
},
getOption(param) {
let formData = new FormData();
let url = '/test/case/edit/testPlan';
this.uploadList.forEach(f => {
formData.append("file", f);
});
param.updatedFileList = this.fileList;
let requestJson = JSON.stringify(param, function (key, value) {
return key === "file" ? undefined : value;
});
formData.append('request', new Blob([requestJson], {
type: "application/json "
}));
return {
method: 'POST',
url: url,
data: formData,
headers: {
'Content-Type': undefined;
}
};
},
saveCase() {
let param = {};
param.id = this.testCase.id;
param.status = this.testCase.status;
param.results = [];
param.remark = this.testCase.remark;
param.projectId = this.projectId;
let option = this.getOption(param);
for (let i = 0; i < this.testCase.steptResults.length; i++) {
let result = {};
result.actualResult = this.testCase.steptResults[i].actualResult;
@ -437,9 +540,11 @@ export default {
}
param.results.push(result);
}
param.results = JSON.stringify(param.results);
this.$post('/test/plan/case/edit', param, () => {
this.$request(option, (response) => {
});
this.$success(this.$t('commons.save_success'));
this.updateTestCases(param);
this.setPlanStatus(this.testCase.planId);
@ -495,15 +600,18 @@ export default {
this.getIssues(item.caseId);
this.stepResultChange();
this.getFileMetaData(item);
this.getComments(item);
})
},
getFileMetaData(testCase) {
this.fileList = [];
this.tableData = [];
this.result = this.$get("test/case/file/metadata/" + testCase.caseId, response => {
let files = response.data;
if (!files) {
return;
}
this.fileList = JSON.parse(JSON.stringify(files));
this.tableData = JSON.parse(JSON.stringify(files));
this.tableData.map(f => {
f.size = f.size + ' Bytes';
@ -699,9 +807,24 @@ export default {
this.$success(this.$t('commons.delete_success'));
})
},
handleDelete() {
}
handleDelete(file, index) {
this.$alert(this.$t('load_test.delete_file_confirm') + file.name + "", '', {
confirmButtonText: this.$t('commons.confirm'),
callback: (action) => {
if (action === 'confirm') {
this._handleDelete(file, index);
}
}
});
},
_handleDelete(file, index) {
this.fileList.splice(index, 1);
this.tableData.splice(index, 1);
let i = this.uploadList.findIndex(upLoadFile => upLoadFile.name === file.name);
if (i > -1) {
this.uploadList.splice(i, 1);
}
},
}
}
</script>