import { chromium, test, expect } from '@playwright/test';

test.describe('Authentication Flow', () => {
  test('should sign in and show authenticated home', async ({ page }) => {
    await page.goto('https://code-dev.g4dge7.com:5174/sign-in');
    await page.waitForLoadState('networkidle');

    await page.fill('#email', 'rob@digitaltelepresence.com');
    await page.fill('#password', 'ionfrali');
    await page.click('button[type="submit"]');
    await page.waitForTimeout(3000);

    const userData = await page.evaluate(() => localStorage.getItem('dtp_user'));
    expect(userData).toBeDefined();

    const content = await page.content();
    expect(content).toContain('Welcome');
    expect(content).toContain('Rob Colbert');
  });

  test('should sign out and show unauthenticated home', async ({ page }) => {
    await page.goto('https://code-dev.g4dge7.com:5174/sign-in');
    await page.waitForLoadState('networkidle');
    await page.fill('#email', 'rob@digitaltelepresence.com');
    await page.fill('#password', 'ionfrali');
    await page.click('button[type="submit"]');
    await page.waitForTimeout(2000);

    await page.click('button:has-text("Sign Out")');
    await page.waitForTimeout(2000);

    const userData = await page.evaluate(() => localStorage.getItem('dtp_user'));
    expect(userData).toBeNull();

     const content = await page.content();
     expect(content).toContain('Sign In');
   });
 });