const { chromium } = require('playwright');

async function runTests() {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  
  try {
    // Navigate to the application
    console.log('Navigating to http://localhost:3000...');
    await page.goto('http://localhost:3000', { waitUntil: 'domcontentloaded', timeout: 30000 });
    
    // Wait for page to fully load
    await page.waitForTimeout(2000);
    
    // Close the modal dialog if it exists
    console.log('Attempting to close modal...');
    try {
      // Try clicking the "시작하기" button to close the modal
      const startBtn = page.locator('button:has-text("시작하기")').first();
      await startBtn.click({ timeout: 5000 });
      await page.waitForTimeout(1000);
    } catch (e) {
      console.log('Modal button not found, continuing...');
    }
    
    // Try clicking on "통합 테스트"
    console.log('Looking for 통합 테스트 menu...');
    try {
      const testMenu = page.locator('button:has-text("통합 테스트")').first();
      await testMenu.click({ timeout: 5000 });
      await page.waitForTimeout(1500);
    } catch (e) {
      console.log('Could not click 통합 테스트:', e.message);
    }
    
    // Take screenshot
    console.log('Taking screenshot after navigation...');
    await page.screenshot({ path: 'test_results_1.png', fullPage: true });
    
    // Display page content to see current state
    const pageContent = await page.evaluate(() => {
      return document.body.innerText;
    });
    
    console.log('\n=== CURRENT PAGE STATE ===\n');
    console.log(pageContent.substring(0, 2000));
    
  } catch (error) {
    console.error('Error:', error.message);
  } finally {
    await browser.close();
  }
}

runTests();
