fix(接口测试): 场景&用例表格通过率统计

This commit is contained in:
baiqi 2024-11-07 17:59:34 +08:00 committed by 刘瑞斌
parent 66eac32742
commit 7b3a920f25
8 changed files with 68 additions and 4 deletions

View File

@ -23,6 +23,7 @@ import {
CaseBatchExportLogUrl,
CaseExportLogUrl,
CasePageUrl,
CaseStatisticsUrl,
caseTableBatchSyncUrl,
CheckDefinitionScheduleUrl,
checkSharePsdUrl,
@ -124,6 +125,7 @@ import {
ApiCaseExecuteHistoryItem,
ApiCaseExecuteHistoryParams,
ApiCasePageParams,
type ApiCaseStatisticsItem,
ApiDefinitionBatchDeleteParams,
type ApiDefinitionBatchExportParams,
ApiDefinitionBatchMoveParams,
@ -719,3 +721,8 @@ export function getDocSharePluginScript(id: string | number, orgId: string) {
export function getShareDefinitionDetail(id: string | number) {
return MSR.get<ApiDefinitionDetail>({ url: GetShareDefinitionDetailUrl, params: id });
}
// 用例执行率统计
export function getCaseStatistics(data: string[]) {
return MSR.post<ApiCaseStatisticsItem[]>({ url: CaseStatisticsUrl, data });
}

View File

@ -41,6 +41,7 @@ import {
ScenarioPageUrl,
ScenarioScheduleConfigDeleteUrl,
ScenarioScheduleConfigUrl,
ScenarioStatisticsUrl,
ScenarioStepTransferFileUrl,
ScenarioTransferFileUrl,
ScenarioTransferModuleOptionsUrl,
@ -77,6 +78,7 @@ import {
ScenarioDetail,
ScenarioHistoryItem,
ScenarioHistoryPageParams,
type ScenarioStatisticsItem,
ScenarioStepResourceInfo,
} from '@/models/apiTest/scenario';
import {
@ -369,3 +371,8 @@ export function getScenarioDownloadFile(projectId: string, fileId: string) {
export function scenarioBatchEditSchedule(data: ApiScenarioBatchScheduleConfig) {
return MSR.post({ url: ScenarioBatchEditScheduleUrl, data });
}
// 场景执行率统计
export function getScenarioStatistics(data: string[]) {
return MSR.post<ScenarioStatisticsItem[]>({ url: ScenarioStatisticsUrl, data });
}

View File

@ -99,6 +99,7 @@ export const GetCaseReportDetailUrl = '/api/report/case/get/detail/'; // 接口
export const CaseExportLogUrl = '/api/report/case/export'; // 接口用例导出报告日志记录
export const CaseBatchExportLogUrl = '/api/report/case/batch-export'; // 接口用例批量导出报告日志记录
export const GetCaseBatchExportParamsUrl = '/api/report/case/batch-param'; // 接口用例批量导出报告id集合
export const CaseStatisticsUrl = '/api/case/statistics'; // 用例执行率统计
/**
*

View File

@ -28,6 +28,8 @@ export const BatchEditScenarioUrl = '/api/scenario/batch-operation/edit'; // 批
export const BatchRunScenarioUrl = '/api/scenario/batch-operation/run'; // 批量执行接口场景
export const UpdateScenarioPriorityUrl = '/api/scenario/update-priority'; // 场景更新等级
export const UpdateScenarioStatusUrl = '/api/scenario/update-status'; // 场景更新状态
export const ScenarioStatisticsUrl = '/api/scenario/statistics'; // 场景执行率统计
// 场景导入导出相关
export const ImportScenarioUrl = '/api/scenario/import'; // 导入场景
export const ExportScenarioUrl = '/api/scenario/export'; // 导出场景

View File

@ -475,3 +475,8 @@ export interface ShareDetailType {
isPrivate: boolean;
projectName?: string;
}
// 接口用例统计项
export interface ApiCaseStatisticsItem {
id: string;
passRate: string;
}

View File

@ -558,3 +558,9 @@ export interface ExportScenarioParams extends BatchActionQueryParams {
exportAllRelatedData: boolean;
fileId: string;
}
// 场景统计项
export interface ScenarioStatisticsItem {
id: string;
execPassRate: string;
}

View File

@ -345,6 +345,7 @@
dragSort,
getCaseDetail,
getCasePage,
getCaseStatistics,
updateCasePriority,
updateCaseStatus,
} from '@/api/modules/api-test/management';
@ -635,6 +636,22 @@
}
return moduleIds;
}
async function initStatistics() {
try {
const res = await getCaseStatistics(propsRes.value.data.map((item) => item.id));
propsRes.value.data.forEach((e) => {
const item = res.find((i: any) => i.scenarioId === e.id);
if (item) {
e.passRate = item.passRate;
}
});
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
}
async function loadCaseList() {
const selectModules = await getModuleIds();
const params = {
@ -648,7 +665,8 @@
combineSearch: advanceFilter,
};
setLoadListParams(params);
loadList();
await loadList();
initStatistics();
}
function loadCaseListAndResetSelector() {
resetSelector();

View File

@ -528,6 +528,7 @@
deleteScheduleConfig,
dragSort,
getScenarioPage,
getScenarioStatistics,
recycleScenario,
scenarioBatchEditSchedule,
scenarioScheduleConfig,
@ -748,8 +749,8 @@
},
{
title: 'apiScenario.table.columns.passRate',
dataIndex: 'requestPassRate',
slotName: 'requestPassRate',
dataIndex: 'execPassRate',
slotName: 'execPassRate',
titleSlotName: 'requestPassRateColumn',
showDrag: true,
showInTable: false,
@ -847,7 +848,7 @@
},
(item) => ({
...item,
requestPassRate: item.requestPassRate ? `${item.requestPassRate}%` : '-',
execPassRate: item.execPassRate ? `${item.execPassRate}%` : '-',
createTime: dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss'),
updateTime: dayjs(item.updateTime).format('YYYY-MM-DD HH:mm:ss'),
})
@ -960,6 +961,22 @@
}
return moduleIds;
}
async function initStatistics() {
try {
const res = await getScenarioStatistics(propsRes.value.data.map((item) => item.id));
propsRes.value.data.forEach((e) => {
const item = res.find((i: any) => i.scenarioId === e.id);
if (item) {
e.execPassRate = item.execPassRate;
}
});
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
}
}
async function loadScenarioList(refreshTreeCount?: boolean) {
const moduleIds = await getModuleIds();
const params = {
@ -969,6 +986,7 @@
};
setLoadListParams({ ...params, viewId: viewId.value, combineSearch: advanceFilter });
await loadList();
initStatistics();
if (refreshTreeCount && !isAdvancedSearchMode.value) {
emit('refreshModuleTree', params);
}