Implemented test run editor's bulk test case selection
This commit is contained in:
@@ -92,10 +92,14 @@ app.use("/runs", runDeleteRoute);
|
|||||||
// "/runcases"
|
// "/runcases"
|
||||||
const runCaseIndexRoute = require("./routes/runcases/index")(sequelize);
|
const runCaseIndexRoute = require("./routes/runcases/index")(sequelize);
|
||||||
const runCaseNewRoute = require("./routes/runcases/new")(sequelize);
|
const runCaseNewRoute = require("./routes/runcases/new")(sequelize);
|
||||||
|
const runCaseBuldNewRoute = require("./routes/runcases/bulkNew")(sequelize);
|
||||||
const runCaseDeleteRoute = require("./routes/runcases/delete")(sequelize);
|
const runCaseDeleteRoute = require("./routes/runcases/delete")(sequelize);
|
||||||
|
const runCaseBulkDeleteRoute = require("./routes/runcases/bulkDelete")(sequelize);
|
||||||
app.use("/runcases", runCaseIndexRoute);
|
app.use("/runcases", runCaseIndexRoute);
|
||||||
app.use("/runcases", runCaseNewRoute);
|
app.use("/runcases", runCaseNewRoute);
|
||||||
|
app.use("/runcases", runCaseBuldNewRoute);
|
||||||
app.use("/runcases", runCaseDeleteRoute);
|
app.use("/runcases", runCaseDeleteRoute);
|
||||||
|
app.use("/runcases", runCaseBulkDeleteRoute);
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 3001;
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
|
|||||||
49
backend/routes/runcases/bulkDelete.js
Normal file
49
backend/routes/runcases/bulkDelete.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const router = express.Router();
|
||||||
|
const defineRunCase = require("../../models/runCases");
|
||||||
|
const { DataTypes, Op } = require("sequelize");
|
||||||
|
|
||||||
|
module.exports = function (sequelize) {
|
||||||
|
const RunCase = defineRunCase(sequelize, DataTypes);
|
||||||
|
|
||||||
|
router.post("/bulkdelete", async (req, res) => {
|
||||||
|
const recordsToDelete = req.body;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const existingRunCases = await RunCase.findAll({
|
||||||
|
where: {
|
||||||
|
[Op.or]: recordsToDelete.map((condition) => ({
|
||||||
|
runId: condition.runId,
|
||||||
|
caseId: condition.caseId,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("######bulkDelete")
|
||||||
|
console.log(recordsToDelete)
|
||||||
|
|
||||||
|
if (existingRunCases.length === 0) {
|
||||||
|
return res.status(400).send("No records found to delete");
|
||||||
|
}
|
||||||
|
|
||||||
|
// await RunCase.destroy({
|
||||||
|
// where: recordsToDelete,
|
||||||
|
// });
|
||||||
|
await RunCase.destroy({
|
||||||
|
where: {
|
||||||
|
[Op.or]: recordsToDelete.map((condition) => ({
|
||||||
|
runId: condition.runId,
|
||||||
|
caseId: condition.caseId,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).send("Records deleted successfully");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error deleting run cases:", error);
|
||||||
|
res.status(500).send("Internal Server Error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
};
|
||||||
47
backend/routes/runcases/bulkNew.js
Normal file
47
backend/routes/runcases/bulkNew.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
const express = require("express");
|
||||||
|
const router = express.Router();
|
||||||
|
const defineRunCase = require("../../models/runCases");
|
||||||
|
const { DataTypes, Op } = require("sequelize");
|
||||||
|
|
||||||
|
module.exports = function (sequelize) {
|
||||||
|
const RunCase = defineRunCase(sequelize, DataTypes);
|
||||||
|
|
||||||
|
router.post("/bulknew", async (req, res) => {
|
||||||
|
const recordsToCreate = req.body;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const existingRunCases = await RunCase.findAll({
|
||||||
|
where: {
|
||||||
|
[Op.or]: recordsToCreate.map((record) => ({
|
||||||
|
runId: record.runId,
|
||||||
|
caseId: record.caseId,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filter out records that already exist
|
||||||
|
const recordsToCreateFiltered = recordsToCreate.filter((record) => {
|
||||||
|
return !existingRunCases.some(
|
||||||
|
(existingRecord) =>
|
||||||
|
existingRecord.runId === record.runId &&
|
||||||
|
existingRecord.caseId === record.caseId
|
||||||
|
);
|
||||||
|
});
|
||||||
|
console.log(recordsToCreateFiltered)
|
||||||
|
const newRunCases = await RunCase.bulkCreate(
|
||||||
|
recordsToCreateFiltered.map((record) => ({
|
||||||
|
runId: record.runId,
|
||||||
|
caseId: record.caseId,
|
||||||
|
status: 0,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
res.json(newRunCases);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send("Internal Server Error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return router;
|
||||||
|
};
|
||||||
@@ -11,6 +11,18 @@ module.exports = function (sequelize) {
|
|||||||
const caseId = req.query.caseId;
|
const caseId = req.query.caseId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Check if the record already exists
|
||||||
|
const existingRunCase = await RunCase.findOne({
|
||||||
|
where: {
|
||||||
|
runId: runId,
|
||||||
|
caseId: caseId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (existingRunCase) {
|
||||||
|
return res.status(400).send("Record already exists");
|
||||||
|
}
|
||||||
|
|
||||||
const newRunCase = await RunCase.create(
|
const newRunCase = await RunCase.create(
|
||||||
{
|
{
|
||||||
runId: runId,
|
runId: runId,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import TestCaseSelector from "./TestCaseSelector";
|
import TestCaseSelector from "./TestCaseSelector";
|
||||||
import { testRunStatus } from "@/config/selection";
|
import { testRunStatus } from "@/config/selection";
|
||||||
import { RunType, RunCaseType } from "@/types/run";
|
import { RunType, RunCaseType, RunCaseInfoType } from "@/types/run";
|
||||||
import { CaseType } from "@/types/case";
|
import { CaseType } from "@/types/case";
|
||||||
import { FolderType } from "@/types/folder";
|
import { FolderType } from "@/types/folder";
|
||||||
import {
|
import {
|
||||||
@@ -36,7 +36,9 @@ import {
|
|||||||
updateRun,
|
updateRun,
|
||||||
fetchRunCases,
|
fetchRunCases,
|
||||||
createRunCase,
|
createRunCase,
|
||||||
|
bulkCreateRunCases,
|
||||||
deleteRunCase,
|
deleteRunCase,
|
||||||
|
bulkDeleteRunCases
|
||||||
} from "../runsControl";
|
} 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";
|
||||||
@@ -148,13 +150,23 @@ export default function RunEditor({ projectId, runId }: Props) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onIncludeExcludeClick = async (mode: string) => {
|
const onIncludeExcludeClick = async (isInclude: boolean) => {
|
||||||
console.log(mode);
|
let keys = [];
|
||||||
if (selectedKeys === "all") {
|
if (selectedKeys === "all") {
|
||||||
const allKeys = testcases.map((item) => item.id);
|
keys = testcases.map((item) => item.id);
|
||||||
console.log(allKeys);
|
|
||||||
} else {
|
} else {
|
||||||
console.log([...selectedKeys]);
|
keys = testcases
|
||||||
|
}
|
||||||
|
|
||||||
|
const runCaseInfo: RunCaseInfoType[] = keys.map((caseId) => ({
|
||||||
|
runId: runId,
|
||||||
|
caseId: caseId,
|
||||||
|
}));
|
||||||
|
if (isInclude) {
|
||||||
|
const createdRunCases = await bulkCreateRunCases(runCaseInfo);
|
||||||
|
console.log(createdRunCases)
|
||||||
|
} else {
|
||||||
|
await bulkDeleteRunCases(runCaseInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
setSelectedKeys(new Set([]));
|
setSelectedKeys(new Set([]));
|
||||||
@@ -263,13 +275,13 @@ export default function RunEditor({ projectId, runId }: Props) {
|
|||||||
<DropdownMenu aria-label="test case select actions">
|
<DropdownMenu aria-label="test case select actions">
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
startContent={<CopyPlus size={16} />}
|
startContent={<CopyPlus size={16} />}
|
||||||
onClick={() => onIncludeExcludeClick("include")}
|
onClick={() => onIncludeExcludeClick(true)}
|
||||||
>
|
>
|
||||||
Include selected cases in run
|
Include selected cases in run
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
startContent={<CopyMinus size={16} />}
|
startContent={<CopyMinus size={16} />}
|
||||||
onClick={() => onIncludeExcludeClick("exclude")}
|
onClick={() => onIncludeExcludeClick(false)}
|
||||||
>
|
>
|
||||||
Exclude selected cases from run
|
Exclude selected cases from run
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import Config from "@/config/config";
|
import Config from "@/config/config";
|
||||||
const apiServer = Config.apiServer;
|
const apiServer = Config.apiServer;
|
||||||
import { RunType } from "@/types/run";
|
import { RunType, RunCaseInfoType } from "@/types/run";
|
||||||
|
|
||||||
async function fetchRun(runId: string) {
|
async function fetchRun(runId: string) {
|
||||||
const url = `${apiServer}/runs/${runId}`;
|
const url = `${apiServer}/runs/${runId}`;
|
||||||
@@ -168,6 +168,30 @@ async function createRunCase(runId: string, caseId: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function bulkCreateRunCases(runCaseInfo: RunCaseInfoType[]) {
|
||||||
|
const fetchOptions = {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(runCaseInfo)
|
||||||
|
};
|
||||||
|
|
||||||
|
const url = `${apiServer}/runcases/bulknew`;
|
||||||
|
|
||||||
|
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 creating new runcase:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteRunCase(runId: string, caseId: number) {
|
async function deleteRunCase(runId: string, caseId: number) {
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
@@ -189,4 +213,37 @@ async function deleteRunCase(runId: string, caseId: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { fetchRun, fetchRuns, createRun, updateRun, deleteRun, fetchRunCases, createRunCase, deleteRunCase };
|
async function bulkDeleteRunCases(runCaseInfo: RunCaseInfoType[]) {
|
||||||
|
const fetchOptions = {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(runCaseInfo)
|
||||||
|
};
|
||||||
|
|
||||||
|
const url = `${apiServer}/runcases/bulkdelete`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, fetchOptions);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error deleting runcase:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
fetchRun,
|
||||||
|
fetchRuns,
|
||||||
|
createRun,
|
||||||
|
updateRun,
|
||||||
|
deleteRun,
|
||||||
|
fetchRunCases,
|
||||||
|
createRunCase,
|
||||||
|
bulkCreateRunCases,
|
||||||
|
deleteRunCase,
|
||||||
|
bulkDeleteRunCases,
|
||||||
|
};
|
||||||
|
|||||||
@@ -16,4 +16,9 @@ type RunCaseType = {
|
|||||||
status: number;
|
status: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { RunType, RunCaseType };
|
type RunCaseInfoType = {
|
||||||
|
runId: number;
|
||||||
|
caseId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { RunType, RunCaseType, RunCaseInfoType };
|
||||||
|
|||||||
Reference in New Issue
Block a user