f149bd1292
* fix(office): disable create button until project + title set Office "New Task" dialog let user submit without picking a project, which hit the backend isOfficeRequest() heuristic and failed validation with "workflow_id is required for non-ephemeral tasks". Disable the button until both title and project are set and surface the missing requirement in a tooltip instead of a backend error toast. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(office): guard handleCreate on projectId + cover with tests PR review feedback (claude, cubic): the handleCreate path only checked title and workspace, so a keyboard shortcut or future programmatic caller could still produce a request with no project and reproduce the backend 'workflow_id is required' error. Guard it there too, and add unit tests that pin the disabled-state + reason behavior of the extracted CreateTaskButton. aria-label on the trigger wrapper surfaces the reason to assistive tech even when the tooltip is closed. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * test(office): cover submitting state for CreateTaskButton PR review feedback (claude): the disabled check had three branches (missing title / missing project / submitting); only two were tested. Add the submitting case so a regression that drops it from the disabled expression is caught. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
73 lines
2.3 KiB
TypeScript
73 lines
2.3 KiB
TypeScript
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
import { render, screen, cleanup } from "@testing-library/react";
|
|
import { TooltipProvider } from "@kandev/ui/tooltip";
|
|
|
|
import { CreateTaskButton } from "./new-task-dialog";
|
|
import type { IssueDraft } from "./new-task-draft";
|
|
|
|
const BASE_DRAFT: IssueDraft = {
|
|
title: "",
|
|
description: "",
|
|
assigneeId: "",
|
|
projectId: "",
|
|
status: "todo",
|
|
priority: "medium",
|
|
showReviewer: false,
|
|
showApprover: false,
|
|
reviewerIds: [],
|
|
approverIds: [],
|
|
};
|
|
|
|
function renderButton(draft: Partial<IssueDraft>) {
|
|
return render(
|
|
<TooltipProvider>
|
|
<CreateTaskButton draft={{ ...BASE_DRAFT, ...draft }} submitting={false} onCreate={vi.fn()} />
|
|
</TooltipProvider>,
|
|
);
|
|
}
|
|
|
|
const TEST_ID = "new-task-create-button";
|
|
|
|
function getButton() {
|
|
return screen.getByTestId(TEST_ID) as HTMLButtonElement;
|
|
}
|
|
|
|
afterEach(() => cleanup());
|
|
|
|
describe("CreateTaskButton", () => {
|
|
it("disables the button and labels missing project when no project selected", () => {
|
|
renderButton({ title: "do thing" });
|
|
expect(getButton().disabled).toBe(true);
|
|
// The tooltip content is rendered as accessible-name on the wrapper.
|
|
expect(screen.getByLabelText(/select a project to create a task/i)).toBeTruthy();
|
|
});
|
|
|
|
it("disables the button and labels missing title when title empty", () => {
|
|
renderButton({ projectId: "proj-1" });
|
|
expect(getButton().disabled).toBe(true);
|
|
expect(screen.getByLabelText(/add a title to create a task/i)).toBeTruthy();
|
|
});
|
|
|
|
it("enables the button without a tooltip when both title and project are set", () => {
|
|
renderButton({ title: "do thing", projectId: "proj-1" });
|
|
expect(getButton().disabled).toBe(false);
|
|
expect(screen.queryByLabelText(/create a task/i)).toBeNull();
|
|
});
|
|
|
|
it("disables the button and shows 'Creating...' while submitting", () => {
|
|
render(
|
|
<TooltipProvider>
|
|
<CreateTaskButton
|
|
draft={{ ...BASE_DRAFT, title: "do thing", projectId: "proj-1" }}
|
|
submitting={true}
|
|
onCreate={vi.fn()}
|
|
/>
|
|
</TooltipProvider>,
|
|
);
|
|
const button = getButton();
|
|
expect(button.disabled).toBe(true);
|
|
expect(button.textContent).toBe("Creating...");
|
|
expect(screen.queryByLabelText(/create a task/i)).toBeNull();
|
|
});
|
|
});
|