import { test, expect, request } from '@playwright/test'; import { login, loginViaAPI, DEMO } from './helpers/auth'; test.describe('Authentication', () => { test('login page renders correctly', async ({ page }) => { await page.goto('/login'); await page.waitForLoadState('domcontentloaded'); await expect(page.locator('h1:has-text("FiberOps")')).toBeVisible(); await expect(page.locator('h2:has-text("Sign in")')).toBeVisible(); await expect(page.locator('input[type="email"]')).toBeVisible(); await expect(page.locator('input[type="password"]')).toBeVisible(); }); test('login with valid credentials redirects to dashboard', async ({ page }) => { await login(page); expect(page.url()).toContain('/dashboard'); }); test('login with wrong credentials returns 401', async () => { const ctx = await request.newContext({ baseURL: 'https://fiberops-api.juankibin.space' }); const resp = await ctx.post('/api/v1/auth/login', { data: { tenantSlug: DEMO.tenant, email: DEMO.email, password: 'wrongpassword' }, headers: { 'Content-Type': 'application/json', 'x-tenant-slug': DEMO.tenant }, }); await ctx.dispose(); expect(resp.status()).toBe(401); }); test('unauthenticated access redirects to login', async ({ page }) => { await page.goto('/login'); await page.evaluate(() => localStorage.clear()); await page.goto('/dashboard'); await page.waitForTimeout(3000); expect(page.url()).toContain('/login'); }); test('logout returns to login', async ({ page }) => { await login(page); const logoutBtn = page.locator('button:has-text("Logout"), a:has-text("Logout")').first(); await logoutBtn.click(); await page.waitForTimeout(3000); expect(page.url()).toContain('/login'); }); });