|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { DashboardPage, SpacesPage, ClientsPage } from '../pages'; |
| 3 | + |
| 4 | +// Helper to click Spaces in sidebar (avoids space switcher button) |
| 5 | +async function goToSpaces(page: import('@playwright/test').Page) { |
| 6 | + await page.locator('nav button:has-text("Spaces")').last().click(); |
| 7 | +} |
| 8 | + |
| 9 | +test.describe('ConfirmDialog – Spaces', () => { |
| 10 | + test('should show confirm dialog when clicking delete on a non-default space', async ({ page }) => { |
| 11 | + const dashboard = new DashboardPage(page); |
| 12 | + await dashboard.navigate(); |
| 13 | + await goToSpaces(page); |
| 14 | + await expect(page.locator('h1:has-text("Workspaces")')).toBeVisible(); |
| 15 | + |
| 16 | + // Look for a delete button |
| 17 | + const deleteBtn = page.locator('[data-testid^="delete-space-"]').first(); |
| 18 | + if (await deleteBtn.isVisible().catch(() => false)) { |
| 19 | + await deleteBtn.click(); |
| 20 | + |
| 21 | + // Confirm dialog should appear |
| 22 | + await expect(page.getByTestId('confirm-dialog')).toBeVisible(); |
| 23 | + await expect(page.getByTestId('confirm-dialog-confirm')).toBeVisible(); |
| 24 | + await expect(page.getByTestId('confirm-dialog-cancel')).toBeVisible(); |
| 25 | + |
| 26 | + // Title should mention delete |
| 27 | + await expect(page.getByTestId('confirm-dialog').locator('h3')).toContainText(/[Dd]elete/); |
| 28 | + } |
| 29 | + }); |
| 30 | + |
| 31 | + test('should dismiss confirm dialog on cancel without deleting', async ({ page }) => { |
| 32 | + const dashboard = new DashboardPage(page); |
| 33 | + await dashboard.navigate(); |
| 34 | + await goToSpaces(page); |
| 35 | + await expect(page.locator('h1:has-text("Workspaces")')).toBeVisible(); |
| 36 | + |
| 37 | + const deleteBtn = page.locator('[data-testid^="delete-space-"]').first(); |
| 38 | + if (await deleteBtn.isVisible().catch(() => false)) { |
| 39 | + // Count spaces before |
| 40 | + const spaceBefore = await page.locator('[data-testid^="space-card-"]').count(); |
| 41 | + |
| 42 | + await deleteBtn.click(); |
| 43 | + await expect(page.getByTestId('confirm-dialog')).toBeVisible(); |
| 44 | + |
| 45 | + // Click cancel |
| 46 | + await page.getByTestId('confirm-dialog-cancel').click(); |
| 47 | + |
| 48 | + // Dialog should close |
| 49 | + await expect(page.getByTestId('confirm-dialog')).not.toBeVisible(); |
| 50 | + |
| 51 | + // Space count should be the same (nothing was deleted) |
| 52 | + const spaceAfter = await page.locator('[data-testid^="space-card-"]').count(); |
| 53 | + expect(spaceAfter).toBe(spaceBefore); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + test('should dismiss confirm dialog when clicking overlay', async ({ page }) => { |
| 58 | + const dashboard = new DashboardPage(page); |
| 59 | + await dashboard.navigate(); |
| 60 | + await goToSpaces(page); |
| 61 | + await expect(page.locator('h1:has-text("Workspaces")')).toBeVisible(); |
| 62 | + |
| 63 | + const deleteBtn = page.locator('[data-testid^="delete-space-"]').first(); |
| 64 | + if (await deleteBtn.isVisible().catch(() => false)) { |
| 65 | + await deleteBtn.click(); |
| 66 | + await expect(page.getByTestId('confirm-dialog')).toBeVisible(); |
| 67 | + |
| 68 | + // Click overlay (outside the dialog) |
| 69 | + await page.getByTestId('confirm-dialog-overlay').click({ position: { x: 5, y: 5 } }); |
| 70 | + |
| 71 | + // Dialog should close |
| 72 | + await expect(page.getByTestId('confirm-dialog')).not.toBeVisible(); |
| 73 | + } |
| 74 | + }); |
| 75 | +}); |
| 76 | + |
| 77 | +test.describe('ConfirmDialog – Clients', () => { |
| 78 | + test('should show confirm dialog when clicking Remove Client', async ({ page }) => { |
| 79 | + const dashboard = new DashboardPage(page); |
| 80 | + await dashboard.navigate(); |
| 81 | + await page.locator('nav button:has-text("Clients")').click(); |
| 82 | + await expect(page.getByRole('heading', { name: 'Connected Clients' })).toBeVisible(); |
| 83 | + |
| 84 | + // Click the first client card to open the detail panel |
| 85 | + const clientCards = page.locator('[data-testid^="client-card-"]'); |
| 86 | + const count = await clientCards.count(); |
| 87 | + |
| 88 | + if (count > 0) { |
| 89 | + await clientCards.first().click(); |
| 90 | + |
| 91 | + // Wait for panel to open |
| 92 | + await page.waitForTimeout(300); |
| 93 | + |
| 94 | + // Find the Remove Client button in the panel |
| 95 | + const removeBtn = page.getByRole('button', { name: /Remove Client/i }); |
| 96 | + if (await removeBtn.isVisible().catch(() => false)) { |
| 97 | + await removeBtn.click(); |
| 98 | + |
| 99 | + // Confirm dialog should appear |
| 100 | + await expect(page.getByTestId('confirm-dialog')).toBeVisible(); |
| 101 | + await expect(page.getByTestId('confirm-dialog-confirm')).toHaveText(/Remove/i); |
| 102 | + |
| 103 | + // Cancel should dismiss without removing |
| 104 | + await page.getByTestId('confirm-dialog-cancel').click(); |
| 105 | + await expect(page.getByTestId('confirm-dialog')).not.toBeVisible(); |
| 106 | + |
| 107 | + // Client should still be there |
| 108 | + const countAfter = await clientCards.count(); |
| 109 | + expect(countAfter).toBe(count); |
| 110 | + } |
| 111 | + } |
| 112 | + }); |
| 113 | +}); |
0 commit comments