Skip to content
Merged
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
60 changes: 60 additions & 0 deletions airflow-core/src/airflow/ui/src/pages/XCom/XComModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
*/
import "@testing-library/jest-dom/vitest";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { http, HttpResponse } from "msw";
import { afterEach, expect, it, vi } from "vitest";

import { XcomService } from "openapi/requests";

import { server } from "src/mocks/server";
import { Wrapper } from "src/utils/Wrapper";

import XComModal from "./XComModal";
Expand Down Expand Up @@ -80,3 +82,61 @@ it("edits the selected regional XCom without using the colliding public map coor
);
expect(fetch).toHaveBeenCalledWith(expect.objectContaining({ regionId, regionIndex: 3 }));
});

it.each([
{ label: "numeric string", value: "123" },
{ label: "boolean string", value: "false" },
{ label: "null string", value: "null" },
{ label: "object string", value: '{"count":1}' },
{ label: "array string", value: "[1,2]" },
{ label: "quoted string", value: '"quoted"' },
{ label: "empty string", value: "" },
{ label: "multiline string", value: "first\nsecond" },
])("preserves a stored $label when saving without edits", async ({ value }) => {
let deserialize: string | null = null;
let stringify: string | null = null;
const update = vi.fn();

server.use(
http.get("/api/v2/dags/dag/dagRuns/run/taskInstances/task/xcomEntries/return_value", ({ request }) => {
const url = new URL(request.url);

deserialize = url.searchParams.get("deserialize");
stringify = url.searchParams.get("stringify");

return HttpResponse.json({ key: "return_value", value });
}),
http.patch(
"/api/v2/dags/dag/dagRuns/run/taskInstances/task/xcomEntries/return_value",
async ({ request }) => {
update(await request.json());

return HttpResponse.json({ key: "return_value", value });
},
),
);

render(
<XComModal
dagId="dag"
isOpen
mapIndex={-1}
mode="edit"
onClose={vi.fn()}
runId="run"
taskId="task"
xcomKey="return_value"
/>,
{ wrapper: Wrapper },
);

const editorValue = JSON.stringify(value, undefined, 2);

await waitFor(() => expect(screen.getByTestId("editor").textContent).toBe(editorValue));
expect(deserialize).toBe("false");
expect(stringify).toBe("false");

fireEvent.click(screen.getByRole("button", { name: "common:modal.save" }));

await waitFor(() => expect(update).toHaveBeenCalledWith({ map_index: -1, value }));
});
6 changes: 4 additions & 2 deletions airflow-core/src/airflow/ui/src/pages/XCom/XComModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ const XComModal = ({
{
dagId,
dagRunId: runId,
deserialize: true,
// Editing needs the stored type; display deserialization can parse JSON-looking strings.
deserialize: false,
mapIndex,
regionId,
regionIndex,
stringify: false,
taskId,
xcomKey: xcomKey ?? "",
},
Expand All @@ -88,7 +90,7 @@ const XComModal = ({
if (isOpen && isEditMode && data) {
const val = data.value;

setValue(typeof val === "string" ? val : JSON.stringify(val, undefined, 2));
setValue(JSON.stringify(val, undefined, 2));
}
}, [data, isEditMode, isOpen]);

Expand Down
Loading