| 
 | 1 | +/*  | 
 | 2 | +Copyright 2024 The Karmada Authors.  | 
 | 3 | +Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 4 | +you may not use this file except in compliance with the License.  | 
 | 5 | +You may obtain a copy of the License at  | 
 | 6 | +    http://www.apache.org/licenses/LICENSE-2.0  | 
 | 7 | +Unless required by applicable law or agreed to in writing, software  | 
 | 8 | +distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 9 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 10 | +See the License for the specific language governing permissions and  | 
 | 11 | +limitations under the License.  | 
 | 12 | +*/  | 
 | 13 | + | 
 | 14 | +import { test, expect } from '@playwright/test';  | 
 | 15 | +import { setupDashboardAuthentication, generateTestIngressYaml, createK8sIngress, getIngressNameFromYaml} from './test-utils';  | 
 | 16 | + | 
 | 17 | +test.beforeEach(async ({ page }) => {  | 
 | 18 | +    await setupDashboardAuthentication(page);  | 
 | 19 | +});  | 
 | 20 | + | 
 | 21 | +test('should delete ingress successfully', async ({ page }) => {  | 
 | 22 | +    // Create a test ingress directly via kubectl to set up test data  | 
 | 23 | +    const testIngressYaml = generateTestIngressYaml();  | 
 | 24 | +    const ingressName = getIngressNameFromYaml(testIngressYaml);  | 
 | 25 | + | 
 | 26 | +    // Setup: Create ingress using kubectl  | 
 | 27 | +    await createK8sIngress(testIngressYaml);  | 
 | 28 | + | 
 | 29 | +    // Navigate to services page  | 
 | 30 | +    await page.click('text=Services');  | 
 | 31 | + | 
 | 32 | +    // Click visible Ingress tab  | 
 | 33 | +    const ingressTab = page.locator('role=option[name="Ingress"]');  | 
 | 34 | +    await ingressTab.waitFor({ state: 'visible', timeout: 30000 });  | 
 | 35 | +    await ingressTab.click();  | 
 | 36 | + | 
 | 37 | +    // Verify selected state  | 
 | 38 | +    await expect(ingressTab).toHaveAttribute('aria-selected', 'true');  | 
 | 39 | +    await expect(page.locator('table')).toBeVisible({ timeout: 30000 });  | 
 | 40 | + | 
 | 41 | +    // Wait for ingress to appear in list  | 
 | 42 | +    const table = page.locator('table');  | 
 | 43 | +    await expect(table.locator(`text=${ingressName}`)).toBeVisible({ timeout: 30000 });  | 
 | 44 | + | 
 | 45 | +    // Find row containing test ingress name  | 
 | 46 | +    const targetRow = page.locator(`table tbody tr:has-text("${ingressName}")`);  | 
 | 47 | +    await expect(targetRow).toBeVisible({ timeout: 15000 });  | 
 | 48 | + | 
 | 49 | +    // Find Delete button in that row and click  | 
 | 50 | +    const deleteButton = targetRow.locator('button[type="button"]').filter({ hasText: /^(Delete)$/ });  | 
 | 51 | +    await expect(deleteButton).toBeVisible({ timeout: 10000 });  | 
 | 52 | + | 
 | 53 | +    // Listen for delete API call  | 
 | 54 | +    const deleteApiPromise = page.waitForResponse(response => {  | 
 | 55 | +        return response.url().includes('/_raw/ingress') &&  | 
 | 56 | +            response.url().includes(`name/${ingressName}`) &&  | 
 | 57 | +            response.request().method() === 'DELETE' &&  | 
 | 58 | +            response.status() === 200;  | 
 | 59 | +    }, { timeout: 15000 });  | 
 | 60 | + | 
 | 61 | +    await deleteButton.click();  | 
 | 62 | + | 
 | 63 | +    // Wait for delete confirmation tooltip to appear  | 
 | 64 | +    await page.waitForSelector('[role="tooltip"]', { timeout: 10000 });  | 
 | 65 | + | 
 | 66 | +    // Click Confirm button to confirm deletion  | 
 | 67 | +    const confirmButton = page.locator('[role="tooltip"] button').filter({ hasText: /^(Confirm)$/ });  | 
 | 68 | +    await expect(confirmButton).toBeVisible({ timeout: 5000 });  | 
 | 69 | +    await confirmButton.click();  | 
 | 70 | + | 
 | 71 | +    // Wait for delete API call to succeed  | 
 | 72 | +    await deleteApiPromise;  | 
 | 73 | + | 
 | 74 | +    // Wait for tooltip to close  | 
 | 75 | +    await page.waitForSelector('[role="tooltip"]', { state: 'detached', timeout: 10000 }).catch(() => {});  | 
 | 76 | + | 
 | 77 | +    // Refresh page to ensure UI is updated after deletion  | 
 | 78 | +    await page.reload();  | 
 | 79 | +    await page.click('text=Services');  | 
 | 80 | +    await expect(table).toBeVisible({ timeout: 30000 });  | 
 | 81 | + | 
 | 82 | +    // Verify ingress no longer exists in table  | 
 | 83 | +    await expect(table.locator(`text=${ingressName}`)).toHaveCount(0, { timeout: 30000 });  | 
 | 84 | + | 
 | 85 | +    // Debug  | 
 | 86 | +    if(process.env.DEBUG === 'true'){  | 
 | 87 | +        await page.screenshot({ path: 'debug-ingress-delete-kubectl.png', fullPage: true });  | 
 | 88 | +    }  | 
 | 89 | +});  | 
0 commit comments