diff --git a/backend/models/runCases.js b/backend/models/runCases.js new file mode 100644 index 0000000..b998aa4 --- /dev/null +++ b/backend/models/runCases.js @@ -0,0 +1,31 @@ +function defineRunCase(sequelize, DataTypes) { + const RunCase = sequelize.define("RunCase", { + runId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + caseId: { + type: DataTypes.INTEGER, + allowNull: false, + }, + status: { + type: DataTypes.INTEGER, + allowNull: false, + }, + }); + + RunCase.associate = (models) => { + RunCase.belongsTo(models.Run, { + foreignKey: "runId", + onDelete: "CASCADE", + }); + RunCase.belongsTo(models.Case, { + foreignKey: "caseId", + onDelete: "CASCADE", + }); + }; + + return RunCase; +} + +module.exports = defineRunCase; diff --git a/backend/routes/runs/show.js b/backend/routes/runs/show.js index f23cfda..5ee946d 100644 --- a/backend/routes/runs/show.js +++ b/backend/routes/runs/show.js @@ -1,10 +1,14 @@ const express = require("express"); const router = express.Router(); const defineRun = require("../../models/runs"); +const defineCase = require("../../models/cases"); const { DataTypes } = require("sequelize"); module.exports = function (sequelize) { const Run = defineRun(sequelize, DataTypes); + const Case = defineCase(sequelize, DataTypes); + Run.belongsToMany(Case, { through: "runCases" }); + Case.belongsToMany(Run, { through: "runCases" }); router.get("/:runId", async (req, res) => { const runId = req.params.runId; @@ -14,7 +18,13 @@ module.exports = function (sequelize) { } try { - const project = await Run.findByPk(runId); + const project = await Run.findByPk(runId, { + include: [ + { + model: Case, + }, + ], + }); if (!project) { return res.status(404).send("Run not found"); } diff --git a/frontend/app/projects/[projectId]/runs/[runId]/RunEditor.tsx b/frontend/app/projects/[projectId]/runs/[runId]/RunEditor.tsx index 88bd966..68dd9c8 100644 --- a/frontend/app/projects/[projectId]/runs/[runId]/RunEditor.tsx +++ b/frontend/app/projects/[projectId]/runs/[runId]/RunEditor.tsx @@ -8,12 +8,18 @@ import { Select, SelectItem, Tooltip, + Listbox, + ListboxItem, + Divider, } from "@nextui-org/react"; import { useRouter } from "next/navigation"; -import { Save, ArrowLeft, Plus } from "lucide-react"; +import { Save, ArrowLeft, Folder } from "lucide-react"; import { testRunStatus } from "@/config/selection"; import { RunType } from "@/types/run"; +import { FolderType } from "@/types/folder"; import { fetchRun, updateRun } from "../runsControl"; +import { fetchFolders } from "../../folders/foldersControl"; +import { fetchCases } from "../../folders/[folderId]/cases/caseControl"; const defaultTestRun = { id: 0, @@ -31,6 +37,9 @@ type Props = { export default function RunEditor({ projectId, runId }: Props) { const [testRun, setTestRun] = useState(defaultTestRun); + const [folders, setFolders] = useState([]); + const [testcases, setTestCases] = useState([]); + const [selectedFolder, setSelectedFolder] = useState({}); const [isNameInvalid, setIsNameInvalid] = useState(false); const [isUpdating, setIsUpdating] = useState(false); const router = useRouter(); @@ -38,8 +47,10 @@ export default function RunEditor({ projectId, runId }: Props) { useEffect(() => { async function fetchDataEffect() { try { - const data = await fetchRun(runId); - setTestRun(data); + const caseData = await fetchRun(runId); + setTestRun(caseData); + const foldersData = await fetchFolders(projectId); + setFolders(foldersData); } catch (error) { console.error("Error in effect:", error.message); } @@ -48,6 +59,24 @@ export default function RunEditor({ projectId, runId }: Props) { fetchDataEffect(); }, []); + useEffect(() => { + async function fetchCasesData() { + if (selectedFolder && selectedFolder.id) { + try { + const testCasesData = await fetchCases(selectedFolder.id); + setTestCases(testCasesData); + } catch (error) { + console.error("Error fetching cases data:", error.message); + } + } + } + + fetchCasesData(); + }, [selectedFolder]); + + const baseClass = ""; + const selectedClass = `${baseClass} bg-neutral-200 dark:bg-neutral-700`; + return ( <>
@@ -80,6 +109,7 @@ export default function RunEditor({ projectId, runId }: Props) {
+
Basic
- -