Update performance tests and adjust expectations for rendering times

This commit is contained in:
Sudo-Ivan
2026-03-09 12:36:45 -05:00
parent 247502e6ca
commit 7dc27f32fd
4 changed files with 55 additions and 17 deletions

View File

@@ -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, {

View File

@@ -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: '<div class="mdi"></div>', props: ["iconName"] };
const LxmfUserIcon = { template: '<div class="lxmf-icon"></div>' };
@@ -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();
});
});

View File

@@ -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) + "`!";

View File

@@ -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);
});
});