2025-10-19 21:35:02 -04:00
|
|
|
/**
|
|
|
|
|
* End-to-end tests using Playwright
|
|
|
|
|
*/
|
|
|
|
|
|
2026-06-19 17:00:57 -04:00
|
|
|
import { test, expect } from '@playwright/test';
|
2025-10-19 21:35:02 -04:00
|
|
|
|
2025-11-01 10:47:02 -04:00
|
|
|
// Helper function for network-resilient page navigation
|
|
|
|
|
async function navigateWithRetry(page: any, url: string, maxRetries = 3): Promise<void> {
|
|
|
|
|
for (let i = 0; i < maxRetries; i++) {
|
|
|
|
|
try {
|
|
|
|
|
await page.goto(url, {
|
|
|
|
|
waitUntil: 'networkidle',
|
2026-06-19 17:00:57 -04:00
|
|
|
timeout: process.env.CI ? 45000 : 30000,
|
|
|
|
|
});
|
|
|
|
|
return; // Success
|
2025-11-01 10:47:02 -04:00
|
|
|
} catch (error) {
|
2026-06-19 17:00:57 -04:00
|
|
|
if (i === maxRetries - 1) throw error; // Last attempt failed
|
|
|
|
|
console.log(`Navigation attempt ${i + 1} failed, retrying...`);
|
|
|
|
|
await page.waitForTimeout(2000); // Wait before retry
|
2025-11-01 10:47:02 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-19 21:35:02 -04:00
|
|
|
test.describe('Plex Playlist App', () => {
|
|
|
|
|
test('should display app title', async ({ page }) => {
|
2026-06-19 17:00:57 -04:00
|
|
|
await navigateWithRetry(page, '/');
|
2025-10-19 21:35:02 -04:00
|
|
|
|
2025-11-01 10:47:02 -04:00
|
|
|
// Wait for the app to fully load with network resilience
|
2026-06-19 17:00:57 -04:00
|
|
|
await page.waitForSelector('h1', { timeout: 15000 });
|
|
|
|
|
await expect(page.locator('h1')).toContainText('Plex Playlist');
|
|
|
|
|
});
|
2025-10-19 21:35:02 -04:00
|
|
|
|
|
|
|
|
test('should have welcome message', async ({ page }) => {
|
2026-06-19 17:00:57 -04:00
|
|
|
await navigateWithRetry(page, '/');
|
2025-10-19 21:35:02 -04:00
|
|
|
|
2025-11-01 10:47:02 -04:00
|
|
|
// Wait for the welcome message to appear with network resilience
|
2026-06-19 17:00:57 -04:00
|
|
|
await page.waitForSelector('p', { timeout: 15000 });
|
|
|
|
|
await expect(page.locator('p')).toContainText('Welcome to the Plex Playlist Manager');
|
|
|
|
|
});
|
2025-10-19 21:35:02 -04:00
|
|
|
|
|
|
|
|
test('should load without errors', async ({ page }) => {
|
2026-06-19 17:00:57 -04:00
|
|
|
const errors: string[] = [];
|
2025-10-19 21:35:02 -04:00
|
|
|
page.on('console', (msg) => {
|
|
|
|
|
if (msg.type() === 'error') {
|
2025-11-01 10:47:02 -04:00
|
|
|
// Filter out network-related errors that are acceptable in CI
|
2026-06-19 17:00:57 -04:00
|
|
|
const errorText = msg.text();
|
2025-11-01 10:47:02 -04:00
|
|
|
if (!errorText.includes('net::') && !errorText.includes('Failed to fetch')) {
|
2026-06-19 17:00:57 -04:00
|
|
|
errors.push(errorText);
|
2025-11-01 10:47:02 -04:00
|
|
|
}
|
2025-10-19 21:35:02 -04:00
|
|
|
}
|
2026-06-19 17:00:57 -04:00
|
|
|
});
|
2025-10-19 21:35:02 -04:00
|
|
|
|
2026-06-19 17:00:57 -04:00
|
|
|
await navigateWithRetry(page, '/');
|
2025-10-19 21:35:02 -04:00
|
|
|
|
2025-11-01 10:47:02 -04:00
|
|
|
// Wait for app to fully load with extra time for network instability
|
2026-06-19 17:00:57 -04:00
|
|
|
await page.waitForLoadState('networkidle');
|
2025-10-19 21:35:02 -04:00
|
|
|
|
2025-11-01 10:47:02 -04:00
|
|
|
// Give extra time for any async operations in unstable networks
|
2026-06-19 17:00:57 -04:00
|
|
|
await page.waitForTimeout(process.env.CI ? 3000 : 1000);
|
2025-11-01 10:47:02 -04:00
|
|
|
|
2026-06-19 17:00:57 -04:00
|
|
|
expect(errors).toHaveLength(0);
|
|
|
|
|
});
|
|
|
|
|
});
|