Audit the project and secure toolbox data

This commit is contained in:
Shinuwa 2026-10-14 16:59:09 +02:00
parent 96af62edf0
commit e87edda5c7
40 changed files with 2324 additions and 125 deletions

View file

@ -1,15 +1,26 @@
// Rôle : couvre les parcours persistants des liens, compteurs, checklists et galeries d'images.
import { expect, test } from "@playwright/test";
import { Buffer } from "node:buffer";
import { createToolboxImportPayload } from "./helpers/toolboxImport.js";
async function firstStoredModuleData(page) {
return page.evaluate(async () => {
const db = await import("/src/utils/indexedDbStorage.js");
const snapshot = await db.getToolboxSnapshot();
return Object.values(snapshot.moduleData)[0] || null;
});
}
async function setup(page, type, data) {
await page.goto("/#/toolboxes");
await page.getByText("Importer une toolbox", { exact: true }).locator('input[type="file"]').setInputFiles({
name: "basic.json", mimeType: "application/json",
buffer: Buffer.from(JSON.stringify({
toolbox: { id: "basic", name: "Basic workflows", modules: [{ id: "tool", type, title: "Tool" }] },
modules: { tool: data },
})),
buffer: Buffer.from(JSON.stringify(createToolboxImportPayload({
id: "basic",
name: "Basic workflows",
modules: [{ id: "tool", type, title: "Tool" }],
moduleData: { tool: data },
}))),
});
await page.getByRole("link", { name: "Ouvrir Basic workflows", exact: true }).first().click();
const tool = page.locator(`[data-module-type="${type}"]`);
@ -69,19 +80,16 @@ test("empty collection tools explain that they have no content", async ({ page }
await page.getByText("Importer une toolbox", { exact: true }).locator('input[type="file"]').setInputFiles({
name: "empty-tools.json",
mimeType: "application/json",
buffer: Buffer.from(JSON.stringify({
toolbox: {
id: "empty-tools",
name: "Empty tools",
modules: [
buffer: Buffer.from(JSON.stringify(createToolboxImportPayload({
id: "empty-tools",
name: "Empty tools",
modules: [
{ id: "checklist", type: "checklist", title: "Checklist" },
{ id: "images", type: "images", title: "Images" },
{ id: "links", type: "links", title: "Links" },
{ id: "counters", type: "counters", title: "Counters" }
]
},
modules: {}
}))
]
})))
});
await page.getByRole("link", { name: "Ouvrir Empty tools", exact: true }).first().click();
await expect(page.getByText("Aucun élément dans cette checklist.", { exact: true })).toBeVisible();
@ -103,6 +111,7 @@ test("checklist quantities are clamped and completed categories hide without los
await expect(quantity).toHaveValue("3");
await tool.getByRole("radio", { name: "Cachée quand terminée", exact: true }).click();
await expect(quantity).toHaveCount(0);
await expect.poll(async () => (await firstStoredModuleData(page))?.hideCompletedSectionsFully).toBe(true);
await page.reload();
await expect(tool.getByRole("radio", { name: "Cachée quand terminée", exact: true })).toHaveAttribute("aria-checked", "true");
await tool.getByRole("radio", { name: "Visible quand terminée", exact: true }).click();
@ -111,14 +120,17 @@ test("checklist quantities are clamped and completed categories hide without los
await hideCompleted.click();
await expect(hideCompleted).toHaveAttribute("aria-pressed", "true");
await expect(quantity).toHaveCount(0);
await expect.poll(async () => (await firstStoredModuleData(page))?.hideCompletedItems).toBe(true);
await page.reload();
await expect(hideCompleted).toHaveAttribute("aria-pressed", "true");
await hideCompleted.click();
await expect(quantity).toHaveValue("3");
await tool.getByRole("button", { name: "Retirer une quantité", exact: true }).click();
await expect.poll(async () => (await firstStoredModuleData(page))?.sections?.[0]?.items?.[0]?.qtyCurrent).toBe(2);
await page.reload();
await expect(quantity).toHaveValue("2");
await tool.getByRole("button", { name: "Supprimer Ore", exact: true }).click();
await expect.poll(async () => Boolean((await firstStoredModuleData(page))?.sections?.length)).toBe(false);
await page.reload();
await expect(quantity).toHaveCount(0);
});