Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
mockIsAuthorized,
mockGetToken,
mockFetch,
mockUseExecutionDataOptional,
} = vi.hoisted(() => ({
navigateMock: vi.fn(),
notifyMock: vi.fn(),
Expand All @@ -31,6 +32,7 @@ const {
mockIsAuthorized: vi.fn(),
mockGetToken: vi.fn(),
mockFetch: vi.fn(),
mockUseExecutionDataOptional: vi.fn(),
}));

// Set up mocks
Expand Down Expand Up @@ -67,6 +69,10 @@ vi.mock("@/utils/submitPipeline", () => ({
submitPipelineRun: mockSubmitPipelineRun,
}));

vi.mock("@/providers/ExecutionDataProvider", () => ({
useExecutionDataOptional: mockUseExecutionDataOptional,
}));

const testOrigin = import.meta.env.VITE_BASE_URL || "http://localhost:3000";

Object.defineProperty(window, "location", {
Expand Down Expand Up @@ -108,6 +114,7 @@ describe("<RerunPipelineButton/>", () => {
mockIsAuthorized.mockReturnValue(true);
mockGetToken.mockReturnValue("mock-token");
mockAwaitAuthorization.mockClear();
mockUseExecutionDataOptional.mockReturnValue(undefined);
});

afterEach(async () => {
Expand Down Expand Up @@ -334,4 +341,81 @@ describe("<RerunPipelineButton/>", () => {
);
});
});

test("passes taskArguments from execution data to submitPipelineRun", async () => {
const mockTaskArguments = {
input_param: "test_value",
another_param: "another_value",
};

mockUseExecutionDataOptional.mockReturnValue({
rootDetails: {
task_spec: {
arguments: mockTaskArguments,
},
},
});

mockSubmitPipelineRun.mockImplementation(async (_, __, { onSuccess }) => {
onSuccess({ id: 456 });
});

await act(async () => {
renderWithProviders(
<RerunPipelineButton componentSpec={componentSpec} />,
);
});

const rerunButton = screen.getByTestId("rerun-pipeline-button");

await act(async () => {
fireEvent.click(rerunButton);
});

await waitFor(() => {
expect(mockSubmitPipelineRun).toHaveBeenCalledWith(
componentSpec,
expect.any(String),
expect.objectContaining({
taskArguments: mockTaskArguments,
authorizationToken: "mock-token",
onSuccess: expect.any(Function),
onError: expect.any(Function),
}),
);
});
});

test("passes undefined taskArguments when execution data is not available", async () => {
mockUseExecutionDataOptional.mockReturnValue(undefined);

mockSubmitPipelineRun.mockImplementation(async (_, __, { onSuccess }) => {
onSuccess({ id: 789 });
});

await act(async () => {
renderWithProviders(
<RerunPipelineButton componentSpec={componentSpec} />,
);
});

const rerunButton = screen.getByTestId("rerun-pipeline-button");

await act(async () => {
fireEvent.click(rerunButton);
});

await waitFor(() => {
expect(mockSubmitPipelineRun).toHaveBeenCalledWith(
componentSpec,
expect.any(String),
expect.objectContaining({
taskArguments: undefined,
authorizationToken: "mock-token",
onSuccess: expect.any(Function),
onError: expect.any(Function),
}),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useAwaitAuthorization } from "@/components/shared/Authentication/useAwa
import TooltipButton from "@/components/shared/Buttons/TooltipButton";
import useToastNotification from "@/hooks/useToastNotification";
import { useBackend } from "@/providers/BackendProvider";
import { useExecutionDataOptional } from "@/providers/ExecutionDataProvider";
import { APP_ROUTES } from "@/routes/router";
import type { PipelineRun } from "@/types/pipelineRun";
import type { ComponentSpec } from "@/utils/componentSpec";
Expand All @@ -24,6 +25,7 @@ export const RerunPipelineButton = ({
const { backendUrl } = useBackend();
const navigate = useNavigate();
const notify = useToastNotification();
const executionData = useExecutionDataOptional();

const { awaitAuthorization, isAuthorized } = useAwaitAuthorization();
const { getToken } = useAuthLocalStorage();
Expand Down Expand Up @@ -59,6 +61,7 @@ export const RerunPipelineButton = ({

return new Promise<PipelineRun>((resolve, reject) => {
submitPipelineRun(componentSpec, backendUrl, {
taskArguments: executionData?.rootDetails?.task_spec.arguments,
authorizationToken,
onSuccess: resolve,
onError: reject,
Expand Down
Loading