@ -5,7 +5,13 @@ import { TransportHTTP } from "@meshtastic/transport-http";
import { describe , expect , it , vi } from "vitest" ;
import { describe , expect , it , vi } from "vitest" ;
vi . mock ( "@core/stores/appStore.ts" , ( ) = > ( {
vi . mock ( "@core/stores/appStore.ts" , ( ) = > ( {
useAppStore : vi.fn ( ( ) = > ( { setSelectedDevice : vi.fn ( ) } ) ) ,
useAppStore : vi.fn ( ( ) = > ( {
setSelectedDevice : vi.fn ( ) ,
addSavedServer : vi.fn ( ) ,
removeSavedServer : vi.fn ( ) ,
clearSavedServers : vi.fn ( ) ,
getSavedServers : vi.fn ( ( ) = > [ ] ) ,
} ) ) ,
} ) ) ;
} ) ) ;
vi . mock ( "@core/stores/deviceStore.ts" , ( ) = > ( {
vi . mock ( "@core/stores/deviceStore.ts" , ( ) = > ( {
@ -14,10 +20,18 @@ vi.mock("@core/stores/deviceStore.ts", () => ({
} ) ) ,
} ) ) ,
} ) ) ;
} ) ) ;
vi . mock ( "@core/stores/messageStore/index.ts" , ( ) = > ( {
useMessageStore : vi.fn ( ( ) = > ( { } ) ) ,
} ) ) ;
vi . mock ( "@core/utils/randId.ts" , ( ) = > ( {
vi . mock ( "@core/utils/randId.ts" , ( ) = > ( {
randId : vi.fn ( ( ) = > "mock-id" ) ,
randId : vi.fn ( ( ) = > "mock-id" ) ,
} ) ) ;
} ) ) ;
vi . mock ( "@core/subscriptions.ts" , ( ) = > ( {
subscribeAll : vi.fn ( ) ,
} ) ) ;
vi . mock ( "@meshtastic/transport-http" , ( ) = > ( {
vi . mock ( "@meshtastic/transport-http" , ( ) = > ( {
TransportHTTP : {
TransportHTTP : {
create : vi.fn ( ( ) = > Promise . resolve ( { } ) ) ,
create : vi.fn ( ( ) = > Promise . resolve ( { } ) ) ,
@ -33,34 +47,35 @@ vi.mock("@meshtastic/core", () => ({
describe ( "HTTP Component" , ( ) = > {
describe ( "HTTP Component" , ( ) = > {
it ( "renders correctly" , ( ) = > {
it ( "renders correctly" , ( ) = > {
render ( < Http closeDialog = { vi . fn ( ) } / > ) ;
render ( < Http closeDialog = { vi . fn ( ) } / > ) ;
expect ( screen . getByText ( "IP Address/Hostname" ) ) . toBeInTheDocument ( ) ;
expect ( screen . getByText ( "Meshtastic Servers" ) ) . toBeInTheDocument ( ) ;
expect ( screen . getByRole ( "textbox" ) ) . toBeInTheDocument ( ) ;
expect ( screen . getByText ( "Add New Server" ) ) . toBeInTheDocument ( ) ;
expect ( screen . getByPlaceholderText ( "000.000.000.000 / meshtastic.local" ) )
expect ( screen . getByText ( "No saved servers yet" ) ) . toBeInTheDocument ( ) ;
. toBeInTheDocument ( ) ;
expect ( screen . getByText ( "Use HTTPS" ) ) . toBeInTheDocument ( ) ;
expect ( screen . getByRole ( "button" , { name : "Connect" } ) ) . toBeInTheDocument ( ) ;
} ) ;
} ) ;
it ( "allows input field to be updat ed" , ( ) = > {
it ( "opens dialog when add new server is clicked" , ( ) = > {
render ( < Http closeDialog = { vi . fn ( ) } / > ) ;
render ( < Http closeDialog = { vi . fn ( ) } / > ) ;
const inputField = screen . getByRole ( "textbox" ) ;
const addButton = screen . getByText ( "Add New Server" ) ;
fireEvent . change ( inputField , { target : { value : "meshtastic.local" } } ) ;
fireEvent . click ( addButton ) ;
expect ( screen . getByPlaceholderText ( "000.000.000.000 / meshtastic.local" ) )
expect ( screen . getByText ( "Hostname or IP Address" ) ) . toBeInTheDocument ( ) ;
expect ( screen . getByPlaceholderText ( "meshtastic.local or 192.168.1.100" ) )
. toBeInTheDocument ( ) ;
. toBeInTheDocument ( ) ;
} ) ;
} ) ;
it ( "toggles HTTPS switch and updates prefix " , ( ) = > {
it ( "toggles HTTPS switch in dialog " , ( ) = > {
render ( < Http closeDialog = { vi . fn ( ) } / > ) ;
render ( < Http closeDialog = { vi . fn ( ) } / > ) ;
// Open the dialog first
const addButton = screen . getByText ( "Add New Server" ) ;
fireEvent . click ( addButton ) ;
const switchInput = screen . getByRole ( "switch" ) ;
const switchInput = screen . getByRole ( "switch" ) ;
expect ( screen . getByText ( "http://" ) ) . toBeInTheDocument ( ) ;
expect ( screen . getByText ( "Use HTTPS (Secure) " ) ) . toBeInTheDocument ( ) ;
fireEvent . click ( switchInput ) ;
fireEvent . click ( switchInput ) ;
expect ( screen . getByText ( "https://" ) ) . toBeInTheDocument ( ) ;
expect ( switchInput ) . toBeChecked ( ) ;
fireEvent . click ( switchInput ) ;
fireEvent . click ( switchInput ) ;
expect ( switchInput ) . not . toBeChecked ( ) ;
expect ( switchInput ) . not . toBeChecked ( ) ;
expect ( screen . getByText ( "http://" ) ) . toBeInTheDocument ( ) ;
} ) ;
} ) ;
it ( "enables HTTPS toggle when location protocol is https" , ( ) = > {
it ( "enables HTTPS toggle when location protocol is https" , ( ) = > {
@ -71,10 +86,12 @@ describe("HTTP Component", () => {
render ( < Http closeDialog = { vi . fn ( ) } / > ) ;
render ( < Http closeDialog = { vi . fn ( ) } / > ) ;
// Open the dialog first
const addButton = screen . getByText ( "Add New Server" ) ;
fireEvent . click ( addButton ) ;
const switchInput = screen . getByRole ( "switch" ) ;
const switchInput = screen . getByRole ( "switch" ) ;
expect ( switchInput ) . toBeChecked ( ) ;
expect ( switchInput ) . toBeChecked ( ) ;
expect ( screen . getByText ( "https://" ) ) . toBeInTheDocument ( ) ;
} ) ;
} ) ;
it . skip ( "submits form and triggers connection process" , async ( ) = > {
it . skip ( "submits form and triggers connection process" , async ( ) = > {