sokko-g/e2e/module-order.spec.js
Shinuwa 22b397ebfa Document Sokko G's architecture and folders, and move JavaScript file headers to JSDoc @file blocks
Add ARCHITECTURE.md (layers, flows, folder map, glossary), CONTRIBUTING.md
(setup and step-by-step recipes) and a README in each main folder, with an
index of docs/. Convert the 511 JavaScript headers from "// Rôle :" lines to
JSDoc @file blocks, define a three-level header template in website/AGENTS.md
and check the header in tests/file-headers.test.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 09:42:13 +01:00

81 lines
4.2 KiB
JavaScript

/**
* @file Vérifie les ordres indépendants une/deux colonnes et leur persistance après déplacement réel.
*/
import { test, expect } from "@playwright/test";
import { movePointerTo, startPointerDrag } from "./helpers/pointer.js";
import { resetSokkoStorage } from "./helpers/storage.js";
async function setup(page, columns) {
await resetSokkoStorage(page);
await page.evaluate(async (columns) => {
const db = await import("/src/utils/indexedDbStorage.js");
await db.setToolboxSnapshot([{
id: "order", name: "Ordering", moduleColumns: columns,
modules: ["a", "b", "c", "d"].map((id) => ({ id, type: "counters", title: id.toUpperCase() })),
moduleOrder: { one: ["a", "b", "c", "d"], two: [["a", "b"], ["c", "d"]] }
}], {}, {});
}, columns);
await page.goto("/#/toolbox/order");
await page.reload();
await expect(page.locator("article.module")).toHaveCount(4);
}
async function savedOrder(page) {
return page.evaluate(async () => {
const db = await import("/src/utils/indexedDbStorage.js");
return (await db.getToolboxes())[0].spaces[0].moduleOrder;
});
}
async function drag(page, title, target, after = false) {
const handle = page.getByRole("button", { name: `Déplacer ${title}`, exact: true });
await startPointerDrag(page, handle);
await expect(page.locator("article.module.is-dragging")).toHaveCount(1);
await movePointerTo(page, target, { y: after ? 0.8 : 0.2 });
await page.mouse.up();
await expect(page.locator("article.module.is-dragging")).toHaveCount(0);
}
test("one-column ordering survives reload without changing the two-column order", async ({ page }) => {
await setup(page, 1);
await drag(page, "C", page.locator('article[data-reorder-item-id="a"]'));
const expected = { one: ["c", "a", "b", "d"], two: [["a", "b"], ["c", "d"]] };
await expect.poll(() => savedOrder(page)).toEqual(expected);
await page.reload();
await expect(page.locator(".module-title")).toHaveText(["C", "A", "B", "D"]);
await page.getByRole("button", { name: "Afficher en colonnes", exact: true }).click();
await expect(page.locator(".module-column").first().locator(".module-title")).toHaveText(["A", "B"]);
await expect(page.locator(".module-column").last().locator(".module-title")).toHaveText(["C", "D"]);
});
test("cross-column drops and empty column boundaries preserve every module and the one-column order", async ({ page }) => {
await setup(page, 2);
const columns = page.locator(".module-column");
await drag(page, "A", page.locator('article[data-reorder-item-id="d"]'), true);
await expect.poll(() => savedOrder(page)).toEqual({ one: ["a", "b", "c", "d"], two: [["b"], ["c", "d", "a"]] });
await drag(page, "B", columns.last().locator(".module-column-boundary-drop-zone").last(), true);
await expect.poll(() => savedOrder(page)).toEqual({ one: ["a", "b", "c", "d"], two: [[], ["c", "d", "a", "b"]] });
await drag(page, "A", columns.first().locator(".module-column-boundary-drop-zone").first());
const expected = { one: ["a", "b", "c", "d"], two: [["a"], ["c", "d", "b"]] };
await expect.poll(() => savedOrder(page)).toEqual(expected);
await page.reload();
await expect(columns.first().locator(".module-title")).toHaveText(["A"]);
await expect(columns.last().locator(".module-title")).toHaveText(["C", "D", "B"]);
await page.getByRole("button", { name: "Afficher en lignes", exact: true }).click();
await expect(page.locator(".module-title")).toHaveText(["A", "B", "C", "D"]);
});
test("adding an off-screen tool scrolls it into view", async ({ page }) => {
await page.setViewportSize({ width: 900, height: 420 });
await setup(page, 1);
await page.getByRole("button", { name: "Afficher l'ajout rapide", exact: true }).click();
await page.getByRole("button", { name: "Ajouter Compteurs", exact: true }).click();
const added = page.locator('article[data-module-type="counters"]').last();
await expect(page.locator("article.module")).toHaveCount(5);
await expect.poll(async () => added.evaluate((element) => {
const rect = element.getBoundingClientRect();
return rect.top >= 0 && rect.top < globalThis.window.innerHeight && rect.bottom > 0;
})).toBe(true);
expect(await page.evaluate(() => globalThis.window.scrollY)).toBeGreaterThan(0);
});