Files
pp-tcms/frontend/src/app/[locale]/projects/[projectId]/home/aggregate.ts
2024-05-06 17:51:45 +09:00

53 lines
1.4 KiB
TypeScript

import { ProjectType } from "@/types/project";
import { testTypes, priorities } from "@/config/selection";
// aggregate folder, case, run mum
function aggregateBasicInfo(project: ProjectType) {
const folderNum = project.Folders.length;
const runNum = project.Runs.length;
let caseNum = 0;
project.Folders.forEach((folder) => {
caseNum += folder.Cases.length;
});
return { folderNum, runNum, caseNum };
}
// aggregate test types of each case
function aggregateTestType(project: ProjectType) {
const typesCounts = {};
project.Folders.forEach((folder) => {
folder.Cases.forEach((testcase) => {
const type = testcase.type;
typesCounts[type] = (typesCounts[type] || 0) + 1;
});
});
const result = [];
for (let type = 0; type <= testTypes.length; type++) {
result.push({ type: type, count: typesCounts[type] || 0 });
}
return result;
}
function aggregateTestPriority(project: ProjectType) {
const priorityCounts = {};
project.Folders.forEach((folder) => {
folder.Cases.forEach((testcase) => {
const priority = testcase.priority;
priorityCounts[priority] = (priorityCounts[priority] || 0) + 1;
});
});
const result = [];
for (let priority = 0; priority <= priorities.length; priority++) {
result.push({ priority: priority, count: priorityCounts[priority] || 0 });
}
return result;
}
export { aggregateBasicInfo, aggregateTestType, aggregateTestPriority };