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

/**
 * Notifications Tests
 *
 * Tests the Notifications functionality including:
 * - Viewing all notifications (admin)
 * - Notification table columns
 *
 * Note: myNotifications page has a view bug that causes 500 error
 * (route generation issue with notifications.markAsRead)
 */

// Helper function to login as admin
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('Notifications', () => {
  test.beforeEach(async ({ page }) => {
    await loginAsAdmin(page);
  });

  test('should display all notifications page', async ({ page }) => {
    // Navigate to notifications page
    await page.goto('/notifications', { waitUntil: 'networkidle' });

    // Verify page elements
    await expect(page.locator('.card').first()).toBeVisible();
    await expect(page.locator('#datatable')).toBeVisible();
  });

  test('should display notification table columns', async ({ page }) => {
    await page.goto('/notifications', { waitUntil: 'networkidle' });

    // Verify table headers
    const tableHeader = page.locator('#datatable thead');
    await expect(tableHeader).toContainText('User');
    await expect(tableHeader).toContainText('Type');
    await expect(tableHeader).toContainText('Title');
    await expect(tableHeader).toContainText('Message');
    await expect(tableHeader).toContainText('Actions');
  });

  test('should have notification heading', async ({ page }) => {
    await page.goto('/notifications', { waitUntil: 'networkidle' });

    // Verify heading
    await expect(page.getByRole('heading', { name: 'Notifications' })).toBeVisible();
  });
});
