Add library tools to local toolboxes
This commit is contained in:
parent
daa5eba8bd
commit
ec7a4a4c1d
15 changed files with 650 additions and 9 deletions
|
|
@ -2,6 +2,25 @@
|
|||
/* global window, document */
|
||||
import { test, expect } from "@playwright/test";
|
||||
import { LIBRARY_CATEGORY_DEFINITIONS } from "../website/src/features/toolboxes/toolboxModuleRegistry.js";
|
||||
import { resetSokkoStorage } from "./helpers/storage.js";
|
||||
|
||||
async function readStoredLibraryCopy(page) {
|
||||
return page.evaluate(async () => new Promise((resolve, reject) => {
|
||||
const request = window.indexedDB.open("sokkog", 1);
|
||||
request.onerror = () => reject(request.error);
|
||||
request.onsuccess = () => {
|
||||
const db = request.result;
|
||||
const transaction = db.transaction(["kv", "modules"], "readonly");
|
||||
const toolboxesRequest = transaction.objectStore("kv").get("toolboxes");
|
||||
const modulesRequest = transaction.objectStore("modules").getAll();
|
||||
transaction.oncomplete = () => {
|
||||
db.close();
|
||||
resolve({ toolboxes: toolboxesRequest.result || [], modules: modulesRequest.result || [] });
|
||||
};
|
||||
transaction.onerror = () => reject(transaction.error);
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
test("loads every library tool through the shared component registry", async ({ page }) => {
|
||||
const errors = [];
|
||||
|
|
@ -74,3 +93,43 @@ test("library cancels obsolete scroll retries on selection and unmount", async (
|
|||
await page.clock.runFor(700);
|
||||
expect(await page.evaluate(() => window.libraryScrolls)).toEqual([]);
|
||||
});
|
||||
|
||||
test("creates a first toolbox and persists the currently presented library example", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 768, height: 720 });
|
||||
await resetSokkoStorage(page);
|
||||
await page.goto("/#/library#library-tool-m5");
|
||||
const example = page.locator('[data-module-type="counters"]');
|
||||
await expect(example).toBeVisible();
|
||||
await example.getByRole("button", { name: "Incrémenter Top 1", exact: true }).click();
|
||||
await expect(example.locator(".counter-item").filter({ hasText: "Top 1" }).locator("strong")).toHaveText("4");
|
||||
|
||||
const section = page.locator("#library-tool-m5");
|
||||
await section.getByRole("button", { name: "Ajouter à une toolbox", exact: true }).click();
|
||||
let dialog = page.getByRole("dialog", { name: "Ajouter Compteurs", exact: true });
|
||||
await expect(dialog.getByText("Copier l’état actuellement présenté", { exact: true })).toBeVisible();
|
||||
expect(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth)).toBe(true);
|
||||
await dialog.getByRole("button", { name: "Annuler", exact: true }).click();
|
||||
await expect(dialog).toHaveCount(0);
|
||||
expect((await readStoredLibraryCopy(page)).toolboxes).toHaveLength(0);
|
||||
|
||||
await section.getByRole("button", { name: "Ajouter à une toolbox", exact: true }).click();
|
||||
dialog = page.getByRole("dialog", { name: "Ajouter Compteurs", exact: true });
|
||||
await dialog.getByRole("textbox", { name: /Nom de la nouvelle toolbox/ }).fill("Depuis la librairie");
|
||||
await dialog.getByRole("button", { name: "Créer et ajouter", exact: true }).click();
|
||||
await expect(page.getByText("Outil ajouté dans « Depuis la librairie ».", { exact: true })).toBeVisible();
|
||||
|
||||
await expect.poll(async () => (await readStoredLibraryCopy(page)).toolboxes.length).toBe(1);
|
||||
const stored = await readStoredLibraryCopy(page);
|
||||
const copiedModule = stored.toolboxes[0].modules.find((module) => module.type === "counters");
|
||||
const copiedData = stored.modules.find((entry) => entry.key === `${stored.toolboxes[0].id}:${copiedModule.id}`).data;
|
||||
expect(copiedModule.id).not.toBe("m5");
|
||||
expect(copiedData.counters.find((counter) => counter.label === "Top 1").value).toBe(4);
|
||||
expect(copiedData.counters.find((counter) => counter.label === "Top 1").id).not.toBe("c1");
|
||||
|
||||
await page.getByRole("button", { name: "Ouvrir", exact: true }).click();
|
||||
await expect(page).toHaveURL(new RegExp(`#\\/toolbox\\/${stored.toolboxes[0].id}$`));
|
||||
const copiedTool = page.locator(`[data-module-id="${copiedModule.id}"]`);
|
||||
await expect(copiedTool.locator(".counter-item").filter({ hasText: "Top 1" }).locator("strong")).toHaveText("4");
|
||||
await page.reload();
|
||||
await expect(copiedTool.locator(".counter-item").filter({ hasText: "Top 1" }).locator("strong")).toHaveText("4");
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue