import { expect, test } from '@playwright/test'; test.describe('Admin Users Page', () => { test.beforeEach(async ({ page }) => { // Navigate to admin users page await page.goto('/admin/users'); }); test('should display user management page', async ({ page }) => { await expect(page.locator('h1')).toContainText('User Management'); }); test('should display user list', async ({ page }) => { await expect(page.locator('text=Users')).toBeVisible(); }); test('should display search input', async ({ page }) => { await expect(page.locator('input[placeholder="Search users..."]')).toBeVisible(); }); test('should display role filter', async ({ page }) => { await expect(page.locator('select')).toBeVisible(); }); test('should search users', async ({ page }) => { await page.fill('input[placeholder="Search users..."]', 'test'); // Wait for search to complete await page.waitForTimeout(500); }); test('should filter by role', async ({ page }) => { await page.selectOption('select', 'admin'); // Wait for filter to complete await page.waitForTimeout(500); }); test('should display user details when user is clicked', async ({ page }) => { // Click on first user const firstUser = page.locator('[class*="border"]').first(); await firstUser.click(); // Wait for user details to appear await expect(page.locator('text=User Details')).toBeVisible(); }); test('should update user information', async ({ page }) => { // Click on first user const firstUser = page.locator('[class*="border"]').first(); await firstUser.click(); // Wait for user details to appear await expect(page.locator('text=User Details')).toBeVisible(); // Update user information await page.fill('input#fullName', 'Updated Name'); await page.click('button:has-text("Save Changes")'); // Wait for success message await expect(page.locator('text=User updated successfully')).toBeVisible(); }); test('should deactivate user', async ({ page }) => { // Click on deactivate button for first user const deactivateButton = page.locator('button:has-text("Deactivate")').first(); await deactivateButton.click(); // Wait for success message await expect(page.locator('text=User deactivated successfully')).toBeVisible(); }); test('should paginate users', async ({ page }) => { // Check if pagination controls are visible const nextButton = page.locator('button:has-text("Next")'); const prevButton = page.locator('button:has-text("Previous")'); if (await nextButton.isVisible()) { await nextButton.click(); await page.waitForTimeout(500); } if (await prevButton.isVisible()) { await prevButton.click(); await page.waitForTimeout(500); } }); test('should close user details when cancel is clicked', async ({ page }) => { // Click on first user const firstUser = page.locator('[class*="border"]').first(); await firstUser.click(); // Wait for user details to appear await expect(page.locator('text=User Details')).toBeVisible(); // Click cancel button await page.click('button:has-text("Cancel")'); // Wait for user details to disappear await expect(page.locator('text=User Details')).not.toBeVisible(); }); });