48 lines
2 KiB
TypeScript
48 lines
2 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
test.describe('Scenario 10: IndexedDB Snapshots (Export, Reset, Import)', () => {
|
|
test('exports database snapshot, resets demo data, imports snapshot, and verifies restored state', async ({ page }) => {
|
|
test.setTimeout(60000);
|
|
await page.goto('/settings', { waitUntil: 'domcontentloaded' });
|
|
|
|
// 1. Export database snapshot
|
|
const exportBtn = page.locator('[data-testid="export-snapshot-btn"]');
|
|
await expect(exportBtn).toBeVisible({ timeout: 15000 });
|
|
|
|
const downloadPromise = page.waitForEvent('download');
|
|
await exportBtn.click();
|
|
const download = await downloadPromise;
|
|
expect(download.suggestedFilename()).toContain('.json');
|
|
|
|
// 2. Read downloaded snapshot content
|
|
const downloadPath = await download.path();
|
|
expect(downloadPath).toBeTruthy();
|
|
|
|
// 3. Reset database to initial state
|
|
const resetBtn = page.locator('[data-testid="reset-database-btn"]');
|
|
await expect(resetBtn).toBeVisible();
|
|
await resetBtn.click();
|
|
|
|
await expect(page.locator('text=сброшена').or(page.locator('text=Сбросить')).first()).toBeVisible({ timeout: 5000 });
|
|
|
|
// 4. Import the exported snapshot back
|
|
if (downloadPath) {
|
|
const fileInput = page.locator('[data-testid="import-snapshot-input"]');
|
|
await fileInput.setInputFiles(downloadPath);
|
|
|
|
// Verify successful import notification
|
|
await expect(page.locator('text=успешно импортирован').or(page.locator('text=Импортировано')).first()).toBeVisible({ timeout: 10000 });
|
|
}
|
|
|
|
// 5. Reload page to ensure restored state persists
|
|
await page.reload({ waitUntil: 'domcontentloaded' });
|
|
await page.waitForLoadState('domcontentloaded');
|
|
|
|
const retryBtn = page.locator('button:has-text("Попробовать снова")');
|
|
if (await retryBtn.isVisible({ timeout: 2000 }).catch(() => false)) {
|
|
await retryBtn.click();
|
|
}
|
|
|
|
await expect(exportBtn).toBeVisible({ timeout: 15000 });
|
|
});
|
|
});
|