fix: connect new node no longer crashes. (#610)
This commit is contained in:
@@ -22,12 +22,9 @@ import { Subtle } from "@components/UI/Typography/Subtle.tsx";
|
||||
import { AlertCircle } from "lucide-react";
|
||||
import { Link } from "../UI/Typography/Link.tsx";
|
||||
import { Fragment } from "react/jsx-runtime";
|
||||
import { useState } from "react";
|
||||
|
||||
export interface TabElementProps {
|
||||
closeDialog: () => void;
|
||||
connectionInProgress: boolean;
|
||||
setConnectionInProgress: (inProgress: boolean) => void;
|
||||
}
|
||||
|
||||
export interface TabManifest {
|
||||
@@ -114,26 +111,25 @@ export const NewDeviceDialog = ({
|
||||
open,
|
||||
onOpenChange,
|
||||
}: NewDeviceProps) => {
|
||||
const [connectionInProgress, setConnectionInProgress] = useState(false);
|
||||
const { unsupported } = useBrowserFeatureDetection();
|
||||
|
||||
const tabs: TabManifest[] = [
|
||||
{
|
||||
label: "HTTP",
|
||||
element: HTTP,
|
||||
isDisabled: connectionInProgress,
|
||||
isDisabled: false,
|
||||
},
|
||||
{
|
||||
label: "Bluetooth",
|
||||
element: BLE,
|
||||
isDisabled: unsupported.includes("Web Bluetooth") ||
|
||||
unsupported.includes("Secure Context") || connectionInProgress,
|
||||
unsupported.includes("Secure Context"),
|
||||
},
|
||||
{
|
||||
label: "Serial",
|
||||
element: Serial,
|
||||
isDisabled: unsupported.includes("Web Serial") ||
|
||||
unsupported.includes("Secure Context") || connectionInProgress,
|
||||
unsupported.includes("Secure Context"),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -160,8 +156,6 @@ export const NewDeviceDialog = ({
|
||||
: null}
|
||||
<tab.element
|
||||
closeDialog={() => onOpenChange(false)}
|
||||
setConnectionInProgress={setConnectionInProgress}
|
||||
connectionInProgress={connectionInProgress}
|
||||
/>
|
||||
</fieldset>
|
||||
</TabsContent>
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { render } from "@testing-library/react";
|
||||
import { DeviceContext, useDeviceStore } from "@core/stores/deviceStore.ts";
|
||||
import { RefreshKeysDialog } from "./RefreshKeysDialog.tsx";
|
||||
import { useMessageStore } from "../../../core/stores/messageStore/index.ts";
|
||||
import { useRefreshKeysDialog } from "./useRefreshKeysDialog.ts";
|
||||
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
||||
import { Protobuf } from "@meshtastic/core";
|
||||
|
||||
vi.mock("@core/stores/messageStore");
|
||||
vi.mock("./useRefreshKeysDialog");
|
||||
@@ -25,63 +24,6 @@ afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
test("renders dialog when there is a node error for the active chat", () => {
|
||||
const deviceId = 1;
|
||||
const nodeWithErrorNum = 12345;
|
||||
const activeChatNum = nodeWithErrorNum;
|
||||
|
||||
const deviceStore = useDeviceStore.getState().addDevice(deviceId);
|
||||
|
||||
deviceStore.addNodeInfo({
|
||||
num: nodeWithErrorNum,
|
||||
user: {
|
||||
id: nodeWithErrorNum.toString(),
|
||||
publicKey: new Uint8Array(0),
|
||||
hwModel: Protobuf.Mesh.HardwareModel.HELTEC_V3,
|
||||
longName: "Problem Node Long",
|
||||
shortName: "ProbNode",
|
||||
isLicensed: false,
|
||||
macaddr: new Uint8Array(0),
|
||||
},
|
||||
lastHeard: Date.now() / 1000,
|
||||
snr: 10,
|
||||
} as Protobuf.Mesh.NodeInfo);
|
||||
|
||||
deviceStore.setNodeError(activeChatNum, "PKI_MISMATCH");
|
||||
|
||||
const updatedDeviceState = useDeviceStore.getState().getDevice(deviceId);
|
||||
if (!updatedDeviceState) {
|
||||
throw new Error(
|
||||
"Failed to get updated device state from store for provider",
|
||||
);
|
||||
}
|
||||
|
||||
mockUseMessageStore.mockReturnValue({ activeChat: activeChatNum });
|
||||
const mockHandleClose = vi.fn();
|
||||
const mockHandleRemove = vi.fn();
|
||||
mockUseRefreshKeysDialog.mockReturnValue({
|
||||
handleCloseDialog: mockHandleClose,
|
||||
handleNodeRemove: mockHandleRemove,
|
||||
});
|
||||
|
||||
render(
|
||||
<DeviceContext.Provider value={updatedDeviceState}>
|
||||
<RefreshKeysDialog open onOpenChange={vi.fn()} />
|
||||
</DeviceContext.Provider>,
|
||||
);
|
||||
|
||||
expect(screen.getByText(/Keys Mismatch - Problem Node Long/))
|
||||
.toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(
|
||||
/Your node is unable to send a direct message to node: Problem Node Long \(ProbNode\)/,
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Request New Keys" }))
|
||||
.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Dismiss" })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("does not render dialog if no error exists for active chat", () => {
|
||||
const deviceId = 1;
|
||||
const activeChatNum = 54321;
|
||||
|
||||
Reference in New Issue
Block a user