import { test, expect } from '@playwright/test'; import { LoginPage } from '../pages/LoginPage'; import { ProblemSetPage } from '../pages/ProblemSetPage'; import { ProblemPage } from '../pages/ProblemPage'; import { SubmitPage } from '../pages/SubmitPage'; import { ChallengePage } from '../pages/ChallengePage'; import { ChallengeListPage } from '../pages/ChallengeListPage'; import { TEST_USER, CODE_SAMPLES, VERDICTS } from '../utils/test-data'; /** * Test Suite: Code Submission * Tests for submitting code and checking judge results * * Note: These tests will actually submit code and be judged by the system */ test.describe('Code Submission', () => { let problemId: number; // Login before all tests test.beforeAll(async ({ browser }) => { const context = await browser.newContext(); const page = await context.newPage(); const loginPage = new LoginPage(page); await loginPage.goto(); await loginPage.login(TEST_USER.email, TEST_USER.password); // Get first available problem const problemSetPage = new ProblemSetPage(page); await problemSetPage.goto(); const firstProblemId = await problemSetPage.getFirstProblemId(); if (firstProblemId) { problemId = firstProblemId; } await context.close(); }); test.beforeEach(async ({ page }) => { const loginPage = new LoginPage(page); await loginPage.goto(); await loginPage.login(TEST_USER.email, TEST_USER.password); await loginPage.verifyLoginSuccess(); }); test('should display submit page correctly', async ({ page }) => { test.skip(!problemId, 'No problem available for testing'); const submitPage = new SubmitPage(page); await submitPage.goto(problemId); await submitPage.verifyOnPage(problemId); // Verify form elements are visible await expect(submitPage.compilerSelect).toBeVisible(); await expect(submitPage.codeTextarea).toBeVisible(); await expect(submitPage.submitButton).toBeVisible(); }); test('should submit C++ code and get judged', async ({ page }) => { test.skip(!problemId, 'No problem available for testing'); test.setTimeout(120000); // 2 minutes timeout for judging const submitPage = new SubmitPage(page); const challengeListPage = new ChallengeListPage(page); const challengePage = new ChallengePage(page); // Go to submit page await submitPage.goto(problemId); // Submit code await submitPage.submitCode('G++', CODE_SAMPLES.cpp_aplusb); // Should redirect to challenge list or challenge detail // Wait a moment for redirect await page.waitForTimeout(2000); // Get the latest challenge ID await challengeListPage.goto(); const challengeId = await challengeListPage.getLatestChallengeId(); expect(challengeId).not.toBeNull(); if (challengeId) { // Go to challenge detail page await challengePage.goto(challengeId); // Wait for judging to complete console.log('Waiting for judge to complete...'); const verdict = await challengePage.waitForJudgeComplete(90000, 3000); console.log(`Judge result: ${verdict}`); // Verdict should be one of the valid states expect(verdict).toBeTruthy(); expect(['AC', 'WA', 'TLE', 'MLE', 'RE', 'CE', 'PE', 'IE']).toContain(verdict); } }); test('should submit Python code and get judged', async ({ page }) => { test.skip(!problemId, 'No problem available for testing'); test.setTimeout(120000); // 2 minutes timeout for judging const submitPage = new SubmitPage(page); const challengeListPage = new ChallengeListPage(page); const challengePage = new ChallengePage(page); // Go to submit page await submitPage.goto(problemId); // Wait for cooldown if needed (30 seconds from previous submission) await submitPage.waitForCooldown(); // Submit Python code await submitPage.submitCode('Python', CODE_SAMPLES.python_aplusb); // Wait for redirect await page.waitForTimeout(2000); // Get the latest challenge ID await challengeListPage.goto(); const challengeId = await challengeListPage.getLatestChallengeId(); if (challengeId) { await challengePage.goto(challengeId); console.log('Waiting for judge to complete...'); const verdict = await challengePage.waitForJudgeComplete(90000, 3000); console.log(`Judge result: ${verdict}`); expect(verdict).toBeTruthy(); } }); test('should respect submission cooldown time', async ({ page }) => { test.skip(!problemId, 'No problem available for testing'); const submitPage = new SubmitPage(page); // First submission await submitPage.goto(problemId); await submitPage.submitCode('G++', CODE_SAMPLES.cpp_aplusb); // Wait a moment await page.waitForTimeout(2000); // Try to submit again immediately await submitPage.goto(problemId); await submitPage.fillCode(CODE_SAMPLES.cpp_aplusb); await submitPage.submit(); // Should see cooldown message or error const errorMsg = await submitPage.getErrorMessage(); console.log('Cooldown error message:', errorMsg); // Note: This test may need adjustment based on actual cooldown implementation }); });