Cache mapping status on reload

This commit is contained in:
2026-08-05 22:57:06 +02:00
parent 9b1898a588
commit e3caf25823
4 changed files with 143 additions and 12 deletions
+46
View File
@@ -33,6 +33,52 @@ test("manufacturer picker shows ten results and supports search", async ({ page
await expect(page.locator("#manufacturerOptions .manufacturer-option")).toHaveText(["La Sportiva"]);
});
test("mapping uses cache on reload and reloads from DB on manual manufacturer change", async ({ page }) => {
let mappingRequests = 0;
await page.route("**/api/catalog-maker/mapping-sources**", async (route) => {
mappingRequests += 1;
await route.fulfill({
contentType: "application/json",
body: JSON.stringify({
mapped: true,
items: [{ key: "hudy", name: "Hudy", enabled: true }],
}),
});
});
await page.addInitScript(() => {
localStorage.setItem("catalog-maker:selected-manufacturer", "13");
localStorage.setItem(
"catalog-maker:mapping-cache",
JSON.stringify({
13: {
mapped: true,
items: [{ key: "cached-hudy", name: "Cached Hudy", enabled: true }],
},
}),
);
});
await page.goto("/");
await page.waitForFunction(() => document.querySelector("#manufacturerSelect")?.value === "13");
await expect(page.locator("#mappingStatusText")).toContainText("Mapping OK");
await page.waitForTimeout(300);
expect(mappingRequests).toBe(0);
await page.locator("#manufacturerSelect").evaluate((select) => {
const nextOption = [...select.options].find((option) => option.value && option.value !== "13");
select.value = nextOption?.value || "";
select.dispatchEvent(new Event("change", { bubbles: true }));
});
await expect.poll(() => mappingRequests).toBe(1);
await page.locator("#manufacturerSelect").evaluate((select) => {
select.value = "13";
select.dispatchEvent(new Event("change", { bubbles: true }));
});
await expect.poll(() => mappingRequests).toBe(2);
});
test("catalog maker remains usable on a narrow viewport", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await page.goto("/");