import { expect, test } from "@playwright/test";

test("un parcours de trois etapes dont une question s execute", async ({
	page,
}) => {
	await page.goto("/");
	const host = page.locator("[data-circuy]");

	await expect(host.getByText("Bienvenue sur la plateforme")).toBeVisible({
		timeout: 10_000,
	});
	await host.getByRole("button", { name: "Suivant" }).click();

	await expect(host.getByText("Creez un projet")).toBeVisible();
	await page.getByTestId("create-project").click();

	await expect(host.getByText("Quelle est votre equipe ?")).toBeVisible();
	await host.getByRole("button", { name: "Technique" }).click();

	await expect(host.getByText("C'est tout")).toBeVisible();
	await host.getByRole("button", { name: "Suivant" }).click();
	await expect(host.locator(".bubble")).toHaveCount(0);
});

test("echap abandonne le parcours et restitue le focus hors de la bulle", async ({
	page,
}) => {
	await page.goto("/");
	const host = page.locator("[data-circuy]");
	await expect(host.getByRole("button", { name: "Fermer" })).toBeFocused({
		timeout: 10_000,
	});

	await page.keyboard.press("Escape");
	await expect(host.locator(".bubble")).toHaveCount(0);

	const focusInsideHost = await page.evaluate(() => {
		const root = document.querySelector("[data-circuy]")?.shadowRoot;
		return Boolean(root?.contains(document.activeElement));
	});
	expect(focusInsideHost).toBe(false);
});
