Add zero-hop impulse advert. Closes #83.

This commit is contained in:
Jack Kingsman
2026-03-18 19:59:08 -07:00
parent d8e22ef4af
commit b832239e22
13 changed files with 159 additions and 45 deletions
+17 -2
View File
@@ -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' }));
});
});
+21 -1
View File
@@ -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 });