mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-06 08:43:36 +02:00
Add zero-hop impulse advert. Closes #83.
This commit is contained in:
@@ -305,7 +305,7 @@ describe('fetchJson (via api methods)', () => {
|
||||
expect(options.method).toBe('DELETE');
|
||||
});
|
||||
|
||||
it('sends POST without body for sendAdvertisement', async () => {
|
||||
it('sends POST with flood mode for sendAdvertisement', async () => {
|
||||
installMockFetch();
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
@@ -317,7 +317,22 @@ describe('fetchJson (via api methods)', () => {
|
||||
const [url, options] = mockFetch.mock.calls[0];
|
||||
expect(url).toBe('/api/radio/advertise');
|
||||
expect(options.method).toBe('POST');
|
||||
expect(options.body).toBeUndefined();
|
||||
expect(options.body).toBe(JSON.stringify({ mode: 'flood' }));
|
||||
});
|
||||
|
||||
it('sends POST with zero-hop mode for sendAdvertisement', async () => {
|
||||
installMockFetch();
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
ok: true,
|
||||
json: () => Promise.resolve({ status: 'ok' }),
|
||||
});
|
||||
|
||||
await api.sendAdvertisement('zero_hop');
|
||||
|
||||
const [url, options] = mockFetch.mock.calls[0];
|
||||
expect(url).toBe('/api/radio/advertise');
|
||||
expect(options.method).toBe('POST');
|
||||
expect(options.body).toBe(JSON.stringify({ mode: 'zero_hop' }));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
AppSettings,
|
||||
AppSettingsUpdate,
|
||||
HealthStatus,
|
||||
RadioAdvertMode,
|
||||
RadioConfig,
|
||||
RadioConfigUpdate,
|
||||
RadioDiscoveryResponse,
|
||||
@@ -74,6 +75,7 @@ function renderModal(overrides?: {
|
||||
onReboot?: () => Promise<void>;
|
||||
onDisconnect?: () => Promise<void>;
|
||||
onReconnect?: () => Promise<void>;
|
||||
onAdvertise?: (mode: RadioAdvertMode) => Promise<void>;
|
||||
meshDiscovery?: RadioDiscoveryResponse | null;
|
||||
meshDiscoveryLoadingTarget?: RadioDiscoveryTarget | null;
|
||||
onDiscoverMesh?: (target: RadioDiscoveryTarget) => Promise<void>;
|
||||
@@ -93,6 +95,7 @@ function renderModal(overrides?: {
|
||||
const onReboot = overrides?.onReboot ?? vi.fn(async () => {});
|
||||
const onDisconnect = overrides?.onDisconnect ?? vi.fn(async () => {});
|
||||
const onReconnect = overrides?.onReconnect ?? vi.fn(async () => {});
|
||||
const onAdvertise = overrides?.onAdvertise ?? vi.fn(async (_mode: RadioAdvertMode) => {});
|
||||
const onDiscoverMesh = overrides?.onDiscoverMesh ?? vi.fn(async () => {});
|
||||
|
||||
const commonProps = {
|
||||
@@ -108,7 +111,7 @@ function renderModal(overrides?: {
|
||||
onReboot,
|
||||
onDisconnect,
|
||||
onReconnect,
|
||||
onAdvertise: vi.fn(async () => {}),
|
||||
onAdvertise,
|
||||
meshDiscovery: overrides?.meshDiscovery ?? null,
|
||||
meshDiscoveryLoadingTarget: overrides?.meshDiscoveryLoadingTarget ?? null,
|
||||
onDiscoverMesh,
|
||||
@@ -135,6 +138,7 @@ function renderModal(overrides?: {
|
||||
onReboot,
|
||||
onDisconnect,
|
||||
onReconnect,
|
||||
onAdvertise,
|
||||
onDiscoverMesh,
|
||||
view,
|
||||
};
|
||||
@@ -206,6 +210,22 @@ describe('SettingsModal', () => {
|
||||
expect(screen.getByText(/Configured radio contact capacity/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders flood and zero-hop advert buttons and passes the selected mode', async () => {
|
||||
const onAdvertise = vi.fn(async (_mode: RadioAdvertMode) => {});
|
||||
renderModal({ onAdvertise });
|
||||
openRadioSection();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Send Flood Advertisement' }));
|
||||
await waitFor(() => {
|
||||
expect(onAdvertise).toHaveBeenCalledWith('flood');
|
||||
});
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Send Zero-Hop Advertisement' }));
|
||||
await waitFor(() => {
|
||||
expect(onAdvertise).toHaveBeenCalledWith('zero_hop');
|
||||
});
|
||||
});
|
||||
|
||||
it('shows radio-unavailable message when config is null', () => {
|
||||
renderModal({ config: null });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user