You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "tirkarthi (via GitHub)" <gi...@apache.org> on 2025/01/13 08:39:54 UTC

[PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

tirkarthi opened a new pull request, #45607:
URL: https://github.com/apache/airflow/pull/45607

   This adds basic tests to ensure filter buttons in dags list page works. This also adds tests for dag documentation button and modal opening flow on click.
   
   * Create a router that has all the routes configured to a memory router. https://api.reactrouter.com/v7/functions/react_router.createMemoryRouter.html
   * Create a wrapper that uses the configured router and also accepts `initialEntries` to load the tests in a given URL location for assertion. There were some issues in using existing `Wrapper.tsx` with the changes in existing tests so created using `AppWrapper.tsx` with the changes to keep them separate.
   * vitest recommends using msw for mocking requests. https://vitest.dev/guide/mocking#requests
   * Handlers structured as per best practices to mock endpoints : https://mswjs.io/docs/best-practices/structuring-handlers
   * On each test create a server with the handlers so that the test data is used.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45607:
URL: https://github.com/apache/airflow/pull/45607#discussion_r1922024020


##########
airflow/ui/src/utils/AppWrapper.tsx:
##########


Review Comment:
   This is really similar to the `Wrapper.tsx` Component. There's just the `router` part that is different. I don't think we need both of them. Just the `AppWrapper` should be enough. If we do need both, we can always re-use one inside of the other. (nest components and use `{children}` to render the extra `          <RouterProvider router={router} />` part)



##########
airflow/ui/src/utils/AppWrapper.tsx:
##########
@@ -0,0 +1,50 @@
+/*!
+ * 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 { RouterProvider } from "react-router-dom";
+import { createMemoryRouter } from "react-router-dom";

Review Comment:
   nit: this import can be merged.



##########
airflow/ui/src/pages/DagsList/DagsList.test.tsx:
##########
@@ -0,0 +1,49 @@
+/*!
+ * 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 "@testing-library/jest-dom";
+import { render, screen, waitFor } from "@testing-library/react";
+import { setupServer, type SetupServerApi } from "msw/node";
+import { afterEach, describe, it, expect, beforeAll, afterAll } from "vitest";
+
+import { handlers } from "src/mocks/handlers";
+import { AppWrapper } from "src/utils/AppWrapper";
+
+let server: SetupServerApi;
+
+beforeAll(() => {
+  server = setupServer(...handlers);
+  server.listen({ onUnhandledRequest: "bypass" });
+});
+
+afterEach(() => server.resetHandlers());
+afterAll(() => server.close());

Review Comment:
   Maybe this setup code should be in the jest setup part ?
   
   Because I am afraid that this will be duplicated in all tests that need the msw mock server.



##########
airflow/ui/src/pages/DagsList/DagsList.test.tsx:
##########
@@ -0,0 +1,49 @@
+/*!
+ * 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 "@testing-library/jest-dom";
+import { render, screen, waitFor } from "@testing-library/react";
+import { setupServer, type SetupServerApi } from "msw/node";
+import { afterEach, describe, it, expect, beforeAll, afterAll } from "vitest";
+
+import { handlers } from "src/mocks/handlers";
+import { AppWrapper } from "src/utils/AppWrapper";
+
+let server: SetupServerApi;
+
+beforeAll(() => {
+  server = setupServer(...handlers);
+  server.listen({ onUnhandledRequest: "bypass" });
+});
+
+afterEach(() => server.resetHandlers());
+afterAll(() => server.close());
+
+describe("Dag Filters", () => {
+  it("Filter by selected last run state", async () => {
+    render(<AppWrapper initialEntries={["/dags"]} />);
+
+    await waitFor(() => expect(screen.getByTestId("dags-success-filter")).toBeInTheDocument());
+    await waitFor(() => screen.getByTestId("dags-success-filter").click());
+    await waitFor(() => expect(screen.getByText(/tutorial_taskflow_api_success/iu)).toBeInTheDocument());

Review Comment:
   Where is the suffix `/iu` coming from ?
   
   I was expecting just the `/tutorial_taskflow_api_success` to be in the document.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "tirkarthi (via GitHub)" <gi...@apache.org>.
tirkarthi commented on code in PR #45607:
URL: https://github.com/apache/airflow/pull/45607#discussion_r1922662946


##########
airflow/ui/src/pages/DagsList/DagsList.test.tsx:
##########
@@ -0,0 +1,49 @@
+/*!
+ * 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 "@testing-library/jest-dom";
+import { render, screen, waitFor } from "@testing-library/react";
+import { setupServer, type SetupServerApi } from "msw/node";
+import { afterEach, describe, it, expect, beforeAll, afterAll } from "vitest";
+
+import { handlers } from "src/mocks/handlers";
+import { AppWrapper } from "src/utils/AppWrapper";
+
+let server: SetupServerApi;
+
+beforeAll(() => {
+  server = setupServer(...handlers);
+  server.listen({ onUnhandledRequest: "bypass" });
+});
+
+afterEach(() => server.resetHandlers());
+afterAll(() => server.close());

Review Comment:
   Thanks, moved the code to `testSetup.ts` .



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "tirkarthi (via GitHub)" <gi...@apache.org>.
tirkarthi commented on PR #45607:
URL: https://github.com/apache/airflow/pull/45607#issuecomment-2613093155

   Rebased against main which had changes to markdown rendering components.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "tirkarthi (via GitHub)" <gi...@apache.org>.
tirkarthi commented on code in PR #45607:
URL: https://github.com/apache/airflow/pull/45607#discussion_r1922664223


##########
airflow/ui/src/pages/DagsList/DagsList.test.tsx:
##########
@@ -0,0 +1,49 @@
+/*!
+ * 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 "@testing-library/jest-dom";
+import { render, screen, waitFor } from "@testing-library/react";
+import { setupServer, type SetupServerApi } from "msw/node";
+import { afterEach, describe, it, expect, beforeAll, afterAll } from "vitest";
+
+import { handlers } from "src/mocks/handlers";
+import { AppWrapper } from "src/utils/AppWrapper";
+
+let server: SetupServerApi;
+
+beforeAll(() => {
+  server = setupServer(...handlers);
+  server.listen({ onUnhandledRequest: "bypass" });
+});
+
+afterEach(() => server.resetHandlers());
+afterAll(() => server.close());
+
+describe("Dag Filters", () => {
+  it("Filter by selected last run state", async () => {
+    render(<AppWrapper initialEntries={["/dags"]} />);
+
+    await waitFor(() => expect(screen.getByTestId("dags-success-filter")).toBeInTheDocument());
+    await waitFor(() => screen.getByTestId("dags-success-filter").click());
+    await waitFor(() => expect(screen.getByText(/tutorial_taskflow_api_success/iu)).toBeInTheDocument());

Review Comment:
   I used regex during testing but made it string as i (case-insensitive), u (unicode) are not needed.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "tirkarthi (via GitHub)" <gi...@apache.org>.
tirkarthi commented on code in PR #45607:
URL: https://github.com/apache/airflow/pull/45607#discussion_r1922661933


##########
airflow/ui/src/utils/AppWrapper.tsx:
##########


Review Comment:
   Thanks, IIRC the issue was around `MemoryRouter` and `Router` with the existing routes configured not playing well as the app expects only one router as children and also some issues with `TimezoneProvider` position. I have made a `BaseWrapper` component and passed the relevant children as suggested to construct `Wrapper` and `AppWrapper` .



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45607:
URL: https://github.com/apache/airflow/pull/45607#discussion_r1922024020


##########
airflow/ui/src/utils/AppWrapper.tsx:
##########


Review Comment:
   They are really similar with `Wrapper.tsx`. You mentioned experiencing some issue re-using the same component. Maybe we can at least factorize it. We can always re-use one inside of the other. (nest components and use `{children}` to render the extra `<RouterProvider router={router} />` part, so all the rest is de-duplicated)



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "tirkarthi (via GitHub)" <gi...@apache.org>.
tirkarthi commented on code in PR #45607:
URL: https://github.com/apache/airflow/pull/45607#discussion_r1929050468


##########
airflow/ui/src/utils/AppWrapper.tsx:
##########


Review Comment:
   Thanks, will try to take it up in other PRs as Brent suggested. 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "bbovenzi (via GitHub)" <gi...@apache.org>.
bbovenzi commented on PR #45607:
URL: https://github.com/apache/airflow/pull/45607#issuecomment-2610910609

   But it looks like we need a rebase


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun merged PR #45607:
URL: https://github.com/apache/airflow/pull/45607


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45607:
URL: https://github.com/apache/airflow/pull/45607#discussion_r1923945504


##########
airflow/ui/src/utils/AppWrapper.tsx:
##########


Review Comment:
   I think you can also factorize the `TimezoneProvider` that both `Wrapper` and `AppWrapper` need.
   
   Also you could always provide the `MemoryRouter` in the base router and not bother with multiple wrapper. (if tests still work like this)



##########
airflow/ui/src/pages/DagsList/DagsList.test.tsx:
##########
@@ -0,0 +1,49 @@
+/*!
+ * 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 "@testing-library/jest-dom";
+import { render, screen, waitFor } from "@testing-library/react";
+import { setupServer, type SetupServerApi } from "msw/node";
+import { afterEach, describe, it, expect, beforeAll, afterAll } from "vitest";
+
+import { handlers } from "src/mocks/handlers";
+import { AppWrapper } from "src/utils/AppWrapper";
+
+let server: SetupServerApi;
+
+beforeAll(() => {
+  server = setupServer(...handlers);
+  server.listen({ onUnhandledRequest: "bypass" });
+});
+
+afterEach(() => server.resetHandlers());
+afterAll(() => server.close());
+
+describe("Dag Filters", () => {
+  it("Filter by selected last run state", async () => {
+    render(<AppWrapper initialEntries={["/dags"]} />);
+
+    await waitFor(() => expect(screen.getByTestId("dags-success-filter")).toBeInTheDocument());
+    await waitFor(() => screen.getByTestId("dags-success-filter").click());
+    await waitFor(() => expect(screen.getByText(/tutorial_taskflow_api_success/iu)).toBeInTheDocument());

Review Comment:
   Got it, thanks.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add tests for dag filtering in home page and dag documentation modal [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #45607:
URL: https://github.com/apache/airflow/pull/45607#discussion_r1922042916


##########
airflow/ui/src/pages/DagsList/DagsList.test.tsx:
##########
@@ -0,0 +1,49 @@
+/*!
+ * 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 "@testing-library/jest-dom";
+import { render, screen, waitFor } from "@testing-library/react";
+import { setupServer, type SetupServerApi } from "msw/node";
+import { afterEach, describe, it, expect, beforeAll, afterAll } from "vitest";
+
+import { handlers } from "src/mocks/handlers";
+import { AppWrapper } from "src/utils/AppWrapper";
+
+let server: SetupServerApi;
+
+beforeAll(() => {
+  server = setupServer(...handlers);
+  server.listen({ onUnhandledRequest: "bypass" });
+});
+
+afterEach(() => server.resetHandlers());
+afterAll(() => server.close());

Review Comment:
   Maybe this setup code should be in the jest setup part ?
   
   Because I am afraid that this will be duplicated in all tests that need the msw mock server.
   
   I don't think we'll ever get a really complex test suite that need splitting, and applying only a subset of handlers.



##########
airflow/ui/src/pages/DagsList/DagsList.test.tsx:
##########
@@ -0,0 +1,49 @@
+/*!
+ * 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 "@testing-library/jest-dom";
+import { render, screen, waitFor } from "@testing-library/react";
+import { setupServer, type SetupServerApi } from "msw/node";
+import { afterEach, describe, it, expect, beforeAll, afterAll } from "vitest";
+
+import { handlers } from "src/mocks/handlers";
+import { AppWrapper } from "src/utils/AppWrapper";
+
+let server: SetupServerApi;
+
+beforeAll(() => {
+  server = setupServer(...handlers);
+  server.listen({ onUnhandledRequest: "bypass" });
+});
+
+afterEach(() => server.resetHandlers());
+afterAll(() => server.close());

Review Comment:
   Maybe this setup code should be in the jest setup part ?
   
   Because I am afraid that this will be duplicated in all tests that need the msw mock server.
   
   I don't think we'll ever get a really complex test suite that need splitting and applying only a subset of handlers.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org