import { afterEach, describe, it, expect } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import Page from './+page.svelte';

afterEach(cleanup);

describe('[personId] page', () => {
	it('shows person name from personNames map', async () => {
		const personId = '123e4567-e89b-12d3-a456-426614174000';
		render(Page, {
			data: {
				personId,
				history: {
					runs: [],
					personNames: { [personId]: 'Anna Müller' }
				}
			}
		});
		await expect.element(page.getByRole('heading', { level: 1 })).toHaveTextContent('Anna Müller');
	});

	it('falls back to Unknown when person name is missing', async () => {
		const personId = '123e4567-e89b-12d3-a456-426614174000';
		render(Page, {
			data: {
				personId,
				history: {
					runs: [],
					personNames: {}
				}
			}
		});
		await expect.element(page.getByRole('heading', { level: 1 })).toHaveTextContent('Unknown');
	});
});
