minyeamer commented on code in PR #71558: URL: https://github.com/apache/airflow/pull/71558#discussion_r4192028015
########## airflow-core/src/airflow/ui/src/pages/TimeSchedule/TimeSchedule.test.tsx: ########## @@ -0,0 +1,417 @@ +/*! + * 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 { ChakraProvider, defaultSystem } from "@chakra-ui/react"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import "@testing-library/jest-dom"; +import { fireEvent, render as baseRender, screen, waitFor, within } from "@testing-library/react"; +import i18n from "i18next"; +import { initReactI18next } from "react-i18next"; +import { MemoryRouter } from "react-router-dom"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +import { + TIME_SCHEDULE_AGGREGATION_MODE_KEY, + TIME_SCHEDULE_DAG_RUN_LIMIT_KEY, + TIME_SCHEDULE_SCHEDULED_ONLY_KEY, + TIME_SCHEDULE_VIEW_MODE_KEY, +} from "src/constants/localStorage"; +import { TimezoneContext } from "src/context/timezone"; + +import { TimeSchedule } from "./TimeSchedule"; + +type StreamItem = { + readonly dag_id: string; + readonly dag_run_id: string; + readonly duration_ms: number; + readonly end_date: string | null; + readonly is_placeholder: boolean; + readonly is_planned: boolean; + readonly is_time_scheduled: boolean; + readonly label: string; + readonly run_count: number; + readonly start_date: string | null; + readonly state: "failed" | "planned" | "success"; +}; + +type StreamBatch = { + readonly dag_run_count: number; + readonly items: Array<StreamItem>; +}; + +const { configResponse, fetchTimeSchedule } = vi.hoisted(() => ({ + configResponse: { current: { multi_team: false } }, + fetchTimeSchedule: vi.fn<(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>>(), +})); + +const TIME_SCHEDULE_STORAGE_KEYS = [ + TIME_SCHEDULE_VIEW_MODE_KEY, + TIME_SCHEDULE_AGGREGATION_MODE_KEY, + TIME_SCHEDULE_DAG_RUN_LIMIT_KEY, + TIME_SCHEDULE_SCHEDULED_ONLY_KEY, +]; + +const createStreamItem = (overrides: Partial<StreamItem> = {}): StreamItem => ({ + dag_id: "example_dag", + dag_run_id: "run-1", + duration_ms: 60_000, + end_date: "2024-01-01T00:01:00Z", + is_placeholder: false, + is_planned: false, + is_time_scheduled: true, + label: "example_dag", + run_count: 1, + start_date: "2024-01-01T00:00:00Z", + state: "success", + ...overrides, +}); + +const defaultBatches: Array<StreamBatch> = [ + { dag_run_count: 1, items: [createStreamItem()] }, + { + dag_run_count: 1, + items: [ + createStreamItem({ + dag_id: "another_dag", + dag_run_id: "run-2", + duration_ms: 120_000, + end_date: "2024-01-01T02:02:00Z", + label: "another_dag", + start_date: "2024-01-01T02:00:00Z", + state: "failed", + }), + ], + }, +]; + +const createStreamResponse = (batches: Array<StreamBatch> = defaultBatches) => + new Response(`${batches.map((batch) => JSON.stringify(batch)).join("\n")}\n`, { + headers: { "Content-Type": "application/x-ndjson" }, + status: 200, + }); + +const render = (initialEntry = "/time_schedule", selectedTimezone = "UTC") => + baseRender( + <QueryClientProvider client={new QueryClient()}> + <TimezoneContext.Provider value={{ selectedTimezone, setSelectedTimezone: vi.fn() }}> + <ChakraProvider value={defaultSystem}> + <MemoryRouter initialEntries={[initialEntry]}> + <TimeSchedule /> + </MemoryRouter> + </ChakraProvider> + </TimezoneContext.Provider> + </QueryClientProvider>, + ); Review Comment: ```typescript import { AppWrapper } from "src/utils/AppWrapper"; ``` ```suggestion baseRender(<AppWrapper initialEntries={[initialEntry]} />); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
