|
| 1 | +/*! |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +import "@testing-library/jest-dom/vitest"; |
| 20 | +import { fireEvent, render, screen, waitFor } from "@testing-library/react"; |
| 21 | +import { afterEach, beforeAll, expect, it, vi } from "vitest"; |
| 22 | + |
| 23 | +import { TaskInstanceService } from "openapi/requests"; |
| 24 | + |
| 25 | +import i18n from "src/i18n/config"; |
| 26 | +import { Wrapper } from "src/utils/Wrapper"; |
| 27 | + |
| 28 | +import dagTranslations from "../../../../public/i18n/locales/en/dag.json"; |
| 29 | +import { ClearExecutionDialog } from "./ClearExecutionDialog"; |
| 30 | + |
| 31 | +beforeAll(() => i18n.addResourceBundle("en", "dag", dagTranslations, true, true)); |
| 32 | +afterEach(() => vi.restoreAllMocks()); |
| 33 | + |
| 34 | +it("keeps stale UUID scope visible when the clear preview rejects an archived execution", async () => { |
| 35 | + const clear = vi |
| 36 | + .spyOn(TaskInstanceService, "postClearTaskInstances") |
| 37 | + .mockRejectedValue({ body: { detail: "Selected execution was archived" }, status: 409 }); |
| 38 | + const onClose = vi.fn(); |
| 39 | + |
| 40 | + render( |
| 41 | + <ClearExecutionDialog |
| 42 | + dagId="dag" |
| 43 | + executions={[ |
| 44 | + { |
| 45 | + id: "archived-uuid", |
| 46 | + map_index: -1, |
| 47 | + region_id: "11111111-1111-1111-1111-111111111111", |
| 48 | + region_index: 3, |
| 49 | + task_display_name: "work", |
| 50 | + task_id: "body.work", |
| 51 | + }, |
| 52 | + ]} |
| 53 | + onClose={onClose} |
| 54 | + open |
| 55 | + runId="run" |
| 56 | + />, |
| 57 | + { wrapper: Wrapper }, |
| 58 | + ); |
| 59 | + expect(await screen.findByText("Selected execution was archived")).toBeVisible(); |
| 60 | + expect(screen.getByRole("button", { name: "Clear selected executions" })).toBeDisabled(); |
| 61 | + expect(clear).toHaveBeenCalledTimes(1); |
| 62 | + expect(clear.mock.lastCall?.[0].requestBody).toMatchObject({ |
| 63 | + dry_run: true, |
| 64 | + task_instance_ids: ["archived-uuid"], |
| 65 | + }); |
| 66 | + expect(onClose).not.toHaveBeenCalled(); |
| 67 | +}); |
| 68 | + |
| 69 | +it("previews and clears UUID seeds with separate whole-expansion and later-loop intent", async () => { |
| 70 | + const clear = vi |
| 71 | + .spyOn(TaskInstanceService, "postClearTaskInstances") |
| 72 | + .mockResolvedValue({ task_instances: [], total_entries: 0 }); |
| 73 | + |
| 74 | + render( |
| 75 | + <ClearExecutionDialog |
| 76 | + dagId="dag" |
| 77 | + executions={[ |
| 78 | + { |
| 79 | + id: "selected-uuid", |
| 80 | + map_index: 1, |
| 81 | + region_id: "11111111-1111-1111-1111-111111111111", |
| 82 | + region_index: 1, |
| 83 | + task_display_name: "mapped", |
| 84 | + task_id: "body.mapped", |
| 85 | + }, |
| 86 | + ]} |
| 87 | + onClose={vi.fn()} |
| 88 | + open |
| 89 | + runId="run" |
| 90 | + />, |
| 91 | + { wrapper: Wrapper }, |
| 92 | + ); |
| 93 | + |
| 94 | + await waitFor(() => |
| 95 | + expect(clear.mock.lastCall?.[0]).toMatchObject({ |
| 96 | + dagId: "dag", |
| 97 | + requestBody: { |
| 98 | + dag_run_id: "run", |
| 99 | + dry_run: true, |
| 100 | + include_downstream: true, |
| 101 | + include_later_loop_iterations: true, |
| 102 | + only_failed: false, |
| 103 | + task_instance_ids: ["selected-uuid"], |
| 104 | + whole_expansion_ids: [], |
| 105 | + }, |
| 106 | + }), |
| 107 | + ); |
| 108 | + fireEvent.click(screen.getByLabelText("Clear whole mapped expansions")); |
| 109 | + fireEvent.click(screen.getByLabelText("Clear later loop iterations")); |
| 110 | + await waitFor(() => |
| 111 | + expect(clear.mock.lastCall?.[0]).toMatchObject({ |
| 112 | + dagId: "dag", |
| 113 | + requestBody: { |
| 114 | + dry_run: true, |
| 115 | + include_later_loop_iterations: false, |
| 116 | + whole_expansion_ids: ["selected-uuid"], |
| 117 | + }, |
| 118 | + }), |
| 119 | + ); |
| 120 | + await waitFor(() => |
| 121 | + expect(screen.getByRole("button", { name: "Clear selected executions" })).toBeEnabled(), |
| 122 | + ); |
| 123 | + fireEvent.click(screen.getByRole("button", { name: "Clear selected executions" })); |
| 124 | + await waitFor(() => |
| 125 | + expect( |
| 126 | + clear.mock.calls.map(([request]) => request).find((request) => request.requestBody.dry_run === false), |
| 127 | + ).toMatchObject({ |
| 128 | + dagId: "dag", |
| 129 | + requestBody: { |
| 130 | + dry_run: false, |
| 131 | + include_downstream: true, |
| 132 | + include_later_loop_iterations: false, |
| 133 | + task_instance_ids: ["selected-uuid"], |
| 134 | + whole_expansion_ids: ["selected-uuid"], |
| 135 | + }, |
| 136 | + }), |
| 137 | + ); |
| 138 | +}); |
0 commit comments