fix broken test

This commit is contained in:
Dan Ditomaso
2025-04-05 08:39:27 -04:00
committed by GitHub
parent 4755c0eeb9
commit 818bbb4a30
+3 -4
View File
@@ -4,7 +4,6 @@ import { MessagesPage } from "./Messages.tsx";
import { useDevice } from "../core/stores/deviceStore"; import { useDevice } from "../core/stores/deviceStore";
import { Protobuf } from "@meshtastic/core"; import { Protobuf } from "@meshtastic/core";
// Mock the store
vi.mock("../core/stores/deviceStore", () => ({ vi.mock("../core/stores/deviceStore", () => ({
useDevice: vi.fn() useDevice: vi.fn()
})); }));
@@ -39,7 +38,7 @@ const mockUseDevice = {
messages: { broadcast: new Map(), direct: new Map() }, messages: { broadcast: new Map(), direct: new Map() },
metadata: new Map(), metadata: new Map(),
unreadCounts: new Map([[1111, 3], [2222, 10]]), unreadCounts: new Map([[1111, 3], [2222, 10]]),
setUnread: vi.fn(), resetUnread: vi.fn(),
hasNodeError: vi.fn() hasNodeError: vi.fn()
}; };
@@ -62,14 +61,14 @@ describe("Messages Page", () => {
render(<MessagesPage />); render(<MessagesPage />);
const nodeButton = screen.getAllByRole("button").filter(b => b.textContent.includes("TN1Test Node 13"))[0]; const nodeButton = screen.getAllByRole("button").filter(b => b.textContent.includes("TN1Test Node 13"))[0];
fireEvent.click(nodeButton); fireEvent.click(nodeButton);
expect(mockUseDevice.setUnread).toHaveBeenCalledWith(1111, 0); expect(mockUseDevice.resetUnread).toHaveBeenCalledWith(1111, 0);
}); });
it("does not update the incorrect node", async () => { it("does not update the incorrect node", async () => {
render(<MessagesPage />); render(<MessagesPage />);
const nodeButton = screen.getAllByRole("button").filter(b => b.textContent.includes("TN1Test Node 1"))[0]; const nodeButton = screen.getAllByRole("button").filter(b => b.textContent.includes("TN1Test Node 1"))[0];
fireEvent.click(nodeButton); fireEvent.click(nodeButton);
expect(mockUseDevice.setUnread).toHaveBeenCalledWith(1111, 0); expect(mockUseDevice.resetUnread).toHaveBeenCalledWith(1111, 0);
expect(mockUseDevice.unreadCounts.get(2222)).toBe(10); expect(mockUseDevice.unreadCounts.get(2222)).toBe(10);
}); });
}); });