Files
brachnha-insight/tests/integration/sync-action-replay.test.ts
Max 3fbbb1a93b Initial commit: Brachnha Insight project setup
- Next.js 14+ with App Router and TypeScript
- Tailwind CSS and ShadCN UI styling
- Zustand state management
- Dexie.js for IndexedDB (local-first data)
- Auth.js v5 for authentication
- BMAD framework integration

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-26 12:28:43 +07:00

41 lines
1.5 KiB
TypeScript

import { expect } from '@playwright/test';
import { test } from '../support/fixtures/offline.fixture';
test.describe('Sync Action Replay', () => {
test('should process pending actions when network restores', async ({ offlineControl, page }) => {
// GIVEN: Offline queue has actions
await page.goto('/'); // Ensure page is loaded to initialize DB
await page.waitForFunction(() => (window as any).db !== undefined, { timeout: 10000 });
await offlineControl.goOffline(page.context());
// Seed queue via evaluate
await page.evaluate(async () => {
// @ts-ignore
await window.db.syncQueue.add({
action: 'saveDraft',
payload: { draftData: { title: 'Pending Sync', content: '...' } },
status: 'pending',
createdAt: Date.now(),
retries: 0
});
});
// WHEN: Network restores
await offlineControl.goOnline(page.context());
// Trigger sync - The SyncManager listens to 'online' event.
// Note: The 'online' event listeners might execute async.
// Wait for processing
// We can poll the DB
await expect.poll(async () => {
return await page.evaluate(async () => {
// @ts-ignore
return await window.db.syncQueue.where('status').equals('pending').count();
});
}, { timeout: 5000 }).toBe(0);
});
});