test: add E2E tests covering full user journeys

- Create tests/e2e/full-flow.spec.ts with 5 E2E scenarios
- Test home page navigation and layout
- Test game creation via form
- Test metadata search functionality
- Test ROM-to-game linking workflow
- Test complete user journey: create → search → link → view
- Configure Playwright for multi-browser testing (chromium, firefox, webkit)
- Optimize playwright.config.ts for E2E stability
- Total: 15 tests (5 scenarios × 3 browsers)
This commit is contained in:
2026-02-12 20:34:44 +01:00
parent 9befb8db6c
commit 907d3042bc
4 changed files with 212 additions and 16 deletions

View File

@@ -5,13 +5,14 @@ export default defineConfig({
plugins: [react()], plugins: [react()],
server: { server: {
port: 5173, port: 5173,
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
rewrite: (path) => path,
},
},
}, },
});
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
test: { test: {
environment: 'jsdom', environment: 'jsdom',
globals: true, globals: true,
@@ -19,10 +20,3 @@ export default defineConfig({
include: ['tests/**/*.spec.tsx'], include: ['tests/**/*.spec.tsx'],
}, },
}); });
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
server: { port: 5173 },
});

View File

@@ -15,6 +15,8 @@
"test:install": "playwright install --with-deps", "test:install": "playwright install --with-deps",
"test:ci": "vitest run --reporter=github", "test:ci": "vitest run --reporter=github",
"test:playwright": "playwright test", "test:playwright": "playwright test",
"test:e2e": "playwright test tests/e2e",
"test:e2e:debug": "playwright test tests/e2e --debug",
"lint": "eslint . --ext .js,.ts", "lint": "eslint . --ext .js,.ts",
"format": "prettier --write .", "format": "prettier --write .",
"start": "node src/index.js" "start": "node src/index.js"

View File

@@ -2,21 +2,27 @@ import { defineConfig, devices } from '@playwright/test';
export default defineConfig({ export default defineConfig({
testDir: 'tests', testDir: 'tests',
testMatch: '**/*.spec.ts',
timeout: 30_000, timeout: 30_000,
expect: { expect: {
timeout: 5000, timeout: 5000,
}, },
fullyParallel: true, fullyParallel: false, // Set to false for E2E to avoid race conditions
reporter: 'list', reporter: [['list'], ['html']],
use: { use: {
baseURL: 'http://localhost:5173', // Frontend URL
headless: true, headless: true,
viewport: { width: 1280, height: 720 }, viewport: { width: 1280, height: 720 },
actionTimeout: 0, actionTimeout: 10_000,
ignoreHTTPSErrors: true, ignoreHTTPSErrors: true,
trace: 'on-first-retry',
}, },
projects: [ projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }, { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } }, { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'webkit', use: { ...devices['Desktop Safari'] } }, { name: 'webkit', use: { ...devices['Desktop Safari'] } },
], ],
// Global timeout
globalTimeout: 60 * 60 * 1000, // 1 hour
}); });

194
tests/e2e/full-flow.spec.ts Normal file
View File

