Files
silverbullet-icalendar/tests/e2e/sync.spec.ts
sstent 90ab92421a
Some checks failed
Build SilverBullet Plug / build (push) Has been cancelled
feat(test): implement Playwright E2E and Dockerized testing infrastructure
2026-02-21 13:19:37 -08:00

81 lines
2.9 KiB
TypeScript

import { test, expect } from '@playwright/test';
test.describe('iCalendar Sync E2E', () => {
test('should verify iCalendar sync activity', async ({ page }) => {
const logs: string[] = [];
const errors: string[] = [];
page.on('console', msg => {
const text = msg.text();
if (msg.type() === 'error') errors.push(text);
if (text.includes('[iCalendar]')) {
logs.push(text);
console.log('Detected SB Log:', text);
}
});
// 1. Load Editor
console.log('Navigating to /');
await page.goto('/');
await page.waitForLoadState('networkidle');
console.log('Page reached, waiting for boot sequence...');
// 2. Persistent Monitoring for Sync Activity
let syncDetected = false;
let eventsSynced = 0;
const timeoutMs = 120000; // 2 minutes
const startTime = Date.now();
console.log(`Starting monitoring loop for ${timeoutMs/1000}s...`);
while (Date.now() - startTime < timeoutMs) {
// Check for notifications
const notification = page.locator('.sb-notification:has-text("Synced")');
if (await notification.count() > 0) {
const text = await notification.innerText();
console.log('Detected Sync Notification:', text);
const match = text.match(/Synced (\d+) events/);
if (match) {
eventsSynced = parseInt(match[1], 10);
if (eventsSynced > 0) {
syncDetected = true;
console.log(`SUCCESS: ${eventsSynced} events synced!`);
break;
}
}
}
// Every 30 seconds, try to "poke" it with a keyboard shortcut if not started
const elapsed = Date.now() - startTime;
if (elapsed > 30000 && elapsed < 35000 && !syncDetected) {
console.log('Auto-sync not detected yet, trying manual trigger shortcut...');
await page.keyboard.press('.');
await page.waitForTimeout(1000);
await page.keyboard.type('iCalendar: Sync');
await page.keyboard.press('Enter');
}
await page.waitForTimeout(2000);
}
// 3. Final verification
console.log('Final accumulated [iCalendar] logs:', logs);
// Check if the query rendered meetings in the UI
const meetingItems = page.locator('li:has-text("to"):has-text(":")');
const meetingCount = await meetingItems.count();
console.log(`Meetings found in UI: ${meetingCount}`);
// Filter out expected noise
const relevantErrors = errors.filter(e => !e.includes('401') && !e.includes('favicon'));
expect(relevantErrors, `Found unexpected errors: ${relevantErrors[0]}`).toHaveLength(0);
expect(syncDetected, 'iCalendar sync failed or synced 0 events').toBe(true);
expect(eventsSynced).toBeGreaterThan(0);
// Verify query rendering
expect(meetingCount).toBeGreaterThanOrEqual(12);
console.log('Test Passed.');
});
});