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

/**
 * Dashboard Navigation Tests
 * Generated from: specs/dashboard/navigation.md
 *
 * Tests the dashboard and navigation functionality
 */

// Helper function to login
async function loginAsAdmin(page) {
  await page.goto('/auth/login', { waitUntil: 'networkidle' });
  await page.locator('#email').fill('admin@demo.com');
  await page.locator('#password').fill('password123');
  await page.locator('button[type="submit"]').click();
  await page.waitForURL('**/dashboard', { timeout: 15000 });
}

test.describe('Dashboard Navigation', () => {
  test('should redirect guest to login', async ({ page }) => {
    // Try to access dashboard without being logged in
    await page.goto('/dashboard', { waitUntil: 'networkidle' });

    // Should be redirected to login
    await expect(page).toHaveURL(/.*login/);
  });

  test('should show dashboard after login', async ({ page }) => {
    // Login first
    await loginAsAdmin(page);

    // Verify dashboard elements
    await expect(page.locator('.layout-wrapper')).toBeVisible();
  });

  test('should display sidebar navigation', async ({ page }) => {
    // Login first
    await loginAsAdmin(page);

    // Verify sidebar is visible
    await expect(page.locator('.layout-menu')).toBeVisible();
  });

  test('should display user info in navbar', async ({ page }) => {
    // Login first
    await loginAsAdmin(page);

    // Verify navbar is visible
    await expect(page.locator('.layout-navbar')).toBeVisible();
  });
});
