|
|
|
@ -3,6 +3,7 @@ import { render, screen, fireEvent, waitFor } from "@testing-library/react"; |
|
|
|
import { MessagesPage } from "./Messages.tsx"; |
|
|
|
import { useDevice } from "../core/stores/deviceStore"; |
|
|
|
import { Protobuf } from "@meshtastic/core"; |
|
|
|
import { b } from "vitest/dist/chunks/suite.qtkXWc6R.js"; |
|
|
|
|
|
|
|
// Mock the store
|
|
|
|
vi.mock("../core/stores/deviceStore", () => ({ |
|
|
|
@ -20,7 +21,7 @@ const mockUseDevice = { |
|
|
|
nodes: new Map([ |
|
|
|
[1111, { |
|
|
|
num: 1111, |
|
|
|
user: { longName: "Test Node", shortName: "TN", publicKey: "12345" } |
|
|
|
user: { longName: "Test Node 1", shortName: "TN1", publicKey: "12345" } |
|
|
|
}], |
|
|
|
[2222, { |
|
|
|
num: 2222, |
|
|
|
@ -63,7 +64,7 @@ describe("Messages Page", () => { |
|
|
|
|
|
|
|
it("does not update the incorrect node",() => { |
|
|
|
render(<MessagesPage />); |
|
|
|
const nodeButton = screen.getByRole("button", { name: "TN Test Node 3" }); |
|
|
|
const nodeButton = screen.getAllByRole("button").filter(b => b.textContent.includes("TN1Test Node 13"))[0]; |
|
|
|
fireEvent.click(nodeButton); |
|
|
|
|
|
|
|
expect(mockUseDevice.setUnread).toHaveBeenCalledWith(1111, 0); |
|
|
|
@ -74,6 +75,9 @@ describe("Messages Page", () => { |
|
|
|
|
|
|
|
it("sorts unreads to the top", () => { |
|
|
|
const container = render(<MessagesPage />); |
|
|
|
const buttonOrder = screen.getAllByRole("button") |
|
|
|
const buttonOrder = screen.getAllByRole("button").filter(b => b.textContent.includes("Test Node")); |
|
|
|
expect(buttonOrder[0].textContent).toContain("TN2Test Node 210"); |
|
|
|
expect(buttonOrder[1].textContent).toContain("TN1Test Node 13"); |
|
|
|
expect(buttonOrder[2].textContent).toContain("TN3Test Node 3"); |
|
|
|
}); |
|
|
|
}); |