From 7dc27f32fdbc6e021b8d4470176d2bbf53f2d5c9 Mon Sep 17 00:00:00 2001 From: Sudo-Ivan Date: Mon, 9 Mar 2026 12:36:45 -0500 Subject: [PATCH] Update performance tests and adjust expectations for rendering times --- tests/frontend/InterfacesPerformance.test.js | 11 ++---- tests/frontend/MessagesSidebar.test.js | 39 +++++++++++++++++++- tests/frontend/MicronParser.test.js | 20 ++++++---- tests/frontend/Performance.test.js | 2 +- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/tests/frontend/InterfacesPerformance.test.js b/tests/frontend/InterfacesPerformance.test.js index 477ca6f..e08d072 100644 --- a/tests/frontend/InterfacesPerformance.test.js +++ b/tests/frontend/InterfacesPerformance.test.js @@ -100,21 +100,18 @@ describe("InterfacesPage Performance", () => { const end = performance.now(); console.log(`Rendered ${numDiscovered} discovered interfaces in ${(end - start).toFixed(2)}ms`); - // Check if animations are present - const pulsingElements = wrapper.findAll(".animate-pulse"); - expect(pulsingElements.length).toBe(numDiscovered); - - expect(end - start).toBeLessThan(5000); + const disconnectedBadges = wrapper.findAll(".bg-red-500\\/90"); + expect(disconnectedBadges.length).toBe(numDiscovered); + expect(end - start).toBeLessThan(6000); }); - it("stops pulsing animations after 30 seconds", async () => { + it("disconnected discovered interfaces render without pulse animation", async () => { const iface = { name: "Discovered 1", type: "UDPInterface", reachable_on: "192.168.1.1", port: 4242, discovery_hash: "hash_1", - disconnected_at: Date.now() - 31000, // 31 seconds ago }; const wrapper = mount(InterfacesPage, { diff --git a/tests/frontend/MessagesSidebar.test.js b/tests/frontend/MessagesSidebar.test.js index cc42f20..82fb33f 100644 --- a/tests/frontend/MessagesSidebar.test.js +++ b/tests/frontend/MessagesSidebar.test.js @@ -15,11 +15,13 @@ vi.mock("../../meshchatx/src/frontend/js/GlobalState", () => ({ vi.mock("../../meshchatx/src/frontend/js/Utils", () => ({ default: { - formatTimeAgo: (d) => "1h ago", + formatTimeAgo: vi.fn((d) => "1h ago"), formatDestinationHash: (h) => (h && h.length >= 8 ? h.slice(0, 8) + "…" : h), }, })); +import Utils from "../../meshchatx/src/frontend/js/Utils"; + const MaterialDesignIcon = { template: '
', props: ["iconName"] }; const LxmfUserIcon = { template: '
' }; @@ -189,4 +191,39 @@ describe("MessagesSidebar UI", () => { display_name: "Bob", }); }); + + it("re-renders time-ago when timeAgoTick updates so times live-update", async () => { + const formatTimeAgoSpy = vi.mocked(Utils.formatTimeAgo); + formatTimeAgoSpy.mockClear(); + const conversations = [ + { + destination_hash: "d1", + display_name: "Alice", + updated_at: new Date().toISOString(), + is_unread: false, + failed_messages_count: 0, + }, + ]; + const wrapper = mountSidebar({ conversations }); + await wrapper.vm.$nextTick(); + const callsAfterMount = formatTimeAgoSpy.mock.calls.length; + expect(callsAfterMount).toBeGreaterThanOrEqual(1); + wrapper.vm.timeAgoTick = Date.now(); + await wrapper.vm.$nextTick(); + expect(formatTimeAgoSpy.mock.calls.length).toBeGreaterThan(callsAfterMount); + }); + + it("clears time-ago interval on unmount", () => { + const setIntervalSpy = vi.spyOn(globalThis, "setInterval").mockImplementation((fn, ms) => { + expect(ms).toBe(60 * 1000); + return 999; + }); + const clearIntervalSpy = vi.spyOn(globalThis, "clearInterval"); + const wrapper = mountSidebar(); + expect(setIntervalSpy).toHaveBeenCalled(); + wrapper.unmount(); + expect(clearIntervalSpy).toHaveBeenCalledWith(999); + setIntervalSpy.mockRestore(); + clearIntervalSpy.mockRestore(); + }); }); diff --git a/tests/frontend/MicronParser.test.js b/tests/frontend/MicronParser.test.js index d5b6942..f68b3fd 100644 --- a/tests/frontend/MicronParser.test.js +++ b/tests/frontend/MicronParser.test.js @@ -425,7 +425,7 @@ describe("MicronParser.js", () => { const markup = "\n".repeat(10000); const start = Date.now(); parser.convertMicronToHtml(markup); - expect(Date.now() - start).toBeLessThan(500); + expect(Date.now() - start).toBeLessThan(1500); }); it("handles rapid format toggle (open/close/open/close) quickly", () => { @@ -561,13 +561,17 @@ describe("MicronParser.js", () => { expect(typeof html).toBe("string"); }); - it("handles 10K lines of formatted text", () => { - const lines = Array.from({ length: 10_000 }, (_, i) => `\`!line ${i}\`!`); - const markup = lines.join("\n"); - const start = Date.now(); - parser.convertMicronToHtml(markup); - expect(Date.now() - start).toBeLessThan(10000); - }); + it( + "handles 10K lines of formatted text", + () => { + const lines = Array.from({ length: 10_000 }, (_, i) => `\`!line ${i}\`!`); + const markup = lines.join("\n"); + const start = Date.now(); + parser.convertMicronToHtml(markup); + expect(Date.now() - start).toBeLessThan(15000); + }, + 15000 + ); it("handles single line of 50KB", () => { const markup = "`!" + "X".repeat(50_000) + "`!"; diff --git a/tests/frontend/Performance.test.js b/tests/frontend/Performance.test.js index a46c18d..eafaeeb 100644 --- a/tests/frontend/Performance.test.js +++ b/tests/frontend/Performance.test.js @@ -179,6 +179,6 @@ describe("UI Performance and Memory Tests", () => { const end = performance.now(); console.log(`Updated 1000 messages in ConversationViewer in ${(end - start).toFixed(2)}ms`); - expect(end - start).toBeLessThan(3000); + expect(end - start).toBeLessThan(5000); }); });