Skip to content

Commit 5aa56c8

Browse files
committed
test(e2e): Add ingress delete E2E test
Signed-off-by: SunsetB612 <[email protected]>
1 parent 5054fb7 commit 5aa56c8

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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, generateTestServiceYaml, createK8sService, getServiceNameFromYaml} from './test-utils';
16+
17+
test.beforeEach(async ({ page }) => {
18+
await setupDashboardAuthentication(page);
19+
});
20+
21+
test('should delete service successfully', async ({ page }) => {
22+
// Create a test service directly via kubectl to set up test data
23+
const testServiceYaml = generateTestServiceYaml();
24+
const serviceName = getServiceNameFromYaml(testServiceYaml);
25+
26+
// Setup: Create service using kubectl
27+
await createK8sService(testServiceYaml);
28+
29+
// Navigate to service page
30+
await page.click('text=Services');
31+
32+
// Click visible Service tab
33+
const serviceTab = page.locator('role=option[name="Service"]');
34+
await serviceTab.waitFor({ state: 'visible', timeout: 30000 });
35+
await serviceTab.click();
36+
37+
// Verify selected state
38+
await expect(serviceTab).toHaveAttribute('aria-selected', 'true');
39+
await expect(page.locator('table')).toBeVisible({ timeout: 30000 });
40+
41+
// Wait for service to appear in list
42+
const table = page.locator('table');
43+
await expect(table.locator(`text=${serviceName}`)).toBeVisible({ timeout: 30000 });
44+
45+
// Find row containing test service name
46+
const targetRow = page.locator(`table tbody tr:has-text("${serviceName}")`);
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/service') &&
56+
response.url().includes(`name/${serviceName}`) &&
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 service no longer exists in table
83+
await expect(table.locator(`text=${serviceName}`)).toHaveCount(0, { timeout: 30000 });
84+
85+
// Debug
86+
if(process.env.DEBUG === 'true'){
87+
await page.screenshot({ path: 'debug-service-delete-kubectl.png', fullPage: true });
88+
}
89+
});

0 commit comments

Comments
 (0)