import { describe, it, expect, vi } from 'vitest';
import { render } from 'vitest-browser-svelte';
import StammbaumGenerationRail from './StammbaumGenerationRail.svelte';

const rows = [
	{ rank: 0, label: 0, centerY: 100 },
	{ rank: 1, label: 1, centerY: 300 },
	{ rank: 2, label: 3, centerY: 500 }
];

describe('StammbaumGenerationRail (#692)', () => {
	it('renders one labelled chip per generation row', async () => {
		render(StammbaumGenerationRail, { svg: null, rows, panZoom: { x: 0, y: 0, z: 1 } });

		await vi.waitFor(() => {
			const labels = Array.from(document.querySelectorAll('[role="text"]')).map((el) => ({
				aria: el.getAttribute('aria-label'),
				text: el.textContent?.trim()
			}));
			expect(labels).toEqual([
				{ aria: 'Generation 0', text: 'G0' },
				{ aria: 'Generation 1', text: 'G1' },
				{ aria: 'Generation 3', text: 'G3' }
			]);
		});
	});

	it('renders nothing when there are no labelled rows', async () => {
		render(StammbaumGenerationRail, { svg: null, rows: [], panZoom: { x: 0, y: 0, z: 1 } });
		await vi.waitFor(() => expect(document.querySelectorAll('[role="text"]')).toHaveLength(0));
	});
});
