vishakha1411 commented on code in PR #60738: URL: https://github.com/apache/airflow/pull/60738#discussion_r2794771378
########## airflow-core/src/airflow/ui/tests/e2e/specs/connections.spec.ts: ########## @@ -0,0 +1,558 @@ +/*! + * 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 { expect, test } from "@playwright/test"; +import { testConfig, AUTH_FILE } from "playwright.config"; +import { ConnectionsPage } from "tests/e2e/pages/ConnectionsPage"; + +test.describe("Connections Page - List and Display", () => { + let connectionsPage: ConnectionsPage; + const { baseUrl } = testConfig.connection; + + test.beforeEach(({ page }) => { + connectionsPage = new ConnectionsPage(page); + }); + test.beforeAll(async ({ browser }) => { + const context = await browser.newContext({ storageState: AUTH_FILE }); + const page = await context.newPage(); + + await page.request.post(`${baseUrl}/api/v2/connections`, { + data: { + conn_type: "http", + connection_id: "list_seed_conn", + host: "seed.example.com", + }, + }); + }); + + test.afterAll(async ({ browser }) => { + const context = await browser.newContext({ storageState: AUTH_FILE }); + const page = await context.newPage(); + + await page.request.delete(`${baseUrl}/api/v2/connections/list_seed_conn`); + }); + + test("should display connections list page", async () => { + await connectionsPage.navigate(); + + // Verify the page is loaded + expect(connectionsPage.page.url()).toContain("/connections"); + + // Verify table or list is visible + expect(await connectionsPage.connectionsTable.isVisible()).toBeTruthy(); + }); + + test("should display connections with correct columns", async () => { + await connectionsPage.navigate(); + + // Check that we have at least one row + const count = await connectionsPage.getConnectionCount(); + + expect(count).toBeGreaterThanOrEqual(0); + + if (count > 0) { + // Verify connections are listed with expected information + const connectionIds = await connectionsPage.getConnectionIds(); + + expect(connectionIds.length).toBeGreaterThan(0); + } + }); + + test("should have Add button visible", async () => { + await connectionsPage.navigate(); + expect(await connectionsPage.addButton.isVisible()).toBeTruthy(); + }); +}); + +test.describe("Connections Page - CRUD Operations", () => { + let connectionsPage: ConnectionsPage; + const { baseUrl } = testConfig.connection; + const timestamp = Date.now(); + + // Test connection details - using dynamic data + const testConnection = { + conn_type: "postgres", // Adjust based on available connection types in your Airflow instance + connection_id: `test_conn_${timestamp}`, + description: `Test connection created at ${new Date().toISOString()}`, + extra: JSON.stringify({ + options: "-c statement_timeout=5000", + sslmode: "require", + }), + host: `test-host-${timestamp}.example.com`, + login: `test_user_${timestamp}`, + password: `test_password_${timestamp}`, + port: 5432, + schema: "test_db", + }; + + const updatedConnection = { + description: `Updated test connection at ${new Date().toISOString()}`, + host: `updated-host-${timestamp}.example.com`, + login: `updated_user_${timestamp}`, + port: 5433, + }; + + test.beforeEach(({ page }) => { + connectionsPage = new ConnectionsPage(page); + }); + + test.afterAll(async ({ browser }) => { + // Cleanup: Delete test connections via API + const context = await browser.newContext({ storageState: AUTH_FILE }); + const page = await context.newPage(); + + // Delete the test connection + const deleteResponse = await page.request.delete( + `${baseUrl}/api/v2/connections/${testConnection.connection_id}`, + ); + + expect([204, 404]).toContain(deleteResponse.status()); + }); + + test("should create a new connection with all fields", async () => { + test.setTimeout(60_000); // 1 minute for slower browsers like Firefox + await connectionsPage.navigate(); + + // Click add button + await connectionsPage.createConnection(testConnection); + // Verify the connection was created + const exists = await connectionsPage.connectionExists(testConnection.connection_id); + + expect(exists).toBeTruthy(); + }); + + test("should display created connection in list with correct type", async () => { + await connectionsPage.navigate(); + + // Verify the connection is visible with correct details + await connectionsPage.verifyConnectionInList(testConnection.connection_id, testConnection.conn_type); + }); + + test("should edit an existing connection", async () => { + test.setTimeout(60_000); // 1 minute for slower browsers like Firefox + await connectionsPage.navigate(); + + // Verify connection exists before editing + let exists = await connectionsPage.connectionExists(testConnection.connection_id); + + expect(exists).toBeTruthy(); + + // Edit the connection + await connectionsPage.editConnection(testConnection.connection_id, updatedConnection); + + // Verify the connection was updated + // await connectionsPage.navigate(); + exists = await connectionsPage.connectionExists(testConnection.connection_id); + expect(exists).toBeTruthy(); + }); + + test("should delete a connection", async () => { + test.setTimeout(60_000); // 1 minute for slower browsers like Firefox + + // Create a temporary connection for deletion test + const tempConnection = { + conn_type: "postgres", + connection_id: `temp_conn_${timestamp}_delete`, + host: `temp-host-${timestamp}.example.com`, + login: "temp_user", + password: "temp_password", + }; + + await connectionsPage.navigate(); + await connectionsPage.createConnection(tempConnection); + let exists = await connectionsPage.connectionExists(tempConnection.connection_id); + + expect(exists).toBeTruthy(); + + // Delete the connection + await connectionsPage.deleteConnection(tempConnection.connection_id); + exists = await connectionsPage.connectionExists(tempConnection.connection_id); + expect(exists).toBeFalsy(); + }); +}); + +test.describe("Connections Page - Pagination", () => { + let connectionsPage: ConnectionsPage; + const { baseUrl } = testConfig.connection; + const timestamp = Date.now(); + + // Create multiple test connections to ensure we have enough for pagination testing + const testConnections = Array.from({ length: 60 }, (_, i) => ({ Review Comment: The pagination UI only appears when there are more than 50 connections (the default page size). With fewer connections, the pagination buttons aren't rendered and the test would skip. Using URL params like ?offset=0&limit=2 would force pagination display, but it wouldn't test the actual user interaction of clicking next/prev buttons and verifying the data changes which is the purpose of this test suite. -- 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]
