// Rôle : couvre les remplacements de données et les onglets invalides du Goal Tree sous StrictMode. /* global window, document */ import { test, expect } from "@playwright/test"; import { fileURLToPath, URL } from "node:url"; const probeUrl = `/@fs/${fileURLToPath(new URL("./fixtures/goal-selection-probe.js", import.meta.url))}`; test("goal selection remains valid through kind changes and data replacement", async ({ page }) => { const errors = []; page.on("pageerror", (error) => errors.push(error.message)); await page.goto("/"); await page.evaluate(async (url) => { const { mountGoalSelectionProbe } = await import(url); const element = document.createElement("div"); document.body.prepend(element); window.goalProbe = mountGoalSelectionProbe(element); }, probeUrl); const first = { id: "first", title: "First", kind: "checklist" }; const second = { id: "second", title: "Second", kind: "checklist" }; async function updateAndCheck(nodes, selected, tab) { const snapshots = await page.evaluate((nodes) => { window.goalProbe.update(nodes); return window.goalProbe.snapshots; }, nodes); expect(snapshots.length).toBeGreaterThan(0); for (const snapshot of snapshots) { expect(snapshot.selected).toBe(selected); expect(snapshot.tab).toBe(tab); expect(snapshot.tabs).toContain(snapshot.tab); } } await updateAndCheck([first, second], "first", "base"); await page.evaluate(() => window.goalProbe.edit("second")); expect(await page.evaluate(() => window.goalProbe.snapshots.at(-1).tab)).toBe("content"); await updateAndCheck([first, { ...second, kind: "step" }], "second", "base"); await updateAndCheck([first], "first", "base"); await updateAndCheck([first, second], "first", "base"); await updateAndCheck([], "", "base"); await updateAndCheck([second], "second", "base"); await page.evaluate(() => window.goalProbe.unmount()); expect(errors).toEqual([]); });