Files
task-manager/tests/data_export.spec.ts
2025-12-17 14:26:54 +01:00

47 lines
1.7 KiB
TypeScript

import { test, expect } from '@playwright/test';
test.describe('Data Export', () => {
test.beforeEach(async ({ page }) => {
await page.goto('http://localhost:5001/auth');
await page.fill('input[name="username"]', 'admin');
await page.fill('input[name="password"]', 'admin123');
await page.click('button[type="submit"]');
await expect(page).toHaveURL('http://localhost:5001/');
});
test.skip('should export user data as JSON', async ({ page }) => {
// 1. Go to Settings
await page.goto('http://localhost:5001/settings');
// 2. Click Export Data button
// Wait for download *response* (the blob)
const downloadPromise = page.waitForResponse(response =>
response.url().includes('/api/user/data-export') &&
response.status() === 200 &&
response.request().method() === 'POST'
);
// Trigger export
await page.click('button[data-testid="button-export-data"]');
const response = await downloadPromise;
expect(response.ok()).toBeTruthy();
// 3. Verify Content
const json = await response.json();
// Verify structure
expect(json).toHaveProperty('user');
expect(json.user).toHaveProperty('username', 'admin');
// expect(json.user).toHaveProperty('email', 'admin@example.com'); // Email might vary if we used seed logic differently, but admin/admin123 usually has admin@example.com
expect(json).toHaveProperty('tasks');
expect(Array.isArray(json.tasks)).toBeTruthy();
expect(json).toHaveProperty('labels');
expect(Array.isArray(json.labels)).toBeTruthy();
expect(json).toHaveProperty('systemSettings');
});
});