Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix: keep planned subtasks in backlog

Bryan Nathan1f20eb931e50
diff --git a/apps/web/src/components/task/task-details-content.tsx b/apps/web/src/components/task/task-details-content.tsx
index 8151e89d6..c6c9d0234 100644
--- a/apps/web/src/components/task/task-details-content.tsx
+++ b/apps/web/src/components/task/task-details-content.tsx
@@ -88,11 +88,14 @@ export default function TaskDetailsContent({
</div>
)}
<div className="mt-4">
- <TaskSubtasks
- taskId={taskId}
- projectId={projectId}
- workspaceId={workspaceId}
- />
+ {task && (
+ <TaskSubtasks
+ taskId={taskId}
+ projectId={projectId}
+ workspaceId={workspaceId}
+ parentStatus={task.status}
+ />
+ )}
</div>
<div className="mt-2">
<TaskRelations
diff --git a/apps/web/src/components/task/task-subtasks.test.tsx b/apps/web/src/components/task/task-subtasks.test.tsx
new file mode 100644
index 000000000..78ae5659a
--- /dev/null
+++ b/apps/web/src/components/task/task-subtasks.test.tsx
@@ -0,0 +1,121 @@
+import {
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import TaskSubtasks from "./task-subtasks";
+
+const mocks = vi.hoisted(() => ({
+ createTask: vi.fn(),
+ createRelation: vi.fn(),
+}));
+
+vi.mock("@tanstack/react-router", () => ({ useNavigate: () => vi.fn() }));
+vi.mock("framer-motion", () => ({
+ AnimatePresence: ({ children }: { children: unknown }) => children,
+}));
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+vi.mock("@/hooks/mutations/task/use-create-task", () => ({
+ default: () => ({ mutateAsync: mocks.createTask, isPending: false }),
+}));
+vi.mock("@/hooks/mutations/task-relation/use-create-task-relation", () => ({
+ default: () => ({ mutateAsync: mocks.createRelation }),
+}));
+vi.mock("@/hooks/mutations/task/use-delete-task", () => ({
+ useDeleteTask: () => ({ mutateAsync: vi.fn() }),
+}));
+vi.mock("@/hooks/mutations/task/use-update-task-status", () => ({
+ useUpdateTaskStatus: () => ({ mutateAsync: vi.fn() }),
+}));
+vi.mock("@/hooks/queries/column/use-get-columns", () => ({
+ useGetColumns: () => ({
+ data: [
+ { id: "todo", slug: "to-do", name: "To Do", isFinal: false },
+ { id: "done", slug: "done", name: "Done", isFinal: true },
+ ],
+ }),
+}));
+vi.mock("@/hooks/queries/task-relation/use-get-task-relations", () => ({
+ default: () => ({ data: [] }),
+}));
+vi.mock("@/hooks/queries/workspace/use-active-workspace", () => ({
+ default: () => ({ data: { id: "workspace-1" } }),
+}));
+vi.mock(
+ "@/hooks/queries/workspace-users/use-get-active-workspace-users",
+ () => ({
+ useGetActiveWorkspaceUsers: () => ({ data: { members: [] } }),
+ }),
+);
+vi.mock("@/hooks/use-workspace-permission", () => ({
+ useWorkspacePermission: () => ({ canManageTasks: () => true }),
+}));
+vi.mock("@/lib/toast", () => ({ toast: { error: vi.fn(), success: vi.fn() } }));
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+describe("TaskSubtasks", () => {
+ it("creates a subtask as planned when its parent is planned", async () => {
+ mocks.createTask.mockResolvedValue({ id: "subtask-1" });
+ mocks.createRelation.mockResolvedValue({});
+
+ render(
+ <TaskSubtasks
+ taskId="parent-1"
+ projectId="project-1"
+ workspaceId="workspace-1"
+ parentStatus="planned"
+ />,
+ );
+
+ fireEvent.click(screen.getAllByRole("button")[1]);
+ fireEvent.change(
+ screen.getByPlaceholderText("tasks:subtasks.inputPlaceholder"),
+ { target: { value: "Design login form" } },
+ );
+ fireEvent.click(
+ screen.getByRole("button", { name: "tasks:subtasks.addAction" }),
+ );
+
+ await waitFor(() => expect(mocks.createTask).toHaveBeenCalledTimes(1));
+ expect(mocks.createTask).toHaveBeenCalledWith(
+ expect.objectContaining({ status: "planned" }),
+ );
+ });
+
+ it("uses the project's first active column for an active parent", async () => {
+ mocks.createTask.mockResolvedValue({ id: "subtask-2" });
+ mocks.createRelation.mockResolvedValue({});
+
+ render(
+ <TaskSubtasks
+ taskId="parent-2"
+ projectId="project-1"
+ workspaceId="workspace-1"
+ parentStatus="in-progress"
+ />,
+ );
+
+ fireEvent.click(screen.getAllByRole("button")[1]);
+ fireEvent.change(
+ screen.getByPlaceholderText("tasks:subtasks.inputPlaceholder"),
+ { target: { value: "Implement login form" } },
+ );
+ fireEvent.click(
+ screen.getByRole("button", { name: "tasks:subtasks.addAction" }),
+ );
+
+ await waitFor(() => expect(mocks.createTask).toHaveBeenCalledTimes(1));
+ expect(mocks.createTask).toHaveBeenCalledWith(
+ expect.objectContaining({ status: "to-do" }),
+ );
+ });
+});
diff --git a/apps/web/src/components/task/task-subtasks.tsx b/apps/web/src/components/task/task-subtasks.tsx
index 5ba00fad8..46fa8998c 100644
--- a/apps/web/src/components/task/task-subtasks.tsx
+++ b/apps/web/src/components/task/task-subtasks.tsx
@@ -38,12 +38,14 @@ type TaskSubtasksProps = {
taskId: string;
projectId: string;
workspaceId: string;
+ parentStatus: string;
};
export default function TaskSubtasks({
taskId,
projectId,
workspaceId,
+ parentStatus,
}: TaskSubtasksProps) {
const { t } = useTranslation();
const navigate = useNavigate();
@@ -260,7 +262,7 @@ export default function TaskSubtasks({
title: newTitle.trim(),
description: "",
projectId,
- status: "to-do",
+ status: parentStatus === "planned" ? "planned" : todoSlug,
priority: "no-priority",
});