fix(测试跟踪): 用例中包含超长文本导出内容为空

--bug=1024670 --user=陈建星 【测试跟踪】功能用例-全选所有页-导出excel文件-文件为空 https://www.tapd.cn/55049933/s/1353684
This commit is contained in:
chenjianxing 2023-03-21 14:44:52 +08:00 committed by jianxing
parent e464791a14
commit e67e60c5e9
6 changed files with 45 additions and 36 deletions

View File

@ -225,10 +225,17 @@ export function downloadFile(method, url, data, fileName, processHandler) {
fileName = fileName.replaceAll("\"", "");
_downloadFile(fileName, res.data);
resolve();
})
.catch((e) => {
$error(e.message);
reject(e);
}).catch((e) => {
// 报错后,将 blob 格式转成字符串,打印错误信息
let reader = new FileReader();
reader.readAsText(e.response.data, 'utf-8');
reader.onload = function (e) {
if (reader.result) {
let info = JSON.parse(reader.result);
reject(info);
$error(info.message);
}
}
});
});
}

View File

@ -1724,6 +1724,7 @@ public class TestCaseService {
buildExportCustomField(customSelectValueMap, customNameMap, t, data, textFields);
buildExportOtherField(data, t, otherHeaders);
this.validateExportTextField(t);
if (CollectionUtils.isNotEmpty(stepDescList)) {
// 如果有多条步骤则添加多条数据之后合并单元格
buildExportMergeData(rowMergeInfo, list, stepDescList, stepResultList, data);
@ -1734,6 +1735,21 @@ public class TestCaseService {
return list;
}
private void validateExportTextField(TestCaseDTO data) {
List<String> textValues= Arrays.asList(data.getPrerequisite(), data.getStepDescription(), data.getExpectedResult(), data.getRemark());
for (String textValue : textValues) {
validateExportText(data.getName(), textValue);
}
}
private void validateExportText(String name, String textValue) {
// poi 导出的单个单元格最大字符数量为 32767 这里添加校验提示
int maxLength = 32767;
if (textValue.length() > maxLength) {
MSException.throwException(String.format(Translator.get("case_export_text_validate_tip"), name, maxLength));
}
}
private void buildExportOtherField(TestCaseExcelData data, TestCaseDTO t, List<TestCaseExportRequest.TestCaseExportHeader> otherHeaders) {
if (CollectionUtils.isEmpty(otherHeaders)) {
return;
@ -1800,6 +1816,7 @@ public class TestCaseService {
String id = field.getFieldId();
if (textFields.contains(id)) {
map.put(customNameMap.get(id), field.getTextValue());
this.validateExportText(data.getName(), field.getTextValue());
continue;
}
if (StringUtils.isNotBlank(field.getValue())) {

View File

@ -231,3 +231,4 @@ api_status_fake_error=FakeError
serial=Serial
parallel=Parallel
rerun_warning=The connection is abnormal, please check the environment configuration
case_export_text_validate_tip=Use case %s contains extremely long text, currently supported up to %s!

View File

@ -202,3 +202,4 @@ api_status_fake_error=误报
serial=串行
parallel=并行
rerun_warning=连接异常,请检查环境配置
case_export_text_validate_tip=用例 %s 包含超长文本,目前支持最大长度为 %s

View File

@ -202,3 +202,4 @@ api_status_fake_error=誤報
serial=串行
parallel=並行
rerun_warning=連接異常,請檢查環境配置
case_export_text_validate_tip=用例 %s 包含超長文本,目前支持最大長度為 %s

View File

@ -314,6 +314,7 @@ import TestCaseReviewStatusTableItem from "@/business/common/tableItems/TestCase
import RelateDemand from "@/business/case/components/RelateDemand";
import TestPlanCaseStatusTableItem from "@/business/common/tableItems/TestPlanCaseStatusTableItem";
import {
fileDownloadPost,
generateColumnKey,
getCustomFieldValueForTrack,
getProjectMemberOption
@ -1052,43 +1053,24 @@ export default {
}
let param = buildBatchParam(this, this.$refs.table.selectIds);
Object.assign(param, fieldParam);
let config = {};
let fileNameSuffix = "";
let fileNameSuffix;
let url;
if (exportType === 'xmind') {
config = {
url: '/test/case/export/testcase/xmind',
method: 'post',
responseType: 'blob',
data: param
};
url = '/test/case/export/testcase/xmind';
fileNameSuffix = ".xmind";
} else {
config = {
url: '/test/case/export/testcase',
method: 'post',
responseType: 'blob',
data: param
};
url = '/test/case/export/testcase'
fileNameSuffix = ".xlsx";
}
this.loading = true;
store.isTestCaseExporting = true;
this.$request(config).then(response => {
fileDownloadPost(url, param, "Metersphere_case_" + this.projectName + fileNameSuffix)
.then(() => {
this.loading = false;
const filename = "Metersphere_case_" + this.projectName + fileNameSuffix;
const blob = new Blob([response.data]);
if ("download" in document.createElement("a")) {
let aTag = document.createElement('a');
aTag.download = filename;
aTag.href = URL.createObjectURL(blob);
aTag.click();
URL.revokeObjectURL(aTag.href);
this.$emit('closeExport');
} else {
navigator.msSaveBlob(blob, filename);
this.$emit('closeExport');
}
store.isTestCaseExporting = false;
}).catch(() => {
this.loading = false;
store.isTestCaseExporting = false;
});
},