feat: přidání testů – Jest unit testy + Playwright E2E + CI pipeline
Server: - Jest unit testy (88 testů): auth, utils, restaurants, service, voting, pizza - in-memory storage mock pro izolaci testů - oprava race condition při inicializaci Redis (storageReady promise) - dev route dostupná i pro NODE_ENV=test - getStatsMock deterministický (nahrazení Math.random) - exporty interních helperů pro testovatelnost - /api/health endpoint pro Playwright readiness check - tsconfig vylučuje test soubory z produkčního buildu E2E (e2e/): - Playwright s Firefoxem + Chromiem - testy: login, menu, výběr jídla, pizza day životní cyklus, QR/nastavení - trusted-header auth bypass pro testy, video + trace při selhání CI (Woodpecker): - pipeline spouštěna na všech větvích a PR (nejen master) - redis-stack-server service pro E2E – čistý Redis per větev automaticky - kroky: unit testy, build, E2E testy (parallel kde možné) - Docker build zůstává pouze pro master Co-Authored-By: Claude Opus (extra usage) 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Trusted-header login runs automatically when Login mounts.
|
||||
// networkidle zaručí, že fetch('/api/data') byl dokončen.
|
||||
await page.goto('/');
|
||||
await page.waitForLoadState('networkidle');
|
||||
});
|
||||
|
||||
test('zobrazí mock datum 10.01.2025', async ({ page }) => {
|
||||
// MOCK_DATA=true pins today to 2025-01-10
|
||||
await expect(page.locator('text=10.01')).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
test('zobrazí čtyři restaurační karty z mock dat', async ({ page }) => {
|
||||
// Každá restaurace je obalena v .restaurant-card
|
||||
const cards = page.locator('.restaurant-card');
|
||||
await expect(cards).toHaveCount(4, { timeout: 10_000 });
|
||||
});
|
||||
|
||||
test('zobrazí alespoň jedno jídlo v menu každé restaurace', async ({ page }) => {
|
||||
await expect(page.locator('.restaurant-card').first()).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
// Každá karta musí mít aspoň jeden řádek v .food-table
|
||||
const cards = page.locator('.restaurant-card');
|
||||
const count = await cards.count();
|
||||
for (let i = 0; i < count; i++) {
|
||||
const card = cards.nth(i);
|
||||
const rows = card.locator('.food-table tr');
|
||||
expect(await rows.count()).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
test('zobrazí volbu stravování před menu', async ({ page }) => {
|
||||
// Sekce .choice-section obsahuje select pro výběr stravování
|
||||
const choiceSection = page.locator('.choice-section');
|
||||
await expect(choiceSection).toBeVisible({ timeout: 10_000 });
|
||||
await expect(choiceSection.locator('select').first()).toBeVisible();
|
||||
});
|
||||
Reference in New Issue
Block a user