Skip to content

Commit b15fa21

Browse files
authored
Hotfix RunDetails Tests (#1187)
1 parent 1c5aec0 commit b15fa21

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/components/PipelineRun/RunDetails.test.tsx

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ vi.mock("@/hooks/usePipelineRunData");
3939
vi.mock("@/services/pipelineRunService");
4040
vi.mock("@/providers/BackendProvider");
4141

42+
vi.mock("@/hooks/useUserDetails", () => ({
43+
useUserDetails: vi.fn(() => ({
44+
data: {
45+
name: "test-user",
46+
permissions: {
47+
read: true,
48+
write: true,
49+
},
50+
},
51+
})),
52+
}));
53+
4254
describe("<RunDetails/>", () => {
4355
const queryClient = new QueryClient({
4456
defaultOptions: {
@@ -237,7 +249,7 @@ describe("<RunDetails/>", () => {
237249
});
238250

239251
describe("Cancel Pipeline Run Button", () => {
240-
test("should render cancel button when status is RUNNING", async () => {
252+
test("should render cancel button when status is RUNNING and user is the creator of the run", async () => {
241253
// arrange
242254
vi.mocked(usePipelineRunData).mockReturnValue({
243255
executionData: {
@@ -276,6 +288,35 @@ describe("<RunDetails/>", () => {
276288
const cancelButton = screen.queryByTestId("cancel-pipeline-run-button");
277289
expect(cancelButton).not.toBeInTheDocument();
278290
});
291+
292+
test("should NOT render cancel button when the user is not the creator of the run", async () => {
293+
// arrange
294+
const pipelineRunWithDifferentCreator = {
295+
...mockPipelineRun,
296+
created_by: "different-user",
297+
};
298+
299+
vi.mocked(pipelineRunService.fetchPipelineRunById).mockResolvedValue(
300+
pipelineRunWithDifferentCreator,
301+
);
302+
303+
vi.mocked(usePipelineRunData).mockReturnValue({
304+
executionData: {
305+
details: mockExecutionDetails,
306+
state: mockRunningExecutionState,
307+
},
308+
rootExecutionId: "test-execution-id",
309+
isLoading: false,
310+
error: null,
311+
});
312+
313+
// act
314+
await act(async () => renderWithQueryClient(<RunDetails />));
315+
316+
// assert
317+
const cancelButton = screen.queryByTestId("cancel-pipeline-run-button");
318+
expect(cancelButton).not.toBeInTheDocument();
319+
});
279320
});
280321

281322
describe("Rerun Pipeline Run Button", () => {

src/components/shared/ManageComponent/PublishComponent.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { HydratedComponentReference } from "@/utils/componentSpec";
88
import { PublishComponent } from "./PublishComponent";
99

1010
// Mock the hooks
11-
vi.mock("./hooks/useUserDetails", () => ({
11+
vi.mock("@/hooks/useUserDetails", () => ({
1212
useUserDetails: vi.fn(() => ({
1313
data: {
1414
name: "TestUser",

0 commit comments

Comments
 (0)