|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +import { streamRoutesPom } from '@e2e/pom/stream_routes'; |
| 18 | +import { randomId } from '@e2e/utils/common'; |
| 19 | +import { test } from '@e2e/utils/test'; |
| 20 | +import { uiHasToastMsg } from '@e2e/utils/ui'; |
| 21 | +import { |
| 22 | + uiCheckStreamRouteRequiredFields, |
| 23 | + uiFillStreamRouteRequiredFields, |
| 24 | +} from '@e2e/utils/ui/stream_routes'; |
| 25 | +import { expect } from '@playwright/test'; |
| 26 | + |
| 27 | +test.describe.configure({ mode: 'serial' }); |
| 28 | + |
| 29 | +test('CRUD stream route with all fields', async ({ page }) => { |
| 30 | + // Navigate to stream routes page |
| 31 | + await streamRoutesPom.toIndex(page); |
| 32 | + await expect(page.getByRole('heading', { name: 'Stream Routes' })).toBeVisible(); |
| 33 | + |
| 34 | + // Navigate to add page |
| 35 | + await streamRoutesPom.toAdd(page); |
| 36 | + await expect(page.getByRole('heading', { name: 'Add Stream Route' })).toBeVisible({ timeout: 30000 }); |
| 37 | + |
| 38 | + // Use unique server addresses to avoid collisions when running tests in parallel |
| 39 | + const uniqueId = randomId('test'); |
| 40 | + const uniqueIpSuffix = parseInt(uniqueId.slice(-6), 36) % 240 + 10; // 10-249 |
| 41 | + const streamRouteData = { |
| 42 | + server_addr: `127.0.0.${uniqueIpSuffix}`, |
| 43 | + server_port: 9100 + parseInt(uniqueId.slice(-4), 36) % 1000, // Unique port |
| 44 | + remote_addr: '192.168.10.0/24', |
| 45 | + sni: `edge-${uniqueId}.example.com`, |
| 46 | + desc: `Stream route with optional fields - ${uniqueId}`, |
| 47 | + labels: { |
| 48 | + env: 'production', |
| 49 | + version: '2.0', |
| 50 | + region: 'us-west', |
| 51 | + }, |
| 52 | + } as const; |
| 53 | + |
| 54 | + await uiFillStreamRouteRequiredFields(page, streamRouteData); |
| 55 | + |
| 56 | + // Fill upstream nodes manually |
| 57 | + const upstreamSection = page.getByRole('group', { name: 'Upstream', exact: true }); |
| 58 | + const nodesSection = upstreamSection.getByRole('group', { name: 'Nodes' }); |
| 59 | + const addBtn = nodesSection.getByRole('button', { name: 'Add a Node' }); |
| 60 | + |
| 61 | + // Add a node |
| 62 | + await addBtn.click(); |
| 63 | + const dataRows = nodesSection.locator('tr.ant-table-row'); |
| 64 | + const firstRow = dataRows.first(); |
| 65 | + |
| 66 | + const hostInput = firstRow.locator('input').nth(0); |
| 67 | + await hostInput.click(); |
| 68 | + await hostInput.fill('127.0.0.11'); |
| 69 | + |
| 70 | + const portInput = firstRow.locator('input').nth(1); |
| 71 | + await portInput.click(); |
| 72 | + await portInput.fill('8081'); |
| 73 | + |
| 74 | + const weightInput = firstRow.locator('input').nth(2); |
| 75 | + await weightInput.click(); |
| 76 | + await weightInput.fill('100'); |
| 77 | + |
| 78 | + // Submit and land on detail page |
| 79 | + await page.getByRole('button', { name: 'Add', exact: true }).click(); |
| 80 | + |
| 81 | + // Wait for success toast before checking detail page |
| 82 | + await uiHasToastMsg(page, { |
| 83 | + hasText: 'Add Stream Route Successfully', |
| 84 | + }); |
| 85 | + |
| 86 | + await streamRoutesPom.isDetailPage(page); |
| 87 | + |
| 88 | + // Verify initial values in detail view |
| 89 | + await uiCheckStreamRouteRequiredFields(page, streamRouteData); |
| 90 | + |
| 91 | + // Enter edit mode from detail page |
| 92 | + await page.getByRole('button', { name: 'Edit' }).click(); |
| 93 | + await expect(page.getByRole('heading', { name: 'Edit Stream Route' })).toBeVisible(); |
| 94 | + await uiCheckStreamRouteRequiredFields(page, streamRouteData); |
| 95 | + |
| 96 | + // Edit fields - update description, add a label, and modify server settings |
| 97 | + const updatedIpSuffix = (uniqueIpSuffix + 100) % 240 + 10; |
| 98 | + const updatedData = { |
| 99 | + server_addr: `127.0.0.${updatedIpSuffix}`, |
| 100 | + server_port: 9200 + parseInt(uniqueId.slice(-4), 36) % 1000, // Unique port |
| 101 | + remote_addr: '10.10.0.0/16', |
| 102 | + sni: `edge-updated-${uniqueId}.example.com`, |
| 103 | + desc: `Updated stream route with optional fields - ${uniqueId}`, |
| 104 | + labels: { |
| 105 | + ...streamRouteData.labels, |
| 106 | + updated: 'true', |
| 107 | + }, |
| 108 | + } as const; |
| 109 | + |
| 110 | + await page |
| 111 | + .getByLabel('Server Address', { exact: true }) |
| 112 | + .fill(updatedData.server_addr); |
| 113 | + await page |
| 114 | + .getByLabel('Server Port', { exact: true }) |
| 115 | + .fill(updatedData.server_port.toString()); |
| 116 | + await page.getByLabel('Remote Address').fill(updatedData.remote_addr); |
| 117 | + await page.getByLabel('SNI').fill(updatedData.sni); |
| 118 | + await page.getByLabel('Description').first().fill(updatedData.desc); |
| 119 | + |
| 120 | + const labelsField = page.getByPlaceholder('Input text like `key:value`,').first(); |
| 121 | + await labelsField.fill('updated:true'); |
| 122 | + await labelsField.press('Enter'); |
| 123 | + |
| 124 | + // Submit edit and return to detail page |
| 125 | + await page.getByRole('button', { name: 'Save', exact: true }).click(); |
| 126 | + await streamRoutesPom.isDetailPage(page); |
| 127 | + |
| 128 | + // Verify updated values from detail view |
| 129 | + await uiCheckStreamRouteRequiredFields(page, updatedData); |
| 130 | + |
| 131 | + // Navigate back to index and locate the updated row |
| 132 | + await streamRoutesPom.toIndex(page); |
| 133 | + const updatedRow = page |
| 134 | + .getByRole('row') |
| 135 | + .filter({ hasText: updatedData.server_addr }); |
| 136 | + await expect(updatedRow).toBeVisible({ timeout: 10000 }); // Longer timeout for parallel tests |
| 137 | + |
| 138 | + // View detail page from the list to double-check values |
| 139 | + await updatedRow.getByRole('button', { name: 'View' }).click(); |
| 140 | + await streamRoutesPom.isDetailPage(page); |
| 141 | + await uiCheckStreamRouteRequiredFields(page, updatedData); |
| 142 | + |
| 143 | + // Delete from detail page |
| 144 | + await page.getByRole('button', { name: 'Delete' }).click(); |
| 145 | + await page.getByRole('dialog').getByRole('button', { name: 'Delete' }).click(); |
| 146 | + await page.waitForURL((url) => url.pathname.endsWith('/stream_routes')); |
| 147 | + |
| 148 | + await streamRoutesPom.isIndexPage(page); |
| 149 | + await expect( |
| 150 | + page.getByRole('row').filter({ hasText: updatedData.server_addr }) |
| 151 | + ).toHaveCount(0); |
| 152 | +}); |
0 commit comments