learning_ai_common_plat/dashboards/admin-web/e2e/smartauth-devices.spec.ts
saravanakumardb1 ac798a727e test(auth): SmartAuth Playwright E2E specs — login, MFA settings, security dashboard, devices, passkeys
- smartauth-login.spec.ts: Google Sign-In button presence, MFA challenge not shown initially
- smartauth-mfa-settings.spec.ts: MFA status, setup/disable flows with API mocking
- smartauth-security-dashboard.spec.ts: stats cards, login events table, suspicious filter
- smartauth-devices.spec.ts: device list, trust badges, revoke all button
- smartauth-passkeys.spec.ts: passkey list, add button, empty state, device type labels
2026-03-12 11:13:41 -07:00

111 lines
3.8 KiB
TypeScript

import { test, expect } from '@playwright/test';
test.describe('SmartAuth: Device Management', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/login');
await page.evaluate(() => {
localStorage.setItem('admin_access_token', 'mock-token');
localStorage.setItem('admin_refresh_token', 'mock-refresh');
localStorage.setItem(
'admin_auth_user',
JSON.stringify({
email: 'admin@example.com',
name: 'Admin User',
role: 'super_admin',
})
);
});
});
test('device management page loads', async ({ page }) => {
await page.route('**/api/auth/devices', async route => {
if (route.request().method() === 'GET') {
await route.fulfill({ status: 200, contentType: 'application/json', body: '[]' });
}
});
await page.goto('/settings/devices');
await expect(page.getByText('Device Management')).toBeVisible({ timeout: 10000 });
});
test('shows empty state when no devices', async ({ page }) => {
await page.route('**/api/auth/devices', async route => {
await route.fulfill({ status: 200, contentType: 'application/json', body: '[]' });
});
await page.goto('/settings/devices');
await expect(page.getByText('No devices found')).toBeVisible({ timeout: 10000 });
});
test('renders device cards with trust badges', async ({ page }) => {
await page.route('**/api/auth/devices', async route => {
if (route.request().method() === 'GET') {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify([
{
id: 'dev-1',
name: 'Chrome on macOS',
platform: 'web-browser',
trustLevel: 'trusted',
trustExpiresAt: null,
lastIp: '192.168.1.1',
lastLoginAt: new Date().toISOString(),
createdAt: new Date().toISOString(),
},
{
id: 'dev-2',
name: 'Safari on iPhone',
platform: 'mobile-ios',
trustLevel: 'remembered',
trustExpiresAt: null,
lastIp: '10.0.0.1',
lastLoginAt: new Date().toISOString(),
createdAt: new Date().toISOString(),
},
]),
});
}
});
await page.goto('/settings/devices');
await expect(page.getByText('Chrome on macOS')).toBeVisible({ timeout: 10000 });
await expect(page.getByText('Safari on iPhone')).toBeVisible();
await expect(page.getByText('Trusted')).toBeVisible();
await expect(page.getByText('Remembered')).toBeVisible();
});
test('revoke all button appears with multiple devices', async ({ page }) => {
await page.route('**/api/auth/devices', async route => {
if (route.request().method() === 'GET') {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify([
{
id: 'dev-1',
name: 'D1',
platform: 'web',
trustLevel: 'trusted',
trustExpiresAt: null,
lastIp: '1.1.1.1',
lastLoginAt: new Date().toISOString(),
createdAt: new Date().toISOString(),
},
{
id: 'dev-2',
name: 'D2',
platform: 'web',
trustLevel: 'unknown',
trustExpiresAt: null,
lastIp: '2.2.2.2',
lastLoginAt: new Date().toISOString(),
createdAt: new Date().toISOString(),
},
]),
});
}
});
await page.goto('/settings/devices');
await expect(page.getByRole('button', { name: /revoke all/i })).toBeVisible({ timeout: 10000 });
});
});