Skip to content

Commit 6bfafda

Browse files
authored
Move dag.doc_md test from app-level to component-level (apache#47103)
1 parent 6faa429 commit 6bfafda

File tree

2 files changed

+64
-45
lines changed

2 files changed

+64
-45
lines changed

airflow/ui/src/mocks/handlers/dag.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,47 @@
2020
/* eslint-disable unicorn/no-null */
2121
import { http, HttpResponse, type HttpHandler } from "msw";
2222

23+
export const MOCK_DAG = {
24+
asset_expression: null,
25+
catchup: false,
26+
concurrency: 16,
27+
dag_display_name: "tutorial_taskflow_api",
28+
dag_id: "tutorial_taskflow_api",
29+
dag_run_timeout: null,
30+
default_view: "grid",
31+
description: null,
32+
doc_md:
33+
"\n ### TaskFlow API Tutorial Documentation\n This is a simple data pipeline example which demonstrates the use of\n the TaskFlow API using three simple tasks for Extract, Transform, and Load.\n Documentation that goes along with the Airflow TaskFlow API tutorial is\n located\n [here](https://airflow.apache.org/docs/apache-airflow/stable/tutorial_taskflow_api.html)\n ",
34+
end_date: null,
35+
file_token:
36+
".eJw9yUsOgCAMBcC7cAB7JPISizR82kCJcnvjxtUsJlDWxlQwPEvhjU7TV0pk27N2goxU9f7lB80qxxPXJF-uQ1CjY5avI0wO2-EFouohiw.fhdU5u0Pb7lElEd-AUUXqjHSsdo",
37+
fileloc: "/airflow/dags/tutorial_taskflow_api.py",
38+
has_import_errors: false,
39+
has_task_concurrency_limits: false,
40+
is_active: true,
41+
is_paused: false,
42+
is_paused_upon_creation: null,
43+
last_expired: null,
44+
last_parsed: "2025-01-13T04:33:54.141792Z",
45+
last_parsed_time: "2025-01-13T04:34:13.543097Z",
46+
max_active_runs: 16,
47+
max_active_tasks: 16,
48+
max_consecutive_failed_dag_runs: 0,
49+
next_dagrun: null,
50+
next_dagrun_create_after: null,
51+
next_dagrun_data_interval_end: null,
52+
next_dagrun_data_interval_start: null,
53+
owners: ["airflow"],
54+
params: {},
55+
render_template_as_native_obj: false,
56+
start_date: "2021-01-01T00:00:00Z",
57+
tags: [{ dag_id: "tutorial_taskflow_api", name: "example" }],
58+
template_search_path: null,
59+
timetable_description: "Never, external triggers only",
60+
timetable_summary: null,
61+
timezone: "UTC",
62+
};
63+
2364
export const handlers: Array<HttpHandler> = [
24-
http.get("/public/dags/tutorial_taskflow_api/details", () =>
25-
HttpResponse.json({
26-
asset_expression: null,
27-
catchup: false,
28-
concurrency: 16,
29-
dag_display_name: "tutorial_taskflow_api",
30-
dag_id: "tutorial_taskflow_api",
31-
dag_run_timeout: null,
32-
default_view: "grid",
33-
description: null,
34-
doc_md:
35-
"\n ### TaskFlow API Tutorial Documentation\n This is a simple data pipeline example which demonstrates the use of\n the TaskFlow API using three simple tasks for Extract, Transform, and Load.\n Documentation that goes along with the Airflow TaskFlow API tutorial is\n located\n [here](https://airflow.apache.org/docs/apache-airflow/stable/tutorial_taskflow_api.html)\n ",
36-
end_date: null,
37-
file_token:
38-
".eJw9yUsOgCAMBcC7cAB7JPISizR82kCJcnvjxtUsJlDWxlQwPEvhjU7TV0pk27N2goxU9f7lB80qxxPXJF-uQ1CjY5avI0wO2-EFouohiw.fhdU5u0Pb7lElEd-AUUXqjHSsdo",
39-
fileloc: "/airflow/dags/tutorial_taskflow_api.py",
40-
has_import_errors: false,
41-
has_task_concurrency_limits: false,
42-
is_active: true,
43-
is_paused: false,
44-
is_paused_upon_creation: null,
45-
last_expired: null,
46-
last_parsed: "2025-01-13T04:33:54.141792Z",
47-
last_parsed_time: "2025-01-13T04:34:13.543097Z",
48-
max_active_runs: 16,
49-
max_active_tasks: 16,
50-
max_consecutive_failed_dag_runs: 0,
51-
next_dagrun: null,
52-
next_dagrun_create_after: null,
53-
next_dagrun_data_interval_end: null,
54-
next_dagrun_data_interval_start: null,
55-
owners: ["airflow"],
56-
params: {},
57-
render_template_as_native_obj: false,
58-
start_date: "2021-01-01T00:00:00Z",
59-
tags: [{ dag_id: "tutorial_taskflow_api", name: "example" }],
60-
template_search_path: null,
61-
timetable_description: "Never, external triggers only",
62-
timetable_summary: null,
63-
timezone: "UTC",
64-
}),
65-
),
65+
http.get("/public/dags/tutorial_taskflow_api/details", () => HttpResponse.json(MOCK_DAG)),
6666
];

airflow/ui/src/pages/Dag/Dag.test.tsx renamed to airflow/ui/src/pages/Dag/DagHeader.test.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ import { render, screen, waitFor } from "@testing-library/react";
2121
import { setupServer, type SetupServerApi } from "msw/node";
2222
import { afterEach, describe, it, expect, beforeAll, afterAll } from "vitest";
2323

24+
import type { DAGDetailsResponse } from "openapi/requests/types.gen";
2425
import { handlers } from "src/mocks/handlers";
25-
import { AppWrapper } from "src/utils/AppWrapper";
26+
import { MOCK_DAG } from "src/mocks/handlers/dag";
27+
import { BaseWrapper } from "src/utils/Wrapper";
28+
29+
import { Header } from "./Header";
2630

2731
let server: SetupServerApi;
2832

@@ -35,13 +39,28 @@ afterEach(() => server.resetHandlers());
3539
afterAll(() => server.close());
3640

3741
describe("Dag Documentation Modal", () => {
38-
it("Display documentation button only when docs_md is present", async () => {
39-
render(<AppWrapper initialEntries={["/dags/tutorial_taskflow_api"]} />);
42+
it("Display documentation button when doc_md is present", async () => {
43+
render(
44+
<BaseWrapper>
45+
<Header dag={MOCK_DAG as unknown as DAGDetailsResponse} />
46+
</BaseWrapper>,
47+
);
4048

4149
await waitFor(() => expect(screen.getByTestId("markdown-button")).toBeInTheDocument());
4250
await waitFor(() => screen.getByTestId("markdown-button").click());
4351
await waitFor(() =>
4452
expect(screen.getByText(/taskflow api tutorial documentation/iu)).toBeInTheDocument(),
4553
);
4654
});
55+
56+
it("Do not display documentation button only doc_md is not present", () => {
57+
render(
58+
<BaseWrapper>
59+
{/* eslint-disable-next-line unicorn/no-null */}
60+
<Header dag={{ ...MOCK_DAG, doc_md: null } as unknown as DAGDetailsResponse} />
61+
</BaseWrapper>,
62+
);
63+
64+
expect(screen.queryByTestId("markdown-button")).toBeNull();
65+
});
4766
});

0 commit comments

Comments
 (0)