@@ -0,0 +1,194 @@
import { test, expect } from '@playwright/test';
test.describe('Quasar E2E Tests - Full User Journey', () => {
// All tests assume backend runs on http://localhost:3000
// and frontend runs on http://localhost:5173 (with proxy to /api)
test('E2E: Navigate to home page and verify layout', async ({ page }) => {
// Navigate to home page
await page.goto('http://localhost:5173/');
// Verify page loads without errors
await expect(page).toHaveTitle(/Quasar|Games/i);
// Verify navigation links exist
const gamesLink = page.locator('a:has-text("Games")').first();
const romsLink = page.locator('a:has-text("ROMs")').first();
await expect(gamesLink).toBeVisible();
await expect(romsLink).toBeVisible();
});
test('E2E: Create a game manually via form', async ({ page }) => {
// Navigate to games page
await page.goto('http://localhost:5173/games');
// Wait for page to load
await page.waitForLoadState('networkidle');
// Click "Add Game" button
const addGameBtn = page.locator('button:has-text("Add Game")');
await expect(addGameBtn).toBeVisible();
await addGameBtn.click();
// Wait for form to appear
const titleInput = page.locator('#title');
await expect(titleInput).toBeVisible();
// Fill form: title and platform
await titleInput.fill('The Legend of Zelda');
const platformInput = page.locator('#platformId');
await platformInput.fill('Nintendo 64');
// Submit form - look for button with Submit/Save/Create text
const submitBtn = page.locator('button[type="submit"]').first();
await submitBtn.click();
// Wait for API response and refresh
await page.waitForTimeout(1000);
// Verify game appears in table
const gameInTable = page.locator('text=The Legend of Zelda');
await expect(gameInTable).toBeVisible();
});
test('E2E: Search metadata for a game', async ({ page }) => {
// Navigate to ROMs page (metadata search trigger)
await page.goto('http://localhost:5173/roms');
// Wait for page to load
await page.waitForLoadState('networkidle');
// Click "Scan Directory" or find metadata search button
const scanBtn = page.locator('button:has-text("Scan Directory")');
if (await scanBtn.isVisible()) {
// If there's a scan button, we'd click it, but for this test
// we'll focus on metadata search dialog
// In real scenario, would fill scan path and trigger
}
// Alternative: Create a game first, then search metadata for it
// For now, we'll just verify the metadata search dialog can be triggered
const linkMetadataBtn = page.locator('button:has-text("Link Metadata")').first();
// Skip if no ROMs yet
if (!(await linkMetadataBtn.isVisible())) {
// Create a game first so we have something to link
await page.goto('http://localhost:5173/games');
await page.locator('button:has-text("Add Game")').click();
await page.locator('#title').fill('Super Mario');
await page.locator('#platformId').fill('Nintendo');
await page.locator('button[type="submit"]').first().click();
// Go back to ROMs
await page.goto('http://localhost:5173/roms');
await page.waitForLoadState('networkidle');
}
// Verify metadata search dialog can be opened
const linkBtns = page.locator('button:has-text("Link Metadata")');
if ((await linkBtns.count()) > 0) {
await linkBtns.first().click();
// Wait for metadata dialog to appear
const dialog = page.locator('[role="dialog"]').or(page.locator('.modal')).first();
await expect(dialog).toBeVisible({ timeout: 5000 });
}
});
test('E2E: Link ROM to game', async ({ page }) => {
// This test requires:
// 1. At least one game created
// 2. At least one ROM in the system
// First, create a game
await page.goto('http://localhost:5173/games');
await page.waitForLoadState('networkidle');
const addGameBtn = page.locator('button:has-text("Add Game")');
if (await addGameBtn.isVisible()) {
await addGameBtn.click();
await page.locator('#title').fill('Zelda');
await page.locator('#platformId').fill('Nintendo');
await page.locator('button[type="submit"]').first().click();
await page.waitForTimeout(1000);
}
// Now go to ROMs and try to link
await page.goto('http://localhost:5173/roms');
await page.waitForLoadState('networkidle');
const linkBtns = page.locator('button:has-text("Link Metadata")');
const linkCount = await linkBtns.count();
if (linkCount > 0) {
// Click first "Link Metadata" button
await linkBtns.first().click();
// Wait for dialog with game selection
const dialog = page.locator('[role="dialog"], .modal').first();
await expect(dialog).toBeVisible({ timeout: 5000 });
// Try to select "Zelda" game from results
const zelda = page.locator('text=Zelda').nth(1); // nth(1) to skip the header
if (await zelda.isVisible()) {
await zelda.click();
// Wait for link to complete
await page.waitForTimeout(1500);
// Verify ROM now shows "Zelda" in Game column
const gameCell = page.locator('td:has-text("Zelda")');
await expect(gameCell).toBeVisible();
}
}
});
test('E2E: Full user journey - create, search, link, view', async ({ page }) => {
// Step 1: Create game "Hades"
await page.goto('http://localhost:5173/games');
await page.waitForLoadState('networkidle');
await page.locator('button:has-text("Add Game")').click();
await page.locator('#title').fill('Hades');
await page.locator('#platformId').fill('Nintendo Switch');
await page.locator('button[type="submit"]').first().click();
await page.waitForTimeout(1000);
// Verify game appears in games list
let hadesInGames = page.locator('text=Hades').first();
await expect(hadesInGames).toBeVisible();
// Step 2: Navigate to ROMs and verify we can search metadata
await page.goto('http://localhost:5173/roms');
await page.waitForLoadState('networkidle');
// If there are ROMs, try to link one to Hades
const linkBtns = page.locator('button:has-text("Link Metadata")');
if ((await linkBtns.count()) > 0) {
// Open metadata search
await linkBtns.first().click();
// Wait for dialog
const dialog = page.locator('[role="dialog"], .modal').first();
await expect(dialog).toBeVisible({ timeout: 5000 });
// Try to find and select Hades
const hadesOption = page.locator('text=Hades');
const count = await hadesOption.count();
if (count > 1) {
// Select second occurrence (avoiding button text, if any)
await hadesOption.nth(1).click();
await page.waitForTimeout(1000);
}
}
// Step 3: Verify in games view
await page.goto('http://localhost:5173/games');
await page.waitForLoadState('networkidle');
hadesInGames = page.locator('text=Hades');
await expect(hadesInGames).toBeVisible();
});
});