51 lines
2.5 KiB
JavaScript
51 lines
2.5 KiB
JavaScript
// Rôle : teste la synchronisation, la validation et l'annulation des éditions inline.
|
|
/* global window, document */
|
|
import { test, expect } from "@playwright/test";
|
|
import { fileURLToPath, URL } from "node:url";
|
|
|
|
const probeUrl = `/@fs/${fileURLToPath(new URL("./fixtures/inline-edit-probe.js", import.meta.url))}`;
|
|
|
|
for (const contentEditable of [false, true]) {
|
|
test(`inline ${contentEditable ? "contentEditable" : "input"} synchronizes and cancels under StrictMode`, async ({ page }) => {
|
|
const errors = [];
|
|
page.on("pageerror", (error) => errors.push(error.message));
|
|
await page.goto("/");
|
|
await page.evaluate(async ({ probeUrl, contentEditable }) => {
|
|
const { mountInlineEditProbe } = await import(probeUrl);
|
|
const element = document.createElement("div");
|
|
element.id = "inline-probe";
|
|
document.body.prepend(element);
|
|
window.inlineProbe = mountInlineEditProbe(element, contentEditable);
|
|
}, { probeUrl, contentEditable });
|
|
const editor = page.locator("#inline-probe").getByRole("textbox", { name: "Edit" });
|
|
const expectValue = (value) => contentEditable ? expect(editor).toHaveText(value) : expect(editor).toHaveValue(value);
|
|
await expectValue("Initial");
|
|
await editor.fill("Uncommitted");
|
|
await page.evaluate(() => window.inlineProbe.update("Initial"));
|
|
await expectValue("Uncommitted");
|
|
await editor.press("Escape");
|
|
await expectValue("Initial");
|
|
expect(await page.evaluate(() => window.inlineProbe.commits)).toEqual([]);
|
|
|
|
await page.evaluate(() => window.inlineProbe.update("Updated"));
|
|
await expectValue("Updated");
|
|
const sourceRenders = await page.evaluate(() => window.inlineProbe.renders.filter((entry) => entry.value === "Updated"));
|
|
expect(sourceRenders.length).toBeGreaterThan(0);
|
|
expect(sourceRenders.every((entry) => entry.draft === "Updated")).toBe(true);
|
|
|
|
await editor.fill(" Saved ");
|
|
await editor.press("Enter");
|
|
expect(await page.evaluate(() => window.inlineProbe.commits)).toEqual(["Saved"]);
|
|
await page.evaluate(() => window.inlineProbe.update("Saved"));
|
|
await expectValue("Saved");
|
|
await editor.fill("Discard");
|
|
await editor.press("Escape");
|
|
await expectValue("Saved");
|
|
expect(await page.evaluate(() => window.inlineProbe.commits)).toEqual(["Saved"]);
|
|
|
|
await page.evaluate(() => window.inlineProbe.update("Initial"));
|
|
await expectValue("Initial");
|
|
await page.evaluate(() => window.inlineProbe.unmount());
|
|
expect(errors).toEqual([]);
|
|
});
|
|
}
|