import { DataMocker } from '@mock-data/dataMocker.class'

import { setData } from 'support/set-data'

import { expect, test } from '../fixtures/test-fixtures'

// ------------------------------------------------------------
// 🧭 Visual Regression Test
// ------------------------------------------------------------
// Purpose: Capture a baseline screenshot of the homepage.
// Expectation: Screenshot is stored and compared against future changes.
// ------------------------------------------------------------
test('Navigate to homepage and take snapshot', async ({ page }) => {
  await page.goto('/')

  await expect(page).toHaveScreenshot()
})

// ------------------------------------------------------------
// 📊 Navigation Test — Dashboard Accessibility
// ------------------------------------------------------------
// Purpose: Ensure that the dashboard page can be accessed directly.
// Expectation: The browser navigates to /dashboard successfully.
// ------------------------------------------------------------
test('Dashboard page is accessible ', async ({ page }) => {
  await page.goto('/dashboard')

  await expect(page).toHaveURL(/.*\/dashboard$/)
})

// ------------------------------------------------------------
// 🙋‍♂️ Dashboard Content Test — User Greeting
// ------------------------------------------------------------
// Purpose: Verify that a logged-in user sees a personalized greeting.
// Expectation: The greeting text “Hi Test User!” is visible on the page.
// ------------------------------------------------------------
test('Dashboard displays user greeting message', async ({ page }) => {
  await page.goto('/dashboard')

  await expect(page.getByText('Hi Test User!')).toBeVisible()
})

// ------------------------------------------------------------
// 🌙 UI Theme Toggle Test
// ------------------------------------------------------------
// Purpose: Validate that the theme toggle switches to dark mode.
// Steps:
//   1. Navigate to /dashboard
//   2. Click the theme toggle button (data-test-id)
// Expectation: A toast confirms “As you may see now it's dark theme”.
// ------------------------------------------------------------
test('Theme toggle switches to dark mode successfully', async ({ page }) => {
  await page.goto('/dashboard')

  await page.getByTestId('button-toggle-theme').click()

  await expect(page.getByText("As you may see now it's dark theme")).toBeVisible()
})

/**
 * 🧪 Backend Data Reset Test
 *
 * This test demonstrates how to use the DataMocker class for backend data manipulation
 * in E2E tests. It shows the pattern for:
 * - Creating test data using DataMocker
 * - Sending data to the backend for test setup
 * - Ensuring clean state between test runs
 *
 * Keep this test for reference during further development.
 */
test.skip('Should reset data with data mocker', async () => {
  const data = new DataMocker()

  data.addUser({ id: 'user1' })

  await expect(setData(data)).resolves.not.toThrow()
})
