-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathTaskHeaderActions.test.tsx
More file actions
117 lines (106 loc) · 3.58 KB
/
Copy pathTaskHeaderActions.test.tsx
File metadata and controls
117 lines (106 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import type { Task } from "@posthog/shared/domain-types";
import { Theme } from "@radix-ui/themes";
import { render, screen } from "@testing-library/react";
import type { ReactNode } from "react";
import { describe, expect, it, vi } from "vitest";
const { useWorkspace, useWorkspaceLoaded } = vi.hoisted(() => ({
useWorkspace: vi.fn(),
useWorkspaceLoaded: vi.fn(),
}));
vi.mock("@posthog/ui/features/workspace/useWorkspace", () => ({
useWorkspace,
useWorkspaceLoaded,
}));
vi.mock("@posthog/ui/features/auth/store", () => ({
useAuthStateValue: (selector: (state: { status: string }) => unknown) =>
selector({ status: "authenticated" }),
}));
vi.mock("@posthog/ui/features/feature-flags/useFeatureFlag", () => ({
useFeatureFlag: () => true,
}));
vi.mock("@posthog/ui/features/sessions/useSession", () => ({
useSessionForTask: () => null,
}));
vi.mock("@posthog/ui/features/sessions/hooks/useSessionCallbacks", () => ({
useSessionCallbacks: () => ({ initiateHandoffToCloud: vi.fn() }),
}));
vi.mock("@posthog/ui/features/sessions/handoffDialogStore", () => ({
useHandoffDialogStore: (selector: (state: object) => unknown) =>
selector({
confirmOpen: false,
direction: null,
branchName: null,
openConfirm: vi.fn(),
closeConfirm: vi.fn(),
}),
}));
vi.mock("@posthog/ui/features/code-review/hooks/useDiffStatsToggle", () => ({
useDiffStatsToggle: () => ({
filesChanged: 0,
linesAdded: 0,
linesRemoved: 0,
isOpen: false,
toggle: vi.fn(),
}),
}));
vi.mock(
"@posthog/ui/features/skill-buttons/components/SkillButtonsMenu",
() => ({
SkillButtonsMenu: () => null,
}),
);
vi.mock("@posthog/ui/features/autoresearch/AutoresearchHeaderButton", () => ({
AutoresearchHeaderButton: () => null,
}));
vi.mock(
"@posthog/ui/features/git-interaction/components/BranchSelector",
() => ({
BranchSelector: () => null,
}),
);
vi.mock(
"@posthog/ui/features/git-interaction/components/CloudGitInteractionHeader",
() => ({ CloudGitInteractionHeader: () => <div>cloud actions</div> }),
);
vi.mock(
"@posthog/ui/features/git-interaction/components/TaskActionsMenu",
() => ({
TaskActionsMenu: () => <div>task menu</div>,
}),
);
vi.mock("@posthog/ui/features/sessions/components/StopCloudRunButton", () => ({
StopCloudRunButton: () => <div>stop cloud run</div>,
}));
vi.mock("@posthog/ui/features/diff-stats/DiffStatsBadge", () => ({
DiffStatsBadge: () => null,
}));
vi.mock("@posthog/ui/primitives/Tooltip", () => ({
Tooltip: ({ children }: { children: ReactNode }) => children,
}));
import { TaskHeaderActions } from "./TaskHeaderActions";
const task = { id: "task-1", title: "Fix the bug" } as Task;
function renderActions() {
render(
<Theme>
<TaskHeaderActions task={task} />
</Theme>,
);
}
describe("TaskHeaderActions", () => {
it("does not show workspace-dependent actions before workspaces load", () => {
useWorkspace.mockReturnValue(null);
useWorkspaceLoaded.mockReturnValue(false);
renderActions();
expect(screen.queryByText("Continue in cloud")).not.toBeInTheDocument();
expect(screen.queryByText("task menu")).not.toBeInTheDocument();
});
it("shows cloud controls for a loaded cloud workspace", () => {
useWorkspace.mockReturnValue({ mode: "cloud" });
useWorkspaceLoaded.mockReturnValue(true);
renderActions();
expect(screen.getByText("stop cloud run")).toBeInTheDocument();
expect(screen.getByText("cloud actions")).toBeInTheDocument();
expect(screen.getByText("task menu")).toBeInTheDocument();
expect(screen.queryByText("Continue in cloud")).not.toBeInTheDocument();
});
});