/** * E2E Test: Tournament Edit with allowTies * * User Story: As a tournament admin, I want to edit tournament settings including allowTies * * Acceptance Criteria: * - Can edit tournament settings * - allowTies checkbox can be toggled * - allowTies value is saved correctly */ import { test, expect } from '@playwright/test'; import { prisma } from '@/lib/prisma'; test.describe('Tournament Edit - allowTies functionality', () => { let tournamentId: number; test.beforeAll(async () => { // Create a test tournament for editing const tournament = await prisma.event.create({ data: { name: 'Test Tournament for AllowTies Edit', eventType: 'tournament', format: 'round_robin', status: 'planned', allowTies: false, targetScore: 5, createdAt: new Date(), updatedAt: new Date(), }, }); tournamentId = tournament.id; }); test.afterAll(async () => { // Clean up test tournament if (tournamentId) { await prisma.event.delete({ where: { id: tournamentId }, }); } }); test('should display allowTies checkbox on edit form @chromium-admin', async ({ page }) => { // Navigate to tournament edit page await page.goto(`/admin/tournaments/${tournamentId}/edit`); // Wait for form to load await expect(page.locator('text=Tournament Name')).toBeVisible(); // Check that allowTies checkbox exists const allowTiesCheckbox = page.locator('input[name="allowTies"]'); await expect(allowTiesCheckbox).toBeVisible(); await expect(allowTiesCheckbox).not.toBeChecked(); }); test('should save allowTies when toggled to true @chromium-admin', async ({ page }) => { // Navigate to tournament edit page await page.goto(`/admin/tournaments/${tournamentId}/edit`); // Wait for form to load await expect(page.locator('text=Tournament Name')).toBeVisible(); // Toggle allowTies checkbox const allowTiesCheckbox = page.locator('input[name="allowTies"]'); await allowTiesCheckbox.check(); await expect(allowTiesCheckbox).toBeChecked(); // Submit form await page.click('button[type="submit"]'); // Wait for success message await expect(page.locator('text=Tournament updated successfully')).toBeVisible({ timeout: 5000 }); // Verify allowTies was saved by checking the database const updatedTournament = await prisma.event.findUnique({ where: { id: tournamentId }, }); expect(updatedTournament?.allowTies).toBe(true); }); test('should save allowTies when toggled to false @chromium-admin', async ({ page }) => { // First, set allowTies to true await prisma.event.update({ where: { id: tournamentId }, data: { allowTies: true }, }); // Navigate to tournament edit page await page.goto(`/admin/tournaments/${tournamentId}/edit`); // Wait for form to load await expect(page.locator('text=Tournament Name')).toBeVisible(); // Verify checkbox is checked const allowTiesCheckbox = page.locator('input[name="allowTies"]'); await expect(allowTiesCheckbox).toBeChecked(); // Uncheck allowTies checkbox await allowTiesCheckbox.uncheck(); await expect(allowTiesCheckbox).not.toBeChecked(); // Submit form await page.click('button[type="submit"]'); // Wait for success message await expect(page.locator('text=Tournament updated successfully')).toBeVisible({ timeout: 5000 }); // Verify allowTies was saved by checking the database const updatedTournament = await prisma.event.findUnique({ where: { id: tournamentId }, }); expect(updatedTournament?.allowTies).toBe(false); }); });