fix(测试用例): 处理导出富文本内容格式

This commit is contained in:
WangXu10 2024-08-16 11:14:43 +08:00 committed by Craftsman
parent b783cc4420
commit 24a6a1ea70
2 changed files with 28 additions and 12 deletions

View File

@ -77,6 +77,8 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@ -610,8 +612,10 @@ public class FunctionalCaseFileService {
// 如果有多条步骤则添加多条数据之后合并单元格
buildExportMergeData(rowMergeInfo, list, textDescriptionList, expectedResultList, data);
} else {
data.setTextDescription(parseData(textDescriptionList));
data.setExpectedResult(parseData(expectedResultList));
if (CollectionUtils.isNotEmpty(textDescriptionList)) {
data.setTextDescription(parseData(textDescriptionList));
data.setExpectedResult(parseData(expectedResultList));
}
list.add(data);
}
});
@ -646,7 +650,7 @@ public class FunctionalCaseFileService {
data.setModule(moduleMap.get(functionalCase.getModuleId()));
//构建步骤
buildExportStep(data, functionalCaseBlob, functionalCase.getCaseEditType(), textDescriptionList, expectedResultList);
data.setPrerequisite(new String(functionalCaseBlob.getPrerequisite() == null ? new byte[0] : functionalCaseBlob.getPrerequisite(), StandardCharsets.UTF_8));
data.setPrerequisite(parseHtml(new String(functionalCaseBlob.getPrerequisite() == null ? new byte[0] : functionalCaseBlob.getPrerequisite(), StandardCharsets.UTF_8)));
//标签
data.setTags(JSON.toJSONString(functionalCase.getTags()));
@ -797,7 +801,7 @@ public class FunctionalCaseFileService {
// 这里如果填的是选项值替换成选项ID保存
map.put(v.getFieldName(), customFieldValidator.parse2Value(caseFieldvalueMap.get(k), v));
} else {
map.put(v.getFieldName(), caseFieldvalueMap.get(k));
map.put(Translator.get("custom_field.functional_priority"), caseFieldvalueMap.get(k));
}
}
}
@ -827,8 +831,8 @@ public class FunctionalCaseFileService {
*/
private void buildExportStep(FunctionalCaseExcelData data, FunctionalCaseBlob functionalCaseBlob, String caseEditType, List<String> textDescriptionList, List<String> expectedResultList) {
if (StringUtils.equals(caseEditType, FunctionalCaseTypeConstants.CaseEditType.TEXT.name())) {
data.setTextDescription(new String(functionalCaseBlob.getTextDescription() == null ? new byte[0] : functionalCaseBlob.getTextDescription(), StandardCharsets.UTF_8));
data.setExpectedResult(new String(functionalCaseBlob.getExpectedResult() == null ? new byte[0] : functionalCaseBlob.getExpectedResult(), StandardCharsets.UTF_8));
data.setTextDescription(parseHtml(new String(functionalCaseBlob.getTextDescription() == null ? new byte[0] : functionalCaseBlob.getTextDescription(), StandardCharsets.UTF_8)));
data.setExpectedResult(parseHtml(new String(functionalCaseBlob.getExpectedResult() == null ? new byte[0] : functionalCaseBlob.getExpectedResult(), StandardCharsets.UTF_8)));
} else {
String steps = new String(functionalCaseBlob.getSteps() == null ? new byte[0] : functionalCaseBlob.getSteps(), StandardCharsets.UTF_8);
List jsonArray = new ArrayList();
@ -853,6 +857,16 @@ public class FunctionalCaseFileService {
}
}
public String parseHtml(String html) {
Pattern pattern = Pattern.compile("<p[^>]*>(.*?)</p>");
Matcher matcher = pattern.matcher(html);
if (matcher.find()) {
String content = matcher.group(1);
return content;
}
return StringUtils.EMPTY;
}
/**
* 获取模块map

View File

@ -31,14 +31,16 @@ import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@ -239,10 +241,10 @@ public class FunctionalCaseXmindService {
dto.setTags(JSON.toJSONString(item.getTags()));
dto.setCaseEditType(item.getCaseEditType());
dto.setSteps(new String(functionalCaseBlob.getSteps() == null ? new byte[0] : functionalCaseBlob.getSteps(), StandardCharsets.UTF_8));
dto.setTextDescription(new String(functionalCaseBlob.getTextDescription() == null ? new byte[0] : functionalCaseBlob.getTextDescription(), StandardCharsets.UTF_8));
dto.setExpectedResult(new String(functionalCaseBlob.getExpectedResult() == null ? new byte[0] : functionalCaseBlob.getExpectedResult(), StandardCharsets.UTF_8));
dto.setPrerequisite(new String(functionalCaseBlob.getPrerequisite() == null ? new byte[0] : functionalCaseBlob.getPrerequisite(), StandardCharsets.UTF_8));
dto.setDescription(new String(functionalCaseBlob.getDescription() == null ? new byte[0] : functionalCaseBlob.getDescription(), StandardCharsets.UTF_8));
dto.setTextDescription(functionalCaseFileService.parseHtml(new String(functionalCaseBlob.getTextDescription() == null ? new byte[0] : functionalCaseBlob.getTextDescription(), StandardCharsets.UTF_8)));
dto.setExpectedResult(functionalCaseFileService.parseHtml(new String(functionalCaseBlob.getExpectedResult() == null ? new byte[0] : functionalCaseBlob.getExpectedResult(), StandardCharsets.UTF_8)));
dto.setPrerequisite(functionalCaseFileService.parseHtml(new String(functionalCaseBlob.getPrerequisite() == null ? new byte[0] : functionalCaseBlob.getPrerequisite(), StandardCharsets.UTF_8)));
dto.setDescription(functionalCaseFileService.parseHtml(new String(functionalCaseBlob.getDescription() == null ? new byte[0] : functionalCaseBlob.getDescription(), StandardCharsets.UTF_8)));
dto.setCustomFieldDTOList(customFields);
caseXmindDTOS.add(dto);
});