From 8aaa7706368e68de648d61660e16de74106cfbc4 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sun, 12 Apr 2026 19:12:24 -0500 Subject: [PATCH] refactor(tests): update test selectors --- tests/frontend/BotsPage.test.js | 6 ++-- tests/frontend/Interface.test.js | 10 +++--- tests/frontend/ToolsPage.test.js | 8 ++--- tests/frontend/UIThemeAndVisibility.test.js | 2 +- tests/frontend/VisualizerOptimization.test.js | 31 +++++++------------ 5 files changed, 26 insertions(+), 31 deletions(-) diff --git a/tests/frontend/BotsPage.test.js b/tests/frontend/BotsPage.test.js index 370cbe4..2013a0a 100644 --- a/tests/frontend/BotsPage.test.js +++ b/tests/frontend/BotsPage.test.js @@ -62,8 +62,10 @@ describe("BotsPage.vue", () => { const wrapper = mountBotsPage(); await vi.waitFor(() => expect(wrapper.vm.loading).toBe(false)); - const templateCard = wrapper.find(".glass-card[class*='cursor-pointer']"); - await templateCard.trigger("click"); + const selectBtn = wrapper + .findAll("button") + .find((b) => b.text().includes("bots.select")); + await selectBtn.trigger("click"); expect(wrapper.vm.selectedTemplate).not.toBeNull(); expect(wrapper.text()).toContain("bots.start_bot: Echo Bot"); diff --git a/tests/frontend/Interface.test.js b/tests/frontend/Interface.test.js index bf1d270..3ad56d9 100644 --- a/tests/frontend/Interface.test.js +++ b/tests/frontend/Interface.test.js @@ -37,14 +37,14 @@ describe("Interface.vue", () => { it("emits disable when Disable button is clicked", async () => { const wrapper = mountInterface(); - const disableBtn = wrapper.find("button.secondary-chip"); + const disableBtn = wrapper.find('button[title="interface.disable"]'); await disableBtn.trigger("click"); expect(wrapper.emitted("disable")).toHaveLength(1); }); it("emits enable when Enable button is clicked for disabled interface", async () => { const wrapper = mountInterface({ enabled: false }); - const enableBtn = wrapper.find("button.primary-chip"); + const enableBtn = wrapper.find('button[title="interface.enable"]'); await enableBtn.trigger("click"); expect(wrapper.emitted("enable")).toHaveLength(1); }); @@ -93,9 +93,11 @@ describe("Interface.vue", () => { it("action buttons and dropdown have shrink-0 to prevent squashing", () => { const wrapper = mountInterface(); - const actionsCol = wrapper.find(".flex.flex-col.sm\\:flex-row.gap-2"); + const actionsCol = wrapper.find( + ".absolute.top-2.right-2.z-20.flex.flex-row.items-center.gap-1.sm\\:static", + ); expect(actionsCol.classes()).toContain("sm:shrink-0"); - const btn = wrapper.find("button.secondary-chip"); + const btn = wrapper.find('button[title="interface.disable"]'); expect(btn.classes()).toContain("shrink-0"); }); diff --git a/tests/frontend/ToolsPage.test.js b/tests/frontend/ToolsPage.test.js index 6567cf8..af51ae5 100644 --- a/tests/frontend/ToolsPage.test.js +++ b/tests/frontend/ToolsPage.test.js @@ -21,6 +21,7 @@ describe("ToolsPage.vue", () => { { path: "/paper-message", name: "paper-message", component: { template: "div" } }, { path: "/rnode-flasher", name: "rnode-flasher", component: { template: "div" } }, { path: "/debug-logs", name: "debug-logs", component: { template: "div" } }, + { path: "/mesh-server", name: "mesh-server", component: { template: "div" } }, ], }); @@ -47,11 +48,10 @@ describe("ToolsPage.vue", () => { expect(wrapper.text()).toContain("tools.power_tools"); }); - it("renders all tool cards", () => { + it("renders all tool rows", () => { const wrapper = mountToolsPage(); - const toolCards = wrapper.findAll(".tool-card"); - // tools count in ToolsPage.vue is 17 (including coming soon ones) - expect(toolCards.length).toBe(17); + const toolRows = wrapper.findAll(".tool-row"); + expect(toolRows.length).toBe(17); }); it("filters tools based on search query", async () => { diff --git a/tests/frontend/UIThemeAndVisibility.test.js b/tests/frontend/UIThemeAndVisibility.test.js index f6013e2..50a3f47 100644 --- a/tests/frontend/UIThemeAndVisibility.test.js +++ b/tests/frontend/UIThemeAndVisibility.test.js @@ -485,7 +485,7 @@ describe("Visibility Checks", () => { await wrapper.vm.$nextTick(); const colorInputs = wrapper.findAll('input[type="color"]'); - expect(colorInputs.length).toBe(3); + expect(colorInputs.length).toBe(2); delete window.api; }); diff --git a/tests/frontend/VisualizerOptimization.test.js b/tests/frontend/VisualizerOptimization.test.js index a24ed26..0a0618f 100644 --- a/tests/frontend/VisualizerOptimization.test.js +++ b/tests/frontend/VisualizerOptimization.test.js @@ -245,7 +245,7 @@ describe("NetworkVisualiser Optimization and Abort", () => { expect(end - start).toBeLessThan(100); // Should be very fast }); - it("performance: icon cache hit vs miss for 500 nodes", async () => { + it("reuses one cached icon for 500 nodes with identical lxmf_user_icon", async () => { vi.spyOn(NetworkVisualiser.methods, "init").mockImplementation(() => {}); const wrapper = mountVisualiser(); @@ -266,30 +266,21 @@ describe("NetworkVisualiser Optimization and Abort", () => { return acc; }, {}); - // Mock createIconImage to have some delay for the "miss" case - wrapper.vm.createIconImage = vi.fn().mockImplementation(async () => { - // Add a tiny delay to ensure "miss" is always measurable + wrapper.vm.createIconImage = vi.fn(async function (iconName, foregroundColor, backgroundColor, size = 64) { + const cacheKey = `${iconName}-${foregroundColor}-${backgroundColor}-${size}`; + if (this.iconCache[cacheKey]) { + return this.iconCache[cacheKey]; + } await new Promise((r) => setTimeout(r, 0)); - return "blob:mock-icon"; + const url = "blob:mock-icon"; + this.iconCache[cacheKey] = url; + return url; }); - const startMiss = performance.now(); await wrapper.vm.processVisualization(); - const endMiss = performance.now(); - const missTime = endMiss - startMiss; + expect(wrapper.vm.createIconImage).toHaveBeenCalledTimes(1); - // Second run will hit the cache check in processVisualization - // so it won't even call createIconImage. - const startHit = performance.now(); await wrapper.vm.processVisualization(); - const endHit = performance.now(); - const hitTime = endHit - startHit; - - console.log(`Icon cache MISS for 500 nodes: ${missTime.toFixed(2)}ms`); - console.log(`Icon cache HIT for 500 nodes: ${hitTime.toFixed(2)}ms`); - - // Cache hit should be significantly faster, but we allow for some - // environmental noise in CI environments. - expect(hitTime).toBeLessThan(missTime + 200); + expect(wrapper.vm.createIconImage).toHaveBeenCalledTimes(1); }); });