|
| 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 { consumerGroupsPom } from '@e2e/pom/consumer_groups'; |
| 18 | +import { e2eReq } from '@e2e/utils/req'; |
| 19 | +import { test } from '@e2e/utils/test'; |
| 20 | +import { |
| 21 | + uiFillMonacoEditor, |
| 22 | + uiGetMonacoEditor, |
| 23 | + uiHasToastMsg, |
| 24 | +} from '@e2e/utils/ui'; |
| 25 | +import { expect } from '@playwright/test'; |
| 26 | + |
| 27 | +import { deleteAllConsumerGroups } from '@/apis/consumer_groups'; |
| 28 | + |
| 29 | +test.beforeAll(async () => { |
| 30 | + await deleteAllConsumerGroups(e2eReq); |
| 31 | +}); |
| 32 | + |
| 33 | +test('should CRUD Consumer Group with all fields', async ({ page }) => { |
| 34 | + test.slow(); |
| 35 | + |
| 36 | + const testId = 'test-consumer-group-all-fields'; |
| 37 | + const testDesc = 'Consumer Group with all fields for testing'; |
| 38 | + |
| 39 | + await consumerGroupsPom.toIndex(page); |
| 40 | + await consumerGroupsPom.isIndexPage(page); |
| 41 | + |
| 42 | + await test.step('create consumer group with all fields', async () => { |
| 43 | + // Navigate to add page |
| 44 | + await consumerGroupsPom.getAddConsumerGroupBtn(page).click(); |
| 45 | + await consumerGroupsPom.isAddPage(page); |
| 46 | + |
| 47 | + // Fill in the ID |
| 48 | + const idField = page.getByRole('textbox', { name: 'ID', exact: true }); |
| 49 | + await idField.clear(); |
| 50 | + await idField.fill(testId); |
| 51 | + |
| 52 | + // Fill in the description |
| 53 | + const descField = page.getByRole('textbox', { name: 'Description' }); |
| 54 | + await descField.fill(testDesc); |
| 55 | + |
| 56 | + // Add plugins |
| 57 | + const selectPluginsBtn = page.getByRole('button', { |
| 58 | + name: 'Select Plugins', |
| 59 | + }); |
| 60 | + await selectPluginsBtn.click(); |
| 61 | + |
| 62 | + // Add basic-auth plugin (simpler than limit-count which requires redis) |
| 63 | + const selectPluginsDialog = page.getByRole('dialog', { |
| 64 | + name: 'Select Plugins', |
| 65 | + }); |
| 66 | + const searchInput = selectPluginsDialog.getByPlaceholder('Search'); |
| 67 | + await searchInput.fill('basic-auth'); |
| 68 | + |
| 69 | + await selectPluginsDialog |
| 70 | + .getByTestId('plugin-basic-auth') |
| 71 | + .getByRole('button', { name: 'Add' }) |
| 72 | + .click(); |
| 73 | + |
| 74 | + const addPluginDialog = page.getByRole('dialog', { name: 'Add Plugin' }); |
| 75 | + const pluginEditor = await uiGetMonacoEditor(page, addPluginDialog); |
| 76 | + await uiFillMonacoEditor( |
| 77 | + page, |
| 78 | + pluginEditor, |
| 79 | + '{"hide_credentials": true}' |
| 80 | + ); |
| 81 | + // add plugin |
| 82 | + await addPluginDialog.getByRole('button', { name: 'Add' }).click(); |
| 83 | + await expect(addPluginDialog).toBeHidden(); |
| 84 | + |
| 85 | + // Submit the form |
| 86 | + await consumerGroupsPom.getAddBtn(page).click(); |
| 87 | + await uiHasToastMsg(page, { |
| 88 | + hasText: 'Add Consumer Group Successfully', |
| 89 | + }); |
| 90 | + |
| 91 | + // Should navigate to detail page |
| 92 | + await consumerGroupsPom.isDetailPage(page); |
| 93 | + }); |
| 94 | + |
| 95 | + await test.step('verify all fields in detail page', async () => { |
| 96 | + // Verify ID |
| 97 | + const idField = page.getByRole('textbox', { name: 'ID', exact: true }); |
| 98 | + await expect(idField).toHaveValue(testId); |
| 99 | + await expect(idField).toBeDisabled(); |
| 100 | + |
| 101 | + // Verify description |
| 102 | + const descField = page.getByRole('textbox', { name: 'Description' }); |
| 103 | + await expect(descField).toHaveValue(testDesc); |
| 104 | + await expect(descField).toBeDisabled(); |
| 105 | + |
| 106 | + // Verify plugin is added |
| 107 | + await expect(page.getByText('basic-auth')).toBeVisible(); |
| 108 | + }); |
| 109 | + |
| 110 | + await test.step('edit and update consumer group', async () => { |
| 111 | + // Click Edit button |
| 112 | + await page.getByRole('button', { name: 'Edit' }).click(); |
| 113 | + |
| 114 | + // Verify we're in edit mode |
| 115 | + const descField = page.getByRole('textbox', { name: 'Description' }); |
| 116 | + await expect(descField).toBeEnabled(); |
| 117 | + |
| 118 | + // Update description |
| 119 | + await descField.clear(); |
| 120 | + await descField.fill('Updated description with all fields'); |
| 121 | + |
| 122 | + // Save changes |
| 123 | + await page.getByRole('button', { name: 'Save', exact: true }).click(); |
| 124 | + await uiHasToastMsg(page, { |
| 125 | + hasText: 'success', |
| 126 | + }); |
| 127 | + |
| 128 | + // Verify we're back in detail view |
| 129 | + await consumerGroupsPom.isDetailPage(page); |
| 130 | + |
| 131 | + // Verify updated description |
| 132 | + await expect(descField).toHaveValue('Updated description with all fields'); |
| 133 | + await expect(descField).toBeDisabled(); |
| 134 | + }); |
| 135 | + |
| 136 | + await test.step('verify consumer group exists in list', async () => { |
| 137 | + // Navigate to list page |
| 138 | + await consumerGroupsPom.getConsumerGroupNavBtn(page).click(); |
| 139 | + await consumerGroupsPom.isIndexPage(page); |
| 140 | + |
| 141 | + // Verify consumer group exists |
| 142 | + await expect(page.getByRole('cell', { name: testId, exact: true })).toBeVisible(); |
| 143 | + await expect( |
| 144 | + page.getByRole('cell', { name: 'Updated description with all fields' }) |
| 145 | + ).toBeVisible(); |
| 146 | + }); |
| 147 | + |
| 148 | + await test.step('delete consumer group', async () => { |
| 149 | + // Click View to go to detail page |
| 150 | + await page |
| 151 | + .getByRole('row', { name: new RegExp(testId) }) |
| 152 | + .getByRole('button', { name: 'View' }) |
| 153 | + .click(); |
| 154 | + await consumerGroupsPom.isDetailPage(page); |
| 155 | + |
| 156 | + // Delete consumer group |
| 157 | + await page.getByRole('button', { name: 'Delete' }).click(); |
| 158 | + |
| 159 | + await page |
| 160 | + .getByRole('dialog', { name: 'Delete Consumer Group' }) |
| 161 | + .getByRole('button', { name: 'Delete' }) |
| 162 | + .click(); |
| 163 | + |
| 164 | + // Should redirect to list page |
| 165 | + await consumerGroupsPom.isIndexPage(page); |
| 166 | + await uiHasToastMsg(page, { |
| 167 | + hasText: 'Delete Consumer Group Successfully', |
| 168 | + }); |
| 169 | + |
| 170 | + // Verify deletion |
| 171 | + await expect(page.getByRole('cell', { name: testId, exact: true })).toBeHidden(); |
| 172 | + }); |
| 173 | +}); |
0 commit comments