mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-07 09:13:04 +02:00
Tweak send no-response handling
This commit is contained in:
@@ -24,6 +24,7 @@ const CHANNEL_WARNING_THRESHOLD = 120; // Conservative for multi-hop
|
||||
const CHANNEL_DANGER_BUFFER = 8; // Red zone starts this many bytes before hard limit
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
const RADIO_NO_RESPONSE_SNIPPET = 'no response was heard back';
|
||||
/** Get UTF-8 byte length of a string (LoRa packets are byte-constrained, not character-constrained). */
|
||||
function byteLen(s: string): number {
|
||||
return textEncoder.encode(s).length;
|
||||
@@ -118,8 +119,11 @@ export const MessageInput = forwardRef<MessageInputHandle, MessageInputProps>(fu
|
||||
setText('');
|
||||
} catch (err) {
|
||||
console.error('Failed to send message:', err);
|
||||
toast.error('Failed to send message', {
|
||||
description: err instanceof Error ? err.message : 'Check radio connection',
|
||||
const description = err instanceof Error ? err.message : 'Check radio connection';
|
||||
const isRadioNoResponse =
|
||||
err instanceof Error && err.message.toLowerCase().includes(RADIO_NO_RESPONSE_SNIPPET);
|
||||
toast.error(isRadioNoResponse ? 'Radio did not confirm send' : 'Failed to send message', {
|
||||
description,
|
||||
});
|
||||
return;
|
||||
} finally {
|
||||
|
||||
@@ -9,12 +9,18 @@ import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
import { MessageInput } from '../components/MessageInput';
|
||||
import { toast } from '../components/ui/sonner';
|
||||
|
||||
// Mock sonner (toast)
|
||||
vi.mock('../components/ui/sonner', () => ({
|
||||
toast: { success: vi.fn(), error: vi.fn() },
|
||||
}));
|
||||
|
||||
const mockToast = toast as unknown as {
|
||||
success: ReturnType<typeof vi.fn>;
|
||||
error: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
|
||||
function byteLen(s: string): number {
|
||||
@@ -182,4 +188,24 @@ describe('MessageInput', () => {
|
||||
expect(getSendButton()).toBeEnabled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('send failure toasts', () => {
|
||||
it('shows the radio no-response toast when the send outcome is unknown', async () => {
|
||||
onSend.mockRejectedValueOnce(
|
||||
new Error(
|
||||
'Send command was issued to the radio, but no response was heard back. The message may or may not have sent successfully.'
|
||||
)
|
||||
);
|
||||
renderInput({ conversationType: 'contact' });
|
||||
|
||||
fireEvent.change(getInput(), { target: { value: 'Hello' } });
|
||||
fireEvent.click(getSendButton());
|
||||
|
||||
expect(await screen.findByDisplayValue('Hello')).toBeTruthy();
|
||||
expect(mockToast.error).toHaveBeenCalledWith('Radio did not confirm send', {
|
||||
description:
|
||||
'Send command was issued to the radio, but no response was heard back. The message may or may not have sent successfully.',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user