|
| 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 { consumersPom } from '@e2e/pom/consumers'; |
| 18 | +import { e2eReq } from '@e2e/utils/req'; |
| 19 | +import { test } from '@e2e/utils/test'; |
| 20 | +import { uiHasToastMsg } from '@e2e/utils/ui'; |
| 21 | +import { expect } from '@playwright/test'; |
| 22 | +import { customAlphabet } from 'nanoid'; |
| 23 | + |
| 24 | +import { deleteAllConsumers } from '@/apis/consumers'; |
| 25 | + |
| 26 | +// Consumer usernames can only contain: a-zA-Z0-9_- |
| 27 | +const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 10); |
| 28 | +const consumerUsername = `testconsumer${nanoid()}`; |
| 29 | +const description = 'Test consumer with all fields filled'; |
| 30 | + |
| 31 | +test.beforeAll(async () => { |
| 32 | + await deleteAllConsumers(e2eReq); |
| 33 | +}); |
| 34 | + |
| 35 | +test('should CRUD consumer with all fields', async ({ page }) => { |
| 36 | + test.slow(); |
| 37 | + |
| 38 | + await consumersPom.toIndex(page); |
| 39 | + await consumersPom.isIndexPage(page); |
| 40 | + |
| 41 | + await consumersPom.getAddConsumerBtn(page).click(); |
| 42 | + await consumersPom.isAddPage(page); |
| 43 | + |
| 44 | + await test.step('submit with all fields', async () => { |
| 45 | + // Fill username (required) |
| 46 | + await page.getByRole('textbox', { name: 'Username' }).fill(consumerUsername); |
| 47 | + |
| 48 | + // Fill description (optional) |
| 49 | + await page.getByRole('textbox', { name: 'Description' }).fill(description); |
| 50 | + |
| 51 | + // Add labels using tags input |
| 52 | + const labelsInput = page.getByPlaceholder('Input text like `key:value`, then enter or blur'); |
| 53 | + await labelsInput.fill('version:v1'); |
| 54 | + await labelsInput.press('Enter'); |
| 55 | + await labelsInput.fill('env:test'); |
| 56 | + await labelsInput.press('Enter'); |
| 57 | + await labelsInput.fill('team:engineering'); |
| 58 | + await labelsInput.press('Enter'); |
| 59 | + |
| 60 | + // Submit the form |
| 61 | + await consumersPom.getAddBtn(page).click(); |
| 62 | + await uiHasToastMsg(page, { |
| 63 | + hasText: 'Add Consumer Successfully', |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + await test.step('auto navigate to consumer detail page', async () => { |
| 68 | + await consumersPom.isDetailPage(page); |
| 69 | + |
| 70 | + // Verify the consumer username |
| 71 | + await expect(page.getByRole('textbox', { name: 'Username' })) |
| 72 | + .toHaveValue(consumerUsername); |
| 73 | + }); |
| 74 | + |
| 75 | + await test.step('edit and update all fields', async () => { |
| 76 | + // Enter edit mode |
| 77 | + await page.getByRole('button', { name: 'Edit' }).click(); |
| 78 | + |
| 79 | + // Update description |
| 80 | + await page.getByRole('textbox', { name: 'Description' }).fill('Updated: ' + description); |
| 81 | + |
| 82 | + // Update labels - remove old ones and add new ones |
| 83 | + // First, remove existing labels by clicking the X button |
| 84 | + const labelsSection = page.getByRole('group', { name: 'Basic Infomation' }); |
| 85 | + const removeButtons = labelsSection.locator('button[aria-label^="Remove"]'); |
| 86 | + const count = await removeButtons.count(); |
| 87 | + for (let i = 0; i < count; i++) { |
| 88 | + await removeButtons.first().click(); |
| 89 | + } |
| 90 | + |
| 91 | + // Add new labels |
| 92 | + const labelsInput = page.getByPlaceholder('Input text like `key:value`, then enter or blur'); |
| 93 | + await labelsInput.fill('version:v2'); |
| 94 | + await labelsInput.press('Enter'); |
| 95 | + await labelsInput.fill('env:production'); |
| 96 | + await labelsInput.press('Enter'); |
| 97 | + await labelsInput.fill('team:platform'); |
| 98 | + await labelsInput.press('Enter'); |
| 99 | + |
| 100 | + // Save changes |
| 101 | + await page.getByRole('button', { name: 'Save' }).click(); |
| 102 | + await uiHasToastMsg(page, { |
| 103 | + hasText: 'success', |
| 104 | + }); |
| 105 | + |
| 106 | + // Verify updates |
| 107 | + await expect(page.getByRole('textbox', { name: 'Description' })) |
| 108 | + .toHaveValue('Updated: ' + description); |
| 109 | + }); |
| 110 | + |
| 111 | + await test.step('verify consumer in list page', async () => { |
| 112 | + await consumersPom.getConsumerNavBtn(page).click(); |
| 113 | + await consumersPom.isIndexPage(page); |
| 114 | + |
| 115 | + // Find the consumer in the list |
| 116 | + const row = page.getByRole('row', { name: consumerUsername }); |
| 117 | + await expect(row).toBeVisible(); |
| 118 | + }); |
| 119 | + |
| 120 | + await test.step('delete consumer', async () => { |
| 121 | + // Navigate to detail page |
| 122 | + await page |
| 123 | + .getByRole('row', { name: consumerUsername }) |
| 124 | + .getByRole('button', { name: 'View' }) |
| 125 | + .click(); |
| 126 | + await consumersPom.isDetailPage(page); |
| 127 | + |
| 128 | + // Delete |
| 129 | + await page.getByRole('button', { name: 'Delete' }).click(); |
| 130 | + await page |
| 131 | + .getByRole('dialog', { name: 'Delete Consumer' }) |
| 132 | + .getByRole('button', { name: 'Delete' }) |
| 133 | + .click(); |
| 134 | + |
| 135 | + // Verify deletion |
| 136 | + await uiHasToastMsg(page, { |
| 137 | + hasText: 'Delete Consumer Successfully', |
| 138 | + }); |
| 139 | + |
| 140 | + // Navigate to consumers list to verify consumer is gone |
| 141 | + await consumersPom.toIndex(page); |
| 142 | + await consumersPom.isIndexPage(page); |
| 143 | + await expect(page.getByRole('cell', { name: consumerUsername })).toBeHidden(); |
| 144 | + }); |
| 145 | +}); |
0 commit comments