import { test, expect } from '@playwright/test'; import { clearPizzaDay } from './helpers'; test.beforeEach(async ({ page, request }) => { // Vyčistíme volby dne, aby testy neovlivnily navzájem await request.post('/api/dev/clear', { data: { dayIndex: 4 }, }); await page.goto('/'); await page.waitForLoadState('networkidle'); // Počkáme, až se zobrazí volba stravování await expect(page.locator('.choice-section select').first()).toBeVisible({ timeout: 10_000 }); }); test('výběr restaurace zobrazí seznam jídel', async ({ page }) => { const locationSelect = page.locator('.choice-section select').first(); // Vybereme Sladovnickou – mock menu existuje await locationSelect.selectOption('SLADOVNICKA'); // Po výběru restaurace se zobrazí druhý select s jídly const foodSelect = page.locator('.choice-section select').nth(1); await expect(foodSelect).toBeVisible({ timeout: 5_000 }); // Select musí obsahovat alespoň 2 možnosti (empty + ≥1 jídlo) const options = foodSelect.locator('option'); expect(await options.count()).toBeGreaterThan(1); }); test('výběr jídla se uloží a přetrvá po reload', async ({ page }) => { const locationSelect = page.locator('.choice-section select').first(); await locationSelect.selectOption('SLADOVNICKA'); const foodSelect = page.locator('.choice-section select').nth(1); await expect(foodSelect).toBeVisible({ timeout: 5_000 }); // Vybereme první nenulovou možnost const options = await foodSelect.locator('option:not([value=""])').all(); if (options.length === 0) { test.skip(); // Mock data nejsou dostupná pro tuto restauraci } const firstValue = await options[0].getAttribute('value'); await foodSelect.selectOption({ value: firstValue! }); // Počkáme, až se volba přenese na server await page.waitForLoadState('networkidle'); // Po reload musí volba přetrvat v tabulce choices await page.reload(); await page.waitForLoadState('networkidle'); const choicesTable = page.locator('.choices-table'); await expect(choicesTable).toBeVisible({ timeout: 5_000 }); await expect(choicesTable.locator('text=Sladovnická')).toBeVisible(); }); test('přepnutí na NEOBEDVAM odstraní výběr restaurace', async ({ page }) => { // Nejprve zvolíme restauraci const locationSelect = page.locator('.choice-section select').first(); await locationSelect.selectOption('SLADOVNICKA'); await page.waitForLoadState('networkidle'); // Přepneme na "Neobědvám" await locationSelect.selectOption('NEOBEDVAM'); await page.waitForLoadState('networkidle'); // Tabulka choices musí zobrazovat "Neobědvám" const choicesTable = page.locator('.choices-table'); await expect(choicesTable).toBeVisible({ timeout: 5_000 }); await expect(choicesTable.locator('text=Neobědvám')).toBeVisible(); });