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

const demoCredentials = {
  username: process.env.DEMO_USERNAME ?? 'demo',
  password: process.env.DEMO_PASSWORD ?? 'railgame123',
};

test.describe('Authentication', () => {
  test('allows the demo user to sign in and view the network snapshot', async ({
    page,
  }: {
    page: Page;
  }) => {
    await page.goto('/');

    await expect(page.getByRole('heading', { name: 'Sign in' })).toBeVisible();

    await page.getByLabel('Username').fill(demoCredentials.username);
    await page.getByLabel('Password').fill(demoCredentials.password);
    await page.getByRole('button', { name: 'Sign in' }).click();

    await expect(page.getByRole('heading', { name: 'Network Snapshot' })).toBeVisible();
    await expect(page.getByRole('heading', { name: 'Stations' })).toBeVisible();
    await expect(page.getByRole('button', { name: 'Sign out' })).toBeVisible();
  });
});
