Implemented test run editor's test case selection
This commit is contained in:
@@ -89,6 +89,12 @@ app.use("/runs", runsNewRoute);
|
|||||||
app.use("/runs", runsEditRoute);
|
app.use("/runs", runsEditRoute);
|
||||||
app.use("/runs", runDeleteRoute);
|
app.use("/runs", runDeleteRoute);
|
||||||
|
|
||||||
|
// "/runcases"
|
||||||
|
const runCaseNewRoute = require("./routes/runcases/new")(sequelize);
|
||||||
|
const runCaseDeleteRoute = require("./routes/runcases/delete")(sequelize);
|
||||||
|
app.use("/runcases", runCaseNewRoute);
|
||||||
|
app.use("/runcases", runCaseDeleteRoute);
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 3001;
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`Server is running on port ${PORT}`);
|
console.log(`Server is running on port ${PORT}`);
|
||||||
|
|||||||
35
backend/routes/runcases/delete.js
Normal file
35
backend/routes/runcases/delete.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const router = express.Router();
|
||||||
|
const defineRunCase = require("../../models/runCases");
|
||||||
|
const { DataTypes } = require("sequelize");
|
||||||
|
|
||||||
|
module.exports = function (sequelize) {
|
||||||
|
const RunCase = defineRunCase(sequelize, DataTypes);
|
||||||
|
|
||||||
|
router.delete("/", async (req, res) => {
|
||||||
|
const runId = req.query.runId;
|
||||||
|
const caseId = req.query.caseId;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get RunCase to be deleted.
|
||||||
|
const deletingRunCase = await RunCase.findOne({
|
||||||
|
where: {
|
||||||
|
runId: runId,
|
||||||
|
caseId: caseId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!deletingRunCase) {
|
||||||
|
return res.status(404).send("RunCase not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
await deletingRunCase.destroy();
|
||||||
|
res.status(204).send();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send("Internal Server Error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
};
|
||||||
30
backend/routes/runcases/new.js
Normal file
30
backend/routes/runcases/new.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const router = express.Router();
|
||||||
|
const defineRunCase = require("../../models/runCases");
|
||||||
|
const { DataTypes } = require("sequelize");
|
||||||
|
|
||||||
|
module.exports = function (sequelize) {
|
||||||
|
const RunCase = defineRunCase(sequelize, DataTypes);
|
||||||
|
|
||||||
|
router.post("/", async (req, res) => {
|
||||||
|
const runId = req.query.runId;
|
||||||
|
const caseId = req.query.caseId;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newRunCase = await RunCase.create(
|
||||||
|
{
|
||||||
|
runId: runId,
|
||||||
|
caseId: caseId,
|
||||||
|
status: 0,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
res.json(newRunCase);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send("Internal Server Error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
};
|
||||||
@@ -31,7 +31,12 @@ import { testRunStatus } from "@/config/selection";
|
|||||||
import { RunType } from "@/types/run";
|
import { RunType } from "@/types/run";
|
||||||
import { CaseType } from "@/types/case";
|
import { CaseType } from "@/types/case";
|
||||||
import { FolderType } from "@/types/folder";
|
import { FolderType } from "@/types/folder";
|
||||||
import { fetchRun, updateRun } from "../runsControl";
|
import {
|
||||||
|
fetchRun,
|
||||||
|
updateRun,
|
||||||
|
createRunCase,
|
||||||
|
deleteRunCase,
|
||||||
|
} from "../runsControl";
|
||||||
import { fetchFolders } from "../../folders/foldersControl";
|
import { fetchFolders } from "../../folders/foldersControl";
|
||||||
import { fetchCases } from "../../folders/[folderId]/cases/caseControl";
|
import { fetchCases } from "../../folders/[folderId]/cases/caseControl";
|
||||||
|
|
||||||
@@ -74,33 +79,37 @@ export default function RunEditor({ projectId, runId }: Props) {
|
|||||||
fetchDataEffect();
|
fetchDataEffect();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const fetchAndUpdateCases = async () => {
|
||||||
|
try {
|
||||||
|
const testCasesData = await fetchCases(selectedFolder.id);
|
||||||
|
|
||||||
|
// Check if each testCase has an association with testRun
|
||||||
|
// and add "isIncluded" property
|
||||||
|
testCasesData.forEach((caseItr: CaseType) => {
|
||||||
|
let isIncluded: boolean = false;
|
||||||
|
let runStatus: number = 0;
|
||||||
|
|
||||||
|
testRun.Cases.forEach((runCaseItr: CaseType) => {
|
||||||
|
if (runCaseItr.id === caseItr.id) {
|
||||||
|
isIncluded = true;
|
||||||
|
runStatus = runCaseItr.runCases.status;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
caseItr.isIncluded = isIncluded;
|
||||||
|
caseItr.runStatus = runStatus;
|
||||||
|
});
|
||||||
|
|
||||||
|
setTestCases(testCasesData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching cases data:", error.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchCasesData() {
|
async function fetchCasesData() {
|
||||||
if (selectedFolder && selectedFolder.id) {
|
if (selectedFolder && selectedFolder.id) {
|
||||||
try {
|
await fetchAndUpdateCases();
|
||||||
const testCasesData = await fetchCases(selectedFolder.id);
|
|
||||||
|
|
||||||
// Check if each testCase has an association with testRun
|
|
||||||
// and add "isIncluded" property
|
|
||||||
testCasesData.forEach((caseItr: CaseType) => {
|
|
||||||
let isIncluded: boolean = false;
|
|
||||||
let runStatus: number = 0;
|
|
||||||
|
|
||||||
testRun.Cases.forEach((runCaseItr: CaseType) => {
|
|
||||||
if (runCaseItr.id === caseItr.id) {
|
|
||||||
isIncluded = true;
|
|
||||||
runStatus = runCaseItr.runCases.status;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
caseItr.isIncluded = isIncluded;
|
|
||||||
caseItr.runStatus = runStatus;
|
|
||||||
});
|
|
||||||
|
|
||||||
setTestCases(testCasesData);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching cases data:", error.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +128,16 @@ export default function RunEditor({ projectId, runId }: Props) {
|
|||||||
setSelectedKeys(new Set([]));
|
setSelectedKeys(new Set([]));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleIncludeCase = async (includeTestCaseId: number) => {
|
||||||
|
await createRunCase(runId, includeTestCaseId);
|
||||||
|
fetchAndUpdateCases();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleExcludeCase = async (excludeTestCaseId: number) => {
|
||||||
|
await deleteRunCase(runId, excludeTestCaseId);
|
||||||
|
fetchAndUpdateCases();
|
||||||
|
};
|
||||||
|
|
||||||
const baseClass = "";
|
const baseClass = "";
|
||||||
const selectedClass = `${baseClass} bg-neutral-200 dark:bg-neutral-700`;
|
const selectedClass = `${baseClass} bg-neutral-200 dark:bg-neutral-700`;
|
||||||
|
|
||||||
@@ -224,13 +243,13 @@ export default function RunEditor({ projectId, runId }: Props) {
|
|||||||
startContent={<CopyPlus size={16} />}
|
startContent={<CopyPlus size={16} />}
|
||||||
onClick={() => onIncludeExcludeClick("include")}
|
onClick={() => onIncludeExcludeClick("include")}
|
||||||
>
|
>
|
||||||
Include in run
|
Include selected cases in run
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
startContent={<CopyMinus size={16} />}
|
startContent={<CopyMinus size={16} />}
|
||||||
onClick={() => onIncludeExcludeClick("exclude")}
|
onClick={() => onIncludeExcludeClick("exclude")}
|
||||||
>
|
>
|
||||||
Exclude from run
|
Exclude selected cases from run
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
@@ -266,6 +285,8 @@ export default function RunEditor({ projectId, runId }: Props) {
|
|||||||
cases={testcases}
|
cases={testcases}
|
||||||
selectedKeys={selectedKeys}
|
selectedKeys={selectedKeys}
|
||||||
onSelectionChange={setSelectedKeys}
|
onSelectionChange={setSelectedKeys}
|
||||||
|
onIncludeCase={handleIncludeCase}
|
||||||
|
onExcludeCase={handleExcludeCase}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
Selection,
|
Selection,
|
||||||
SortDescriptor,
|
SortDescriptor,
|
||||||
} from "@nextui-org/react";
|
} from "@nextui-org/react";
|
||||||
import { ChevronDown, MoreVertical } from "lucide-react";
|
import { ChevronDown, MoreVertical, CopyPlus, CopyMinus } from "lucide-react";
|
||||||
import { priorities, testRunCaseStatus } from "@/config/selection";
|
import { priorities, testRunCaseStatus } from "@/config/selection";
|
||||||
import { CaseType } from "@/types/case";
|
import { CaseType } from "@/types/case";
|
||||||
|
|
||||||
@@ -31,12 +31,16 @@ type Props = {
|
|||||||
cases: CaseType[];
|
cases: CaseType[];
|
||||||
selectedKeys: Selection;
|
selectedKeys: Selection;
|
||||||
onSelectionChange: React.Dispatch<React.SetStateAction<Selection>>;
|
onSelectionChange: React.Dispatch<React.SetStateAction<Selection>>;
|
||||||
|
onIncludeCase: (includeCaseId: number) => {};
|
||||||
|
onExcludeCase: (excludeCaseId: number) => {};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TestCaseSelector({
|
export default function TestCaseSelector({
|
||||||
cases,
|
cases,
|
||||||
selectedKeys,
|
selectedKeys,
|
||||||
onSelectionChange,
|
onSelectionChange,
|
||||||
|
onIncludeCase,
|
||||||
|
onExcludeCase
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [sortDescriptor, setSortDescriptor] = useState<SortDescriptor>({
|
const [sortDescriptor, setSortDescriptor] = useState<SortDescriptor>({
|
||||||
column: "id",
|
column: "id",
|
||||||
@@ -104,9 +108,20 @@ export default function TestCaseSelector({
|
|||||||
<MoreVertical size={16} />
|
<MoreVertical size={16} />
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownTrigger>
|
</DropdownTrigger>
|
||||||
<DropdownMenu aria-label="test case actions">
|
<DropdownMenu aria-label="include or exclude actions">
|
||||||
<DropdownItem className="text-danger" onClick={() => {}}>
|
<DropdownItem
|
||||||
status change
|
startContent={<CopyPlus size={16} />}
|
||||||
|
isDisabled={testCase.isIncluded}
|
||||||
|
onClick={() => onIncludeCase(testCase.id)}
|
||||||
|
>
|
||||||
|
Include in run
|
||||||
|
</DropdownItem>
|
||||||
|
<DropdownItem
|
||||||
|
startContent={<CopyMinus size={16} />}
|
||||||
|
isDisabled={!testCase.isIncluded}
|
||||||
|
onClick={() => {onExcludeCase(testCase.id)}}
|
||||||
|
>
|
||||||
|
Exclude from run
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ async function updateRun(updateTestRun: RunType) {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error updating project:", error);
|
console.error("Error updating run:", error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,9 +118,53 @@ async function deleteRun(runId: number) {
|
|||||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error deleting project:", error);
|
console.error("Error deleting run:", error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { fetchRun, fetchRuns, createRun, updateRun, deleteRun };
|
async function createRunCase(runId: string, caseId: number) {
|
||||||
|
const fetchOptions = {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const url = `${apiServer}/runcases?runId=${runId}&caseId=${caseId}`;
|
||||||
|
|
||||||
|
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) {
|
||||||
|
console.error("Error creating new runcase:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteRunCase(runId: string, caseId: number) {
|
||||||
|
const fetchOptions = {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const url = `${apiServer}/runcases?runId=${runId}&caseId=${caseId}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, fetchOptions);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error deleting runcase:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { fetchRun, fetchRuns, createRun, updateRun, deleteRun, createRunCase, deleteRunCase };
|
||||||
|
|||||||
Reference in New Issue
Block a user