fix(tasks): hide human assignee when auth is disabled (#3417)
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { Task } from "@/app/office/tasks/[id]/types";
|
||||
import { TaskProperties } from "./task-properties";
|
||||
|
||||
const mockAppState = vi.hoisted(() => ({
|
||||
auth: {
|
||||
mode: "enabled",
|
||||
authenticated: true,
|
||||
user: { id: "user-1" } as { id: string } | null,
|
||||
ssoProviders: [],
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/components/state-provider", () => ({
|
||||
useAppStore: (selector: (state: typeof mockAppState) => unknown) => selector(mockAppState),
|
||||
}));
|
||||
|
||||
vi.mock("./components/status-picker", () => ({ StatusPicker: () => null }));
|
||||
vi.mock("./components/priority-picker", () => ({ PriorityPicker: () => null }));
|
||||
vi.mock("./components/labels-picker", () => ({ LabelsPicker: () => null }));
|
||||
vi.mock("./components/assignee-picker", () => ({ AssigneePicker: () => null }));
|
||||
vi.mock("./components/human-assignee-picker", () => ({
|
||||
HumanAssigneePicker: () => <span data-testid="human-assignee-picker-trigger" />,
|
||||
}));
|
||||
vi.mock("./components/project-picker", () => ({ ProjectPicker: () => null }));
|
||||
vi.mock("./components/parent-picker", () => ({ ParentPicker: () => null }));
|
||||
vi.mock("./components/blockers-picker", () => ({ BlockersPicker: () => null }));
|
||||
vi.mock("./components/sub-issues-row", () => ({ SubIssuesRow: () => null }));
|
||||
vi.mock("./components/reviewers-picker", () => ({ ReviewersPicker: () => null }));
|
||||
vi.mock("./components/approvers-picker", () => ({ ApproversPicker: () => null }));
|
||||
vi.mock("./components/pending-approval-badge", () => ({ PendingApprovalBadge: () => null }));
|
||||
vi.mock("./components/quorum-status-badge", () => ({ QuorumStatusBadge: () => null }));
|
||||
|
||||
const TASK = {
|
||||
id: "task-1",
|
||||
workspaceId: "workspace-1",
|
||||
identifier: "TASK-1",
|
||||
title: "Auth gate task",
|
||||
status: "todo",
|
||||
priority: "medium",
|
||||
labels: [],
|
||||
blockedBy: [],
|
||||
blocking: [],
|
||||
children: [],
|
||||
reviewers: [],
|
||||
approvers: [],
|
||||
decisions: [],
|
||||
createdBy: "user-1",
|
||||
createdAt: "2026-09-05T12:00:00Z",
|
||||
updatedAt: "2026-09-05T12:00:00Z",
|
||||
} satisfies Task;
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
mockAppState.auth.mode = "enabled";
|
||||
mockAppState.auth.user = { id: "user-1" };
|
||||
});
|
||||
|
||||
describe("TaskProperties human assignee", () => {
|
||||
it.each(["disabled", "setup"] as const)("hides the row in %s auth mode", (mode) => {
|
||||
mockAppState.auth.mode = mode;
|
||||
mockAppState.auth.user = { id: "default-user" };
|
||||
|
||||
render(<TaskProperties task={TASK} />);
|
||||
|
||||
expect(screen.queryByText("Assigned to", { exact: true })).toBeNull();
|
||||
});
|
||||
|
||||
it("hides the row when enabled auth has no signed-in user", () => {
|
||||
mockAppState.auth.user = null;
|
||||
|
||||
render(<TaskProperties task={TASK} />);
|
||||
|
||||
expect(screen.queryByText("Assigned to", { exact: true })).toBeNull();
|
||||
});
|
||||
|
||||
it("shows the row when authentication is enabled for a signed-in user", () => {
|
||||
render(<TaskProperties task={TASK} />);
|
||||
|
||||
expect(screen.getByText("Assigned to", { exact: true })).toBeTruthy();
|
||||
expect(screen.getByTestId("human-assignee-picker-trigger")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -21,6 +21,7 @@ import { PendingApprovalBadge } from "./components/pending-approval-badge";
|
||||
import { QuorumStatusBadge } from "./components/quorum-status-badge";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useAppStore } from "@/components/state-provider";
|
||||
import { canShowHumanAssignee } from "@/lib/auth/human-assignee";
|
||||
|
||||
type TaskPropertiesProps = {
|
||||
task: Task;
|
||||
@@ -60,8 +61,8 @@ function NoneLabel() {
|
||||
// user, so the control would offer a choice that cannot mean anything.
|
||||
function HumanAssigneeRow({ task }: { task: Task }) {
|
||||
const { t } = useTranslation();
|
||||
const hasIdentity = useAppStore((s) => Boolean(s.auth.user));
|
||||
if (!hasIdentity) return null;
|
||||
const showHumanAssignee = useAppStore((s) => canShowHumanAssignee(s.auth));
|
||||
if (!showHumanAssignee) return null;
|
||||
return (
|
||||
<PropertyRow label={t("task:assignedTo")} valueClassName="ml-auto">
|
||||
<HumanAssigneePicker task={task} />
|
||||
|
||||
Reference in New Issue
Block a user