110 lines
3.2 KiB
TypeScript
110 lines
3.2 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
const baseStatus = {
|
|
version: '1.0.0',
|
|
syncStatus: 'idle',
|
|
lastSync: null,
|
|
syncErrorMessage: null,
|
|
isSyncing: false,
|
|
activityLog: [],
|
|
};
|
|
|
|
function mockRoutes(page: any, statusOverrides: Record<string, unknown>) {
|
|
const status = { ...baseStatus, ...statusOverrides };
|
|
return Promise.all([
|
|
page.route('/api/status', (route: any) =>
|
|
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(status) }),
|
|
),
|
|
page.route('/api/conversations', (route: any) =>
|
|
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ conversations: [] }) }),
|
|
),
|
|
page.route('/api/settings', (route: any) =>
|
|
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ apiBaseURL: 'http://localhost:3100' }) }),
|
|
),
|
|
]);
|
|
}
|
|
|
|
test('shows registration when unauthenticated', async ({ page }) => {
|
|
await mockRoutes(page, {
|
|
isAuthenticated: false,
|
|
needsFullDiskAccess: false,
|
|
messageCount: 0,
|
|
conversationCount: 0,
|
|
contactCount: 0,
|
|
});
|
|
await page.route('/api/register', (route) =>
|
|
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 'XYZ789' }) }),
|
|
);
|
|
|
|
await page.goto('/');
|
|
await page.getByText('Admin').click();
|
|
await expect(page.getByText('Device Registration')).toBeVisible();
|
|
});
|
|
|
|
test('shows FDA card when needs disk access', async ({ page }) => {
|
|
await mockRoutes(page, {
|
|
isAuthenticated: true,
|
|
needsFullDiskAccess: true,
|
|
messageCount: 0,
|
|
conversationCount: 0,
|
|
contactCount: 0,
|
|
});
|
|
|
|
await page.goto('/');
|
|
await page.getByText('Admin').click();
|
|
await expect(page.getByText('Full Disk Access Required')).toBeVisible();
|
|
});
|
|
|
|
test('shows stats when authenticated', async ({ page }) => {
|
|
await mockRoutes(page, {
|
|
isAuthenticated: true,
|
|
needsFullDiskAccess: false,
|
|
messageCount: 1234,
|
|
conversationCount: 56,
|
|
contactCount: 78,
|
|
});
|
|
|
|
await page.goto('/');
|
|
await page.getByText('Admin').click();
|
|
await expect(page.getByText('1,234')).toBeVisible();
|
|
await expect(page.getByText('56')).toBeVisible();
|
|
await expect(page.getByText('78')).toBeVisible();
|
|
});
|
|
|
|
test('sync now sends POST', async ({ page }) => {
|
|
await mockRoutes(page, {
|
|
isAuthenticated: true,
|
|
needsFullDiskAccess: false,
|
|
messageCount: 100,
|
|
conversationCount: 10,
|
|
contactCount: 5,
|
|
});
|
|
|
|
let syncCalled = false;
|
|
await page.route('/api/sync', (route) => {
|
|
if (route.request().method() === 'POST') {
|
|
syncCalled = true;
|
|
}
|
|
return route.fulfill({ status: 200, contentType: 'application/json', body: '{}' });
|
|
});
|
|
|
|
await page.goto('/');
|
|
await page.getByText('Admin').click();
|
|
await page.getByRole('button', { name: 'Sync Now' }).click();
|
|
expect(syncCalled).toBe(true);
|
|
});
|
|
|
|
test('reset requires confirmation', async ({ page }) => {
|
|
await mockRoutes(page, {
|
|
isAuthenticated: true,
|
|
needsFullDiskAccess: false,
|
|
messageCount: 100,
|
|
conversationCount: 10,
|
|
contactCount: 5,
|
|
});
|
|
|
|
await page.goto('/');
|
|
await page.getByText('Admin').click();
|
|
await page.getByRole('button', { name: 'Reset All Data' }).click();
|
|
await expect(page.getByRole('button', { name: 'Confirm Reset' })).toBeVisible();
|
|
});
|