Implemented test run editor's test status update
This commit is contained in:
@@ -36,6 +36,7 @@ import {
|
||||
updateRun,
|
||||
fetchRunCases,
|
||||
createRunCase,
|
||||
updateRunCase,
|
||||
bulkCreateRunCases,
|
||||
deleteRunCase,
|
||||
bulkDeleteRunCases,
|
||||
@@ -117,6 +118,18 @@ export default function RunEditor({ projectId, runId }: Props) {
|
||||
fetchCasesData();
|
||||
}, [selectedFolder]);
|
||||
|
||||
const handleChangeStatus = async (changeCaseId: number, status: number) => {
|
||||
await updateRunCase(runId, changeCaseId, status);
|
||||
setTestCases((prevTestCases) => {
|
||||
return prevTestCases.map((testCase) => {
|
||||
if (testCase.id === changeCaseId) {
|
||||
return { ...testCase, runStatus: status };
|
||||
}
|
||||
return testCase;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const handleIncludeExcludeCase = async (
|
||||
isInclude: boolean,
|
||||
clickedTestCaseId: number
|
||||
@@ -152,7 +165,6 @@ export default function RunEditor({ projectId, runId }: Props) {
|
||||
} else {
|
||||
keys = Array.from(selectedKeys).map(Number);
|
||||
}
|
||||
console.log(keys)
|
||||
|
||||
const runCaseInfo: RunCaseInfoType[] = keys.map((caseId) => ({
|
||||
runId: runId,
|
||||
@@ -170,14 +182,13 @@ export default function RunEditor({ projectId, runId }: Props) {
|
||||
});
|
||||
}
|
||||
|
||||
setTestCases((prevTestCases) => {
|
||||
return prevTestCases.map((testCase) => {
|
||||
const isCaseIncluded = isInclude
|
||||
? keys.includes(testCase.id)
|
||||
: !keys.includes(testCase.id);
|
||||
return { ...testCase, isIncluded: isCaseIncluded };
|
||||
});
|
||||
const updatedTestCases = testcases.map((testcase) => {
|
||||
if (keys.includes(testcase.id)) {
|
||||
return { ...testcase, isIncluded: isInclude };
|
||||
}
|
||||
return testcase;
|
||||
});
|
||||
setTestCases(updatedTestCases);
|
||||
|
||||
setSelectedKeys(new Set([]));
|
||||
};
|
||||
@@ -329,6 +340,7 @@ export default function RunEditor({ projectId, runId }: Props) {
|
||||
cases={testcases}
|
||||
selectedKeys={selectedKeys}
|
||||
onSelectionChange={setSelectedKeys}
|
||||
onStatusChange={handleChangeStatus}
|
||||
onIncludeCase={(includeTestId) =>
|
||||
handleIncludeExcludeCase(true, includeTestId)
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ type Props = {
|
||||
cases: CaseType[];
|
||||
selectedKeys: Selection;
|
||||
onSelectionChange: React.Dispatch<React.SetStateAction<Selection>>;
|
||||
onStatusChange: (changeCaseId: number, status: number) => {};
|
||||
onIncludeCase: (includeCaseId: number) => {};
|
||||
onExcludeCase: (excludeCaseId: number) => {};
|
||||
};
|
||||
@@ -48,6 +49,7 @@ export default function TestCaseSelector({
|
||||
cases,
|
||||
selectedKeys,
|
||||
onSelectionChange,
|
||||
onStatusChange,
|
||||
onIncludeCase,
|
||||
onExcludeCase,
|
||||
}: Props) {
|
||||
@@ -121,7 +123,7 @@ export default function TestCaseSelector({
|
||||
<DropdownItem
|
||||
key={index}
|
||||
startContent={renderStatusIcon(runCaseStatus.uid)}
|
||||
onClick={() => {}}
|
||||
onPress={() => onStatusChange(testCase.id, index)}
|
||||
>
|
||||
{runCaseStatus.name}
|
||||
</DropdownItem>
|
||||
|
||||
@@ -168,13 +168,36 @@ async function createRunCase(runId: string, caseId: number) {
|
||||
}
|
||||
}
|
||||
|
||||
async function updateRunCase(runId: string, caseId: number, status: number) {
|
||||
const fetchOptions = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
|
||||
const url = `${apiServer}/runcases?runId=${runId}&caseId=${caseId}&status=${status}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error: any) {
|
||||
console.error("Error updating runcase:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function bulkCreateRunCases(runCaseInfo: RunCaseInfoType[]) {
|
||||
const fetchOptions = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(runCaseInfo)
|
||||
body: JSON.stringify(runCaseInfo),
|
||||
};
|
||||
|
||||
const url = `${apiServer}/runcases/bulknew`;
|
||||
@@ -219,7 +242,7 @@ async function bulkDeleteRunCases(runCaseInfo: RunCaseInfoType[]) {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(runCaseInfo)
|
||||
body: JSON.stringify(runCaseInfo),
|
||||
};
|
||||
|
||||
const url = `${apiServer}/runcases/bulkdelete`;
|
||||
@@ -243,6 +266,7 @@ export {
|
||||
deleteRun,
|
||||
fetchRunCases,
|
||||
createRunCase,
|
||||
updateRunCase,
|
||||
bulkCreateRunCases,
|
||||
deleteRunCase,
|
||||
bulkDeleteRunCases,
|
||||
|
||||
Reference in New Issue
Block a user