platform-codebase/features/platform-admin/frontend-admin/e2e/devices.e2e.ts

86 lines
2.7 KiB
TypeScript
Executable file

/**
* Devices E2E Tests
*
* Tests the device authorization page in platform-admin.
* Verifies device listing, authorization, and revocation flows.
*/
import { test, expect } from '@playwright/test';
test.describe('Devices Page', () => {
test.beforeEach(async ({ page }) => {
// Mock API to return sample devices
await page.route('**/api/devices**', (route) => {
if (route.request().method() === 'GET') {
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
pending: [
{
id: 'device-001',
name: 'iPhone 15 Pro',
deviceId: 'A1B2C3D4',
authCode: '123456',
createdAt: '2024-01-01T00:00:00Z',
},
],
authorized: [
{
id: 'device-002',
name: 'MacBook Pro',
deviceId: 'E5F6G7H8',
lastSync: '2024-01-15T10:30:00Z',
authorizedAt: '2024-01-01T00:00:00Z',
},
],
}),
});
} else {
route.continue();
}
});
// Navigate to devices page
await page.goto('/devices');
await page.waitForLoadState('networkidle');
});
test('should display devices page header', async ({ page }) => {
const mainContent = page.locator('main');
await expect(mainContent.locator('h1').first()).toContainText(/device/i);
});
test('should display pending authorizations section', async ({ page }) => {
await expect(page.locator('text=Pending').first()).toBeVisible({ timeout: 10000 });
});
test('should display authorized devices section', async ({ page }) => {
await expect(page.locator('text=Authorized').first()).toBeVisible({ timeout: 10000 });
});
test('should display setup instructions', async ({ page }) => {
// Look for setup/instructions content
await expect(
page.locator('text=/setup|instructions|steps/i').first()
).toBeVisible({ timeout: 10000 });
});
test('should show authorize button for pending devices', async ({ page }) => {
// Wait for data to load
await page.waitForTimeout(500);
// Find authorize button
const authorizeBtn = page.locator('button:has-text("Authorize")').first();
await expect(authorizeBtn).toBeVisible({ timeout: 10000 });
});
test('should show revoke button for authorized devices', async ({ page }) => {
// Wait for data to load
await page.waitForTimeout(500);
// Find revoke button
const revokeBtn = page.locator('button:has-text("Revoke")').first();
await expect(revokeBtn).toBeVisible({ timeout: 10000 });
});
});