DSingh0304 commented on code in PR #3255: URL: https://github.com/apache/apisix-dashboard/pull/3255#discussion_r2548611708
########## e2e/utils/ui/stream_routes.ts: ########## @@ -0,0 +1,299 @@ +/** + * 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 type { Locator, Page } from '@playwright/test'; +import { expect } from '@playwright/test'; + +import type { APISIXType } from '@/types/schema/apisix'; + +export const uiFillStreamRouteRequiredFields = async ( + page: Page, + data: { + server_addr?: string; + server_port?: number; + remote_addr?: string; + sni?: string; + desc?: string; + labels?: Record<string, string>; + } +) => { + if (data.server_addr) { + await page + .getByLabel('Server Address', { exact: true }) + .fill(data.server_addr); + } + + if (data.server_port) { + await page + .getByLabel('Server Port', { exact: true }) + .fill(data.server_port.toString()); + } + + if (data.remote_addr) { + await page.getByLabel('Remote Address').fill(data.remote_addr); + } + + if (data.sni) { + await page.getByLabel('SNI').fill(data.sni); + } + + if (data.desc) { + await page.getByLabel('Description').first().fill(data.desc); + } + + if (data.labels) { + const labelsField = page.getByPlaceholder('Input text like `key:value`,').first(); + for (const [key, value] of Object.entries(data.labels)) { + await labelsField.fill(`${key}:${value}`); + await labelsField.press('Enter'); + } + } +}; + +export const uiCheckStreamRouteRequiredFields = async ( + page: Page, + data: { + server_addr?: string; + server_port?: number; + remote_addr?: string; + sni?: string; + desc?: string; + labels?: Record<string, string>; + } +) => { + if (data.server_addr) { + await expect(page.getByLabel('Server Address', { exact: true })).toHaveValue( + data.server_addr + ); + } + + if (data.server_port) { + await expect(page.getByLabel('Server Port', { exact: true })).toHaveValue( + data.server_port.toString() + ); + } + + if (data.remote_addr) { + await expect(page.getByLabel('Remote Address')).toHaveValue( + data.remote_addr + ); + } + + if (data.sni) { + await expect(page.getByLabel('SNI')).toHaveValue(data.sni); + } + + if (data.desc) { + await expect(page.getByLabel('Description').first()).toHaveValue(data.desc); + } + + if (data.labels) { + // Labels are displayed as tags, check if the tags exist + for (const [key, value] of Object.entries(data.labels)) { + const labelTag = page.getByText(`${key}:${value}`, { exact: true }); + await expect(labelTag).toBeVisible(); + } + } +}; + +export const uiFillStreamRouteAllFields = async ( + page: Page, + upstreamSection: Locator, + data: { + server_addr?: string; + server_port?: number; + remote_addr?: string; + sni?: string; + desc?: string; + labels?: Record<string, string>; + upstream?: { + nodes?: APISIXType['UpstreamNode'][]; + retries?: number; + timeout?: { + connect?: number; + send?: number; + read?: number; + }; + }; + protocol?: { + name?: string; + superior_id?: string; + }; + } +) => { + // Fill basic fields + await uiFillStreamRouteRequiredFields(page, { + server_addr: data.server_addr, + server_port: data.server_port, + remote_addr: data.remote_addr, + sni: data.sni, + desc: data.desc, + labels: data.labels, + }); + + // Fill upstream nodes + if (data.upstream?.nodes && data.upstream.nodes.length > 0) { + for (let i = 0; i < data.upstream.nodes.length; i++) { + const node = data.upstream.nodes[i]; + const nodeRow = upstreamSection + .locator('section') + .filter({ hasText: 'Nodes' }) + .getByRole('row') + .nth(i + 1); + + await nodeRow.getByPlaceholder('Host').fill(node.host); + await nodeRow.getByPlaceholder('Port').fill(node.port.toString()); + await nodeRow.getByPlaceholder('Weight').fill(node.weight.toString()); + + // Click add if there are more nodes to add + if (i < data.upstream.nodes.length - 1) { + await upstreamSection + .locator('section') + .filter({ hasText: 'Nodes' }) + .getByRole('button', { name: 'Add' }) + .click(); + } + } + } + + // Fill upstream retries + if (data.upstream?.retries !== undefined) { + await upstreamSection.getByLabel('Retries').fill(data.upstream.retries.toString()); + } + + // Fill upstream timeout + if (data.upstream?.timeout) { + if (data.upstream.timeout.connect !== undefined) { + await upstreamSection + .getByLabel('Connect', { exact: true }) + .fill(data.upstream.timeout.connect.toString()); + } + if (data.upstream.timeout.send !== undefined) { + await upstreamSection + .getByLabel('Send', { exact: true }) + .fill(data.upstream.timeout.send.toString()); + } + if (data.upstream.timeout.read !== undefined) { + await upstreamSection + .getByLabel('Read', { exact: true }) + .fill(data.upstream.timeout.read.toString()); + } + } + + // Fill protocol fields + if (data.protocol?.name) { + await page.getByLabel('Protocol Name').fill(data.protocol.name); + } + + if (data.protocol?.superior_id) { + await page.getByLabel('Superior ID').fill(data.protocol.superior_id); + } +}; + +export const uiCheckStreamRouteAllFields = async ( + page: Page, + upstreamSection: Locator, + data: { + server_addr?: string; + server_port?: number; + remote_addr?: string; + sni?: string; + desc?: string; + labels?: Record<string, string>; + upstream?: { + nodes?: APISIXType['UpstreamNode'][]; + retries?: number; + timeout?: { + connect?: number; + send?: number; + read?: number; + }; + }; + protocol?: { + name?: string; + superior_id?: string; + }; + } Review Comment: fixed... -- 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]
