Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for dag filtering in home page and dag documentation modal #45607

Merged
merged 5 commits into from
Jan 24, 2025
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
1 change: 1 addition & 0 deletions airflow/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"eslint-plugin-unicorn": "^55.0.0",
"globals": "^15.9.0",
"happy-dom": "^15.10.2",
"msw": "^2.7.0",
"prettier": "^3.3.3",
"typescript": "~5.5.4",
"typescript-eslint": "^8.5.0",
Expand Down
348 changes: 341 additions & 7 deletions airflow/ui/pnpm-lock.yaml

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions airflow/ui/src/components/DisplayMarkdownButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ const DisplayMarkdownButton = ({

return (
<Box>
<Button onClick={() => setIsDocsOpen(true)} variant="outline">
<Button data-testid="markdown-button" onClick={() => setIsDocsOpen(true)} variant="outline">
{icon}
{text}
</Button>
<Dialog.Root onOpenChange={() => setIsDocsOpen(false)} open={isDocsOpen} size="md">
<Dialog.Root
data-testid="markdown-modal"
onOpenChange={() => setIsDocsOpen(false)}
open={isDocsOpen}
size="md"
>
<Dialog.Content backdrop>
<Dialog.Header bg="blue.muted">
<Heading size="xl">{header}</Heading>
Expand Down
59 changes: 59 additions & 0 deletions airflow/ui/src/mocks/handlers/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { http, HttpResponse, type HttpHandler } from "msw";

export const handlers: Array<HttpHandler> = [
http.get("/ui/config", () =>
HttpResponse.json({
audit_view_excluded_events: "gantt,landing_times,tries,duration,calendar,graph,grid,tree,tree_data",
audit_view_included_events: "",
auto_refresh_interval: 3,
default_ui_timezone: "UTC",
default_wrap: false,
enable_swagger_ui: true,
hide_paused_dags_by_default: false,
instance_name: "Airflow",
instance_name_has_markup: false,
is_k8s: false,
navbar_color: "#fff",
navbar_hover_color: "#eee",
navbar_logo_text_color: "#51504f",
navbar_text_color: "#51504f",
navbar_text_hover_color: "#51504f",
page_size: 15,
require_confirmation_dag_change: false,
state_color_mapping: {
deferred: "mediumpurple",
failed: "red",
queued: "gray",
removed: "lightgrey",
restarting: "violet",
running: "lime",
scheduled: "tan",
skipped: "hotpink",
success: "green",
up_for_reschedule: "turquoise",
up_for_retry: "gold",
upstream_failed: "orange",
},
test_connection: "Disabled",
warn_deployment_exposure: true,
}),
),
];
66 changes: 66 additions & 0 deletions airflow/ui/src/mocks/handlers/dag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/* eslint-disable unicorn/no-null */
import { http, HttpResponse, type HttpHandler } from "msw";

export const handlers: Array<HttpHandler> = [
http.get("/public/dags/tutorial_taskflow_api/details", () =>
HttpResponse.json({
asset_expression: null,
catchup: false,
concurrency: 16,
dag_display_name: "tutorial_taskflow_api",
dag_id: "tutorial_taskflow_api",
dag_run_timeout: null,
default_view: "grid",
description: null,
doc_md:
"\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 ",
end_date: null,
file_token:
".eJw9yUsOgCAMBcC7cAB7JPISizR82kCJcnvjxtUsJlDWxlQwPEvhjU7TV0pk27N2goxU9f7lB80qxxPXJF-uQ1CjY5avI0wO2-EFouohiw.fhdU5u0Pb7lElEd-AUUXqjHSsdo",
fileloc: "/airflow/dags/tutorial_taskflow_api.py",
has_import_errors: false,
has_task_concurrency_limits: false,
is_active: true,
is_paused: false,
is_paused_upon_creation: null,
last_expired: null,
last_parsed: "2025-01-13T04:33:54.141792Z",
last_parsed_time: "2025-01-13T04:34:13.543097Z",
max_active_runs: 16,
max_active_tasks: 16,
max_consecutive_failed_dag_runs: 0,
next_dagrun: null,
next_dagrun_create_after: null,
next_dagrun_data_interval_end: null,
next_dagrun_data_interval_start: null,
owners: ["airflow"],
params: {},
render_template_as_native_obj: false,
start_date: "2021-01-01T00:00:00Z",
tags: [{ dag_id: "tutorial_taskflow_api", name: "example" }],
template_search_path: null,
timetable_description: "Never, external triggers only",
timetable_summary: null,
timezone: "UTC",
}),
),
];
193 changes: 193 additions & 0 deletions airflow/ui/src/mocks/handlers/dags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/* eslint-disable unicorn/no-null */
import { http, HttpResponse, type HttpHandler } from "msw";

export const handlers: Array<HttpHandler> = [
http.get("/ui/dags/recent_dag_runs", ({ request }) => {
const url = new URL(request.url);
const lastDagRunState = url.searchParams.get("last_dag_run_state");
const successDag = {
dag_display_name: "tutorial_taskflow_api_success",
dag_id: "tutorial_taskflow_api_success",
default_view: "grid",
file_token:
".eJw9yUsOgCAMBcC7cAB7JPISizR82kCJcnvjxtUsJlDWxlQwPEvhjU7TV0pk27N2goxU9f7lB80qxxPXJF-uQ1CjY5avI0wO2-EFouohiw.fhdU5u0Pb7lElEd-AUUXqjHSsdo",
fileloc: "/airflow/dags/tutorial_taskflow_api.py",
has_import_errors: false,
has_task_concurrency_limits: false,
is_active: true,
is_paused: false,
last_parsed_time: "2025-01-13T07:34:01.593459Z",
latest_dag_runs: [
{
conf: {},
dag_id: "tutorial_taskflow_api",
dag_run_id: "manual__2025-01-13T04:33:58.387988+00:00",
data_interval_end: "2025-01-13T04:33:58.396323Z",
data_interval_start: "2025-01-13T04:33:58.396323Z",
end_date: "2025-01-13T04:34:12.143831Z",
external_trigger: true,
last_scheduling_decision: "2025-01-13T04:34:12.137382Z",
logical_date: "2025-01-13T04:33:58.396323Z",
queued_at: "2025-01-13T04:33:58.404628Z",
run_type: "manual",
start_date: "2025-01-13T04:33:58.496197Z",
state: "success",
triggered_by: "rest_api",
},
],
max_active_runs: 16,
max_active_tasks: 16,
max_consecutive_failed_dag_runs: 0,
owners: ["airflow"],
tags: [{ dag_id: "tutorial_taskflow_api_success", name: "example" }],
timetable_description: "Never, external triggers only",
};
const failedDag = {
dag_display_name: "tutorial_taskflow_api_failed",
dag_id: "tutorial_taskflow_api_failed",
default_view: "grid",
file_token:
".eJw9yUsOgCAMBcC7cAB7JPISizR82kCJcnvjxtUsJlDWxlQwPEvhjU7TV0pk27N2goxU9f7lB80qxxPXJF-uQ1CjY5avI0wO2-EFouohiw.fhdU5u0Pb7lElEd-AUUXqjHSsdo",
fileloc: "/airflow/dags/tutorial_taskflow_api_failed.py",
has_import_errors: false,
has_task_concurrency_limits: false,
is_active: true,
is_paused: false,
last_parsed_time: "2025-01-13T07:34:01.593459Z",
latest_dag_runs: [
{
conf: {},
dag_id: "tutorial_taskflow_api",
dag_run_id: "manual__2025-01-13T04:33:58.387988+00:00",
data_interval_end: "2025-01-13T04:33:58.396323Z",
data_interval_start: "2025-01-13T04:33:58.396323Z",
end_date: "2025-01-13T04:34:12.143831Z",
external_trigger: true,
last_scheduling_decision: "2025-01-13T04:34:12.137382Z",
logical_date: "2025-01-13T04:33:58.396323Z",
queued_at: "2025-01-13T04:33:58.404628Z",
run_type: "manual",
start_date: "2025-01-13T04:33:58.496197Z",
state: "success",
triggered_by: "rest_api",
},
],
max_active_runs: 16,
max_active_tasks: 16,
max_consecutive_failed_dag_runs: 0,
owners: ["airflow"],
tags: [{ dag_id: "tutorial_taskflow_api_failed", name: "example" }],
timetable_description: "Never, external triggers only",
};

if (lastDagRunState === "success") {
return HttpResponse.json({
dags: [successDag],
total_entries: 1,
});
} else if (lastDagRunState === "failed") {
return HttpResponse.json({
dags: [failedDag],
total_entries: 1,
});
} else {
return HttpResponse.json({
dags: [failedDag],
total_entries: 1,
});
}
}),
http.get("/public/dags", ({ request }) => {
const url = new URL(request.url);
const lastDagRunState = url.searchParams.get("last_dag_run_state");
const failedDag = {
dag_display_name: "tutorial_taskflow_api_failed",
dag_id: "tutorial_taskflow_api_failed",
default_view: "grid",
description: null,
file_token:
".eJw9yUsOgCAMBcC7cAB7JPISizR82kCJcnvjxtUsJlDWxlQwPEvhjU7TV0pk27N2goxU9f7lB80qxxPXJF-uQ1CjY5avI0wO2-EFouohiw.fhdU5u0Pb7lElEd-AUUXqjHSsdo",
fileloc: "/airflow/dags/tutorial_taskflow_api_failed.py",
has_import_errors: false,
has_task_concurrency_limits: false,
is_active: true,
is_paused: false,
last_expired: null,
last_parsed_time: "2025-01-13T06:45:33.009609Z",
max_active_runs: 16,
max_active_tasks: 16,
max_consecutive_failed_dag_runs: 0,
next_dagrun: null,
next_dagrun_create_after: null,
next_dagrun_data_interval_end: null,
next_dagrun_data_interval_start: null,
owners: ["airflow"],
tags: [{ dag_id: "tutorial_taskflow_api_failed", name: "example" }],
timetable_description: "Never, external triggers only",
timetable_summary: null,
};

const successDag = {
dag_display_name: "tutorial_taskflow_api_success",
dag_id: "tutorial_taskflow_api_success",
default_view: "grid",
description: null,
file_token:
".eJw9yUsOgCAMBcC7cAB7JPISizR82kCJcnvjxtUsJlDWxlQwPEvhjU7TV0pk27N2goxU9f7lB80qxxPXJF-uQ1CjY5avI0wO2-EFouohiw.fhdU5u0Pb7lElEd-AUUXqjHSsdo",
fileloc: "/airflow/dags/tutorial_taskflow_api_success.py",
has_import_errors: false,
has_task_concurrency_limits: false,
is_active: true,
is_paused: false,
last_expired: null,
last_parsed_time: "2025-01-13T06:45:33.009609Z",
max_active_runs: 16,
max_active_tasks: 16,
max_consecutive_failed_dag_runs: 0,
next_dagrun: null,
next_dagrun_create_after: null,
next_dagrun_data_interval_end: null,
next_dagrun_data_interval_start: null,
owners: ["airflow"],
tags: [{ dag_id: "tutorial_taskflow_api_success", name: "example" }],
timetable_description: "Never, external triggers only",
timetable_summary: null,
};

if (lastDagRunState === "failed") {
return HttpResponse.json({
dags: [failedDag],
total_entries: 1,
});
} else if (lastDagRunState === "success") {
return HttpResponse.json({
dags: [successDag],
total_entries: 1,
});
} else {
return HttpResponse.json({
dags: [failedDag, successDag],
total_entries: 2,
});
}
}),
];
23 changes: 23 additions & 0 deletions airflow/ui/src/mocks/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { handlers as configHandlers } from "./config";
import { handlers as dagHandlers } from "./dag";
import { handlers as dagsHandlers } from "./dags";

export const handlers = [...configHandlers, ...dagHandlers, ...dagsHandlers];
Loading