import { expect, test } from '@playwright/test';
import { loginAsAdmin } from './fixtures/auth';

// A1 smoke: prove globalSetup + webServer + fixtures + proxy all work.

test.describe('smoke', () => {
	test.describe('unauthenticated', () => {
		test.use({ storageState: { cookies: [], origins: [] } });

		test('root redirects to login and shows the form', async ({ page }) => {
			await page.goto('/admin/');
			await expect(page).toHaveURL(/\/admin\/login$/);
			await expect(page.getByLabel('Username')).toBeVisible();
			await expect(page.getByLabel('Password')).toBeVisible();
			await expect(page.getByRole('button', { name: /sign in/i })).toBeVisible();
		});

		test('valid credentials land on the apps page', async ({ page }) => {
			await loginAsAdmin(page);
			await expect(page.getByRole('link', { name: 'Apps' })).toBeVisible();
		});
	});

	test('admin storageState already lands on apps', async ({ page }) => {
		await page.goto('/admin/');
		await expect(page).toHaveURL(/\/admin\/apps$/);
	});
});
