Browse Source

fix broken test

pull/497/head
Dan Ditomaso 1 year ago
committed by GitHub
parent
commit
818bbb4a30
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      src/pages/Messages.test.tsx

7
src/pages/Messages.test.tsx

@ -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);
}); });
}); });
Loading…
Cancel
Save