Tester feedback: offline mode, pt-PT, menus, layout and translations
Offline (read-only) mode - The last connected radio is remembered; with no radio the app opens on its saved contacts, channels, messages and unread counts. - Main screens stay open on disconnect. A Connect button replaces the battery and signal indicators, with a sheet to reconnect, choose a radio or stop a pending reconnect. - While disconnected everything is read-only: the composer becomes a "connect to send" bar (drafts kept) and controls that change the radio or stored history are disabled or hidden. - Resending while disconnected no longer deletes the message; a different radio no longer shows the previous radio's channels. - Notification taps open the saved chat while offline. Chats and menus - Channel chat menu: notifications, edit channel, delete channel; the filter row lines up with the others; bell moved out of the app bar. - DM and room menus: remove from contacts; rooms get room management. - Search field uses the full app bar; long-press a result to copy. - Hashtag channel titles no longer read "# #name"; more room around the radio activity dot. - Repeat filter: short messages from one sender are caught at the same count as long ones. Layout - Shared menu row (wraps to two lines) and segment label (never splits a word) used across the app. - One Scan button on the scanner; consistent settings tile titles; contact "last seen" wraps instead of truncating; unfetched repeater settings are dimmed. Localization - New European Portuguese locale (pt_PT); regional locales are handled by the language picker, notifications and the background service. - Fill 67 missing strings per locale, including backup and restore. - Keep "Flood" and "Zero Hop" untranslated, shorten "last seen" and routing labels, and fix mistranslated scan, theme and hop strings. - Received-image strings, badge and caption come from translations. - Regenerate the Czech localizations, which were missing strings. Docs - Add documentation/design.md (UI reference) and offline-mode.md; update channel, chat, navigation and scanner docs.
This commit is contained in:
1 parent
47f2293a5c
commit
462159e803
108 files changed
+17435
-4536
No files matched your search
@@ -0,0 +1,243 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/models/channel.dart';
|
||||
import 'package:meshcore_open/models/channel_message.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/models/message.dart';
|
||||
import 'package:meshcore_open/review_mode/review_radio.dart';
|
||||
import 'package:meshcore_open/storage/channel_message_store.dart';
|
||||
import 'package:meshcore_open/storage/channel_store.dart';
|
||||
import 'package:meshcore_open/storage/contact_store.dart';
|
||||
import 'package:meshcore_open/storage/last_radio_store.dart';
|
||||
import 'package:meshcore_open/storage/message_store.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:meshcore_open/storage/unread_store.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
final _radioKey = Uint8List.fromList(List<int>.generate(32, (i) => 0xA0 + i));
|
||||
final _radioHex = pubKeyToHex(_radioKey);
|
||||
final _aliceKey = Uint8List.fromList(List<int>.generate(32, (i) => 0x10 + i));
|
||||
final _psk = Uint8List.fromList(List<int>.generate(16, (i) => 0x40 + i));
|
||||
|
||||
Future<void> _waitFor(bool Function() condition, {int seconds = 8}) async {
|
||||
final end = DateTime.now().add(Duration(seconds: seconds));
|
||||
while (!condition()) {
|
||||
if (DateTime.now().isAfter(end)) fail('Timed out waiting for condition');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 25));
|
||||
}
|
||||
}
|
||||
|
||||
/// Saves a radio's data the way a real session would.
|
||||
Future<void> _seedRadio() async {
|
||||
final alice = Contact(
|
||||
publicKey: _aliceKey,
|
||||
name: 'Alice',
|
||||
type: advTypeChat,
|
||||
pathLength: 1,
|
||||
path: Uint8List.fromList([0x22]),
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(1700000000000),
|
||||
);
|
||||
final self = Contact(
|
||||
publicKey: _radioKey,
|
||||
name: 'Me',
|
||||
type: advTypeChat,
|
||||
pathLength: 0,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(1700000000000),
|
||||
);
|
||||
await (ContactStore()..setPublicKeyHex = _radioHex).saveContacts([
|
||||
alice,
|
||||
self,
|
||||
]);
|
||||
|
||||
final channel = Channel(index: 0, name: 'Base Camp', psk: _psk);
|
||||
final channelId = channel.storageId!;
|
||||
final channelStore = ChannelStore()..setPublicKeyHex = _radioHex;
|
||||
await channelStore.saveChannels([channel]);
|
||||
await channelStore.saveSlotChannelIds({0: channelId});
|
||||
await (ChannelMessageStore()..setPublicKeyHex = _radioHex)
|
||||
.saveChannelMessages(channelId, [
|
||||
ChannelMessage(
|
||||
senderName: 'Bob',
|
||||
text: 'camp is up',
|
||||
timestamp: DateTime.fromMillisecondsSinceEpoch(1700000001000),
|
||||
isOutgoing: false,
|
||||
status: ChannelMessageStatus.sent,
|
||||
channelIndex: 0,
|
||||
),
|
||||
]);
|
||||
|
||||
await (MessageStore()..setPublicKeyHex = _radioHex)
|
||||
.saveMessages(alice.publicKeyHex, [
|
||||
Message(
|
||||
senderKey: _aliceKey,
|
||||
text: 'hi there',
|
||||
timestamp: DateTime.fromMillisecondsSinceEpoch(1700000002000),
|
||||
isOutgoing: false,
|
||||
status: MessageStatus.delivered,
|
||||
),
|
||||
Message(
|
||||
senderKey: _aliceKey,
|
||||
text: 'did not go out',
|
||||
timestamp: DateTime.fromMillisecondsSinceEpoch(1700000003000),
|
||||
isOutgoing: true,
|
||||
status: MessageStatus.failed,
|
||||
),
|
||||
]);
|
||||
|
||||
final unread = UnreadStore()..setPublicKeyHex = _radioHex;
|
||||
unread.saveContactUnreadCount({alice.publicKeyHex: 2});
|
||||
await unread.flush();
|
||||
|
||||
await LastRadioStore().save(
|
||||
LastRadio(
|
||||
publicKeyHex: _radioHex,
|
||||
name: 'Base',
|
||||
transport: LastRadio.transportBle,
|
||||
bleRemoteId: 'AA:BB:CC:DD:EE:FF',
|
||||
savedAt: DateTime.fromMillisecondsSinceEpoch(1700000000000),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// initialize() listens to the notification service's single-subscription
|
||||
// reply stream, so these connectors run without it.
|
||||
MeshCoreConnector _newConnector() {
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
return connector;
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
ChannelMessageStore().forgetArchive();
|
||||
MessageStore().forgetArchive();
|
||||
await _seedRadio();
|
||||
ChannelMessageStore().forgetArchive();
|
||||
MessageStore().forgetArchive();
|
||||
});
|
||||
|
||||
test('restoreLastRadio shows the saved radio while disconnected', () async {
|
||||
final connector = _newConnector();
|
||||
expect(connector.hasRadioData, isFalse);
|
||||
|
||||
await connector.restoreLastRadio();
|
||||
|
||||
expect(connector.isConnected, isFalse);
|
||||
expect(connector.hasRadioData, isTrue);
|
||||
expect(connector.storageKeyHex, _radioHex);
|
||||
expect(connector.lastRadioName, 'Base');
|
||||
expect(connector.lastRadio?.canReconnectBle, isTrue);
|
||||
|
||||
// The radio's own entry is filtered out of the contact list.
|
||||
expect(connector.contacts.map((c) => c.name), ['Alice']);
|
||||
final alice = connector.contacts.single;
|
||||
expect(
|
||||
connector.getMessages(alice).map((m) => m.text),
|
||||
containsAll(['hi there', 'did not go out']),
|
||||
);
|
||||
expect(connector.getUnreadCountForContact(alice), 2);
|
||||
|
||||
expect(connector.channels.map((c) => c.name), ['Base Camp']);
|
||||
expect(
|
||||
connector
|
||||
.getChannelMessages(connector.channels.single)
|
||||
.map((m) => m.text),
|
||||
['camp is up'],
|
||||
);
|
||||
});
|
||||
|
||||
test('resend while offline keeps the message', () async {
|
||||
final connector = _newConnector();
|
||||
await connector.restoreLastRadio();
|
||||
final alice = connector.contacts.single;
|
||||
final failed = connector
|
||||
.getMessages(alice)
|
||||
.firstWhere((m) => m.text == 'did not go out');
|
||||
|
||||
await connector.resendMessage(alice, failed);
|
||||
|
||||
expect(
|
||||
connector.getMessages(alice).where((m) => m.text == 'did not go out'),
|
||||
hasLength(1),
|
||||
);
|
||||
final stored = await (MessageStore()..setPublicKeyHex = _radioHex)
|
||||
.loadMessages(alice.publicKeyHex);
|
||||
expect(stored.map((m) => m.text), contains('did not go out'));
|
||||
});
|
||||
|
||||
test('sendFrame throws RadioNotConnectedException offline', () async {
|
||||
final connector = _newConnector();
|
||||
await expectLater(
|
||||
connector.sendFrame(Uint8List.fromList([1])),
|
||||
throwsA(isA<RadioNotConnectedException>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('a review session neither replaces the remembered radio nor keeps its '
|
||||
'channels, and the saved radio is back afterwards', () async {
|
||||
final connector = _newConnector();
|
||||
connector.reviewRadioFactoryForTest = () => ReviewRadio(
|
||||
scheduledMessageInterval: const Duration(hours: 1),
|
||||
ackDelay: const Duration(milliseconds: 100),
|
||||
replyDelay: const Duration(milliseconds: 200),
|
||||
);
|
||||
await connector.restoreLastRadio();
|
||||
expect(connector.channels.map((c) => c.name), ['Base Camp']);
|
||||
|
||||
await connector.connectReview();
|
||||
expect(connector.isReviewMode, isTrue);
|
||||
await _waitFor(() => connector.channels.length >= 3);
|
||||
|
||||
// A different radio answered: the saved radio's channels are gone.
|
||||
expect(connector.channels.map((c) => c.name), isNot(contains('Base Camp')));
|
||||
expect(connector.contacts.map((c) => c.name), isNot(contains('Alice')));
|
||||
expect(connector.storageKeyHex, isNot(_radioHex));
|
||||
expect(LastRadioStore().load()?.publicKeyHex, _radioHex);
|
||||
|
||||
await connector.disconnect();
|
||||
await _waitFor(
|
||||
() =>
|
||||
connector.channels.any((c) => c.name == 'Base Camp') &&
|
||||
connector.contacts.any((c) => c.name == 'Alice'),
|
||||
);
|
||||
expect(connector.isConnected, isFalse);
|
||||
expect(connector.storageKeyHex, _radioHex);
|
||||
expect(connector.lastRadio?.publicKeyHex, _radioHex);
|
||||
expect(LastRadioStore().load()?.publicKeyHex, _radioHex);
|
||||
final alice = connector.contacts.firstWhere((c) => c.name == 'Alice');
|
||||
expect(
|
||||
connector.getMessages(alice).map((m) => m.text),
|
||||
contains('hi there'),
|
||||
);
|
||||
expect(connector.getUnreadCountForContact(alice), 2);
|
||||
// Review data never lands under the real radio's keys.
|
||||
final channels = await (ChannelStore()..setPublicKeyHex = _radioHex)
|
||||
.loadChannels();
|
||||
expect(channels.map((c) => c.name), ['Base Camp']);
|
||||
});
|
||||
|
||||
test('without a remembered radio nothing is loaded', () async {
|
||||
await LastRadioStore().clear();
|
||||
final connector = _newConnector();
|
||||
await connector.restoreLastRadio();
|
||||
expect(connector.hasRadioData, isFalse);
|
||||
expect(connector.contacts, isEmpty);
|
||||
expect(connector.channels, isEmpty);
|
||||
expect(connector.lastRadio, isNull);
|
||||
});
|
||||
|
||||
test('stored last_radio is JSON with the full key', () {
|
||||
final raw = PrefsManager.instance.getString(LastRadioStore.prefsKey)!;
|
||||
expect((jsonDecode(raw) as Map)['publicKeyHex'], _radioHex);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,347 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/channel.dart';
|
||||
import 'package:meshcore_open/models/channel_message.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/models/message.dart';
|
||||
import 'package:meshcore_open/review_mode/review_radio.dart';
|
||||
import 'package:meshcore_open/screens/channel_chat_screen.dart';
|
||||
import 'package:meshcore_open/screens/channels_screen.dart';
|
||||
import 'package:meshcore_open/screens/chat_screen.dart';
|
||||
import 'package:meshcore_open/screens/contacts_screen.dart';
|
||||
import 'package:meshcore_open/services/app_debug_log_service.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/ble_debug_log_service.dart';
|
||||
import 'package:meshcore_open/services/chat_text_scale_service.dart';
|
||||
import 'package:meshcore_open/services/image_codec_service.dart';
|
||||
import 'package:meshcore_open/services/map_tile_cache_service.dart';
|
||||
import 'package:meshcore_open/services/message_retry_service.dart';
|
||||
import 'package:meshcore_open/services/network_map/network_map_upload_service.dart';
|
||||
import 'package:meshcore_open/services/path_history_service.dart';
|
||||
import 'package:meshcore_open/services/received_image_store.dart';
|
||||
import 'package:meshcore_open/services/storage_service.dart';
|
||||
import 'package:meshcore_open/services/timeout_prediction_service.dart';
|
||||
import 'package:meshcore_open/services/translation_service.dart';
|
||||
import 'package:meshcore_open/services/ui_view_state_service.dart';
|
||||
import 'package:meshcore_open/storage/channel_message_store.dart';
|
||||
import 'package:meshcore_open/storage/channel_store.dart';
|
||||
import 'package:meshcore_open/storage/contact_store.dart';
|
||||
import 'package:meshcore_open/storage/last_radio_store.dart';
|
||||
import 'package:meshcore_open/storage/message_store.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/widgets/chat_composer.dart';
|
||||
import 'package:meshcore_open/widgets/connect_sheet.dart';
|
||||
|
||||
final _radioKey = Uint8List.fromList(List<int>.generate(32, (i) => 0xA0 + i));
|
||||
final _radioHex = pubKeyToHex(_radioKey);
|
||||
final _aliceKey = Uint8List.fromList(List<int>.generate(32, (i) => 0x10 + i));
|
||||
final _psk = Uint8List.fromList(List<int>.generate(16, (i) => 0x40 + i));
|
||||
|
||||
final _l10n = lookupAppLocalizations(const Locale('en'));
|
||||
|
||||
Future<void> _seedRadio() async {
|
||||
final alice = Contact(
|
||||
publicKey: _aliceKey,
|
||||
name: 'Alice',
|
||||
type: advTypeChat,
|
||||
pathLength: 1,
|
||||
path: Uint8List.fromList([0x22]),
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(1700000000000),
|
||||
);
|
||||
await (ContactStore()..setPublicKeyHex = _radioHex).saveContacts([alice]);
|
||||
final channel = Channel(index: 0, name: 'Base Camp', psk: _psk);
|
||||
final channelStore = ChannelStore()..setPublicKeyHex = _radioHex;
|
||||
await channelStore.saveChannels([channel]);
|
||||
await channelStore.saveSlotChannelIds({0: channel.storageId!});
|
||||
await (ChannelMessageStore()..setPublicKeyHex = _radioHex)
|
||||
.saveChannelMessages(channel.storageId!, [
|
||||
ChannelMessage(
|
||||
senderName: 'Bob',
|
||||
text: 'camp is up',
|
||||
timestamp: DateTime.fromMillisecondsSinceEpoch(1700000001000),
|
||||
isOutgoing: false,
|
||||
status: ChannelMessageStatus.sent,
|
||||
channelIndex: 0,
|
||||
),
|
||||
]);
|
||||
await (MessageStore()..setPublicKeyHex = _radioHex)
|
||||
.saveMessages(alice.publicKeyHex, [
|
||||
Message(
|
||||
senderKey: _aliceKey,
|
||||
text: 'hi there',
|
||||
timestamp: DateTime.fromMillisecondsSinceEpoch(1700000002000),
|
||||
isOutgoing: false,
|
||||
status: MessageStatus.delivered,
|
||||
),
|
||||
]);
|
||||
await LastRadioStore().save(
|
||||
LastRadio(
|
||||
publicKeyHex: _radioHex,
|
||||
name: 'Base',
|
||||
transport: LastRadio.transportBle,
|
||||
bleRemoteId: 'AA:BB:CC:DD:EE:FF',
|
||||
savedAt: DateTime.fromMillisecondsSinceEpoch(1700000000000),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Widget> _app(
|
||||
WidgetTester tester,
|
||||
MeshCoreConnector connector,
|
||||
Widget home,
|
||||
) async {
|
||||
final storage = StorageService();
|
||||
final settings = AppSettingsService();
|
||||
await tester.runAsync(settings.loadSettings);
|
||||
final translation = TranslationService(settings);
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: MessageRetryService()),
|
||||
ChangeNotifierProvider.value(value: PathHistoryService(storage)),
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: BleDebugLogService()),
|
||||
ChangeNotifierProvider.value(value: AppDebugLogService()),
|
||||
ChangeNotifierProvider.value(value: ChatTextScaleService()),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: UiViewStateService()),
|
||||
Provider.value(value: storage),
|
||||
ChangeNotifierProvider.value(
|
||||
value: MapTileCacheService(appSettingsService: settings),
|
||||
),
|
||||
ChangeNotifierProvider.value(value: TimeoutPredictionService(storage)),
|
||||
ChangeNotifierProvider.value(value: ImageCodecService(settings)),
|
||||
ChangeNotifierProvider.value(value: ReceivedImageStore()),
|
||||
ChangeNotifierProvider.value(
|
||||
value: NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: home,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _settle(WidgetTester tester) async {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _waitFor(
|
||||
WidgetTester tester,
|
||||
bool Function() condition, {
|
||||
int seconds = 8,
|
||||
}) async {
|
||||
await tester.runAsync(() async {
|
||||
final end = DateTime.now().add(Duration(seconds: seconds));
|
||||
while (!condition()) {
|
||||
if (DateTime.now().isAfter(end)) fail('Timed out waiting for condition');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 25));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Restores the seeded radio into a connector that never connects.
|
||||
Future<MeshCoreConnector> _offlineConnector(WidgetTester tester) async {
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
await tester.runAsync(connector.restoreLastRadio);
|
||||
expect(connector.isConnected, isFalse);
|
||||
expect(connector.channels, isNotEmpty);
|
||||
return connector;
|
||||
}
|
||||
|
||||
PopupMenuItem<Object?> _menuItem(String label) =>
|
||||
find
|
||||
.ancestor(
|
||||
of: find.text(label),
|
||||
matching: find.byWidgetPredicate((w) => w is PopupMenuItem),
|
||||
)
|
||||
.evaluate()
|
||||
.single
|
||||
.widget
|
||||
as PopupMenuItem<Object?>;
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final tempDir = Directory.systemTemp.createTempSync('offline_mode_test');
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('plugins.flutter.io/path_provider'),
|
||||
(call) async => tempDir.path,
|
||||
);
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
ChannelMessageStore().forgetArchive();
|
||||
MessageStore().forgetArchive();
|
||||
await _seedRadio();
|
||||
ChannelMessageStore().forgetArchive();
|
||||
MessageStore().forgetArchive();
|
||||
});
|
||||
|
||||
testWidgets('Channels screen stays put offline with saved data and a '
|
||||
'Connect control', (tester) async {
|
||||
final connector = await _offlineConnector(tester);
|
||||
await tester.pumpWidget(
|
||||
await _app(tester, connector, const ChannelsScreen()),
|
||||
);
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.byType(ChannelsScreen), findsOneWidget);
|
||||
expect(find.text('Base Camp'), findsOneWidget);
|
||||
expect(find.byType(ConnectButton), findsOneWidget);
|
||||
expect(find.text(_l10n.appBar_offlineSubtitle('Base')), findsOneWidget);
|
||||
// Adding a channel needs the radio.
|
||||
expect(find.byType(FloatingActionButton), findsNothing);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.more_vert));
|
||||
await _settle(tester);
|
||||
expect(find.text(_l10n.common_connect), findsWidgets);
|
||||
expect(find.text(_l10n.common_disconnect), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('Contacts screen stays put offline and disables radio actions', (
|
||||
tester,
|
||||
) async {
|
||||
final connector = await _offlineConnector(tester);
|
||||
await tester.pumpWidget(
|
||||
await _app(tester, connector, const ContactsScreen()),
|
||||
);
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.byType(ContactsScreen), findsOneWidget);
|
||||
expect(find.text('Alice'), findsWidgets);
|
||||
expect(find.byType(ConnectButton), findsOneWidget);
|
||||
expect(find.byType(FloatingActionButton), findsNothing);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.more_vert));
|
||||
await _settle(tester);
|
||||
expect(_menuItem(_l10n.contacts_floodAdvert).enabled, isFalse);
|
||||
expect(_menuItem(_l10n.contacts_zeroHopAdvert).enabled, isFalse);
|
||||
expect(_menuItem(_l10n.contacts_addContactFromClipboard).enabled, isFalse);
|
||||
expect(_menuItem(_l10n.common_connect).enabled, isTrue);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('Channel chat offline is read-only', (tester) async {
|
||||
final connector = await _offlineConnector(tester);
|
||||
await tester.pumpWidget(
|
||||
await _app(
|
||||
tester,
|
||||
connector,
|
||||
ChannelChatScreen(channel: connector.channels.single),
|
||||
),
|
||||
);
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.textContaining('camp is up'), findsWidgets);
|
||||
expect(find.byType(OfflineComposerBar), findsOneWidget);
|
||||
expect(find.text(_l10n.chat_composerOffline), findsOneWidget);
|
||||
expect(find.byType(TextField), findsNothing);
|
||||
expect(find.byType(ConnectButton), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.more_vert));
|
||||
await _settle(tester);
|
||||
expect(_menuItem(_l10n.channels_editChannel).enabled, isFalse);
|
||||
expect(_menuItem(_l10n.contact_clearChat).enabled, isFalse);
|
||||
expect(_menuItem(_l10n.channels_deleteChannel).enabled, isFalse);
|
||||
// Per-device preferences stay available.
|
||||
expect(_menuItem(_l10n.chatBackground_title).enabled, isTrue);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('DM chat offline is read-only', (tester) async {
|
||||
final connector = await _offlineConnector(tester);
|
||||
final alice = connector.contacts.single;
|
||||
await tester.pumpWidget(
|
||||
await _app(tester, connector, ChatScreen(contact: alice)),
|
||||
);
|
||||
await _settle(tester);
|
||||
|
||||
expect(find.textContaining('hi there'), findsWidgets);
|
||||
expect(find.byType(OfflineComposerBar), findsOneWidget);
|
||||
expect(find.byType(TextField), findsNothing);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.more_vert));
|
||||
await _settle(tester);
|
||||
expect(_menuItem(_l10n.contact_clearChat).enabled, isFalse);
|
||||
expect(_menuItem(_l10n.contact_telemetry).enabled, isFalse);
|
||||
expect(_menuItem(_l10n.contact_info).enabled, isTrue);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('a draft typed while connected survives a disconnect and '
|
||||
'reconnect', (tester) async {
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
connector.reviewRadioFactoryForTest = () => ReviewRadio(
|
||||
scheduledMessageInterval: const Duration(hours: 1),
|
||||
ackDelay: const Duration(hours: 1),
|
||||
replyDelay: const Duration(hours: 1),
|
||||
);
|
||||
await tester.runAsync(connector.connectReview);
|
||||
await _waitFor(tester, () => connector.contacts.isNotEmpty);
|
||||
final contact = connector.contacts.firstWhere((c) => c.type == advTypeChat);
|
||||
|
||||
await tester.pumpWidget(
|
||||
await _app(tester, connector, ChatScreen(contact: contact)),
|
||||
);
|
||||
await _settle(tester);
|
||||
await tester.enterText(find.byType(TextField), 'half written');
|
||||
await _settle(tester);
|
||||
|
||||
await tester.runAsync(connector.disconnect);
|
||||
// Connector notifications are debounced on a real timer.
|
||||
await _waitFor(tester, () => !connector.isConnected);
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 200)),
|
||||
);
|
||||
await _settle(tester);
|
||||
expect(find.byType(ChatScreen), findsOneWidget);
|
||||
expect(find.byType(OfflineComposerBar), findsOneWidget);
|
||||
expect(find.byType(TextField), findsNothing);
|
||||
|
||||
await tester.runAsync(connector.connectReview);
|
||||
await _waitFor(tester, () => connector.isConnected);
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 200)),
|
||||
);
|
||||
await _settle(tester);
|
||||
expect(find.byType(OfflineComposerBar), findsNothing);
|
||||
final field = tester.widget<TextField>(find.byType(TextField));
|
||||
expect(field.controller?.text, 'half written');
|
||||
|
||||
await tester.runAsync(connector.disconnect);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pump(const Duration(minutes: 1));
|
||||
});
|
||||
}
|
||||
@@ -241,9 +241,20 @@ void main() {
|
||||
|
||||
final variants = [
|
||||
for (final entry in _screens.entries) (entry, false),
|
||||
// Repeater screens add a banner while the companion radio is offline.
|
||||
// Repeater screens add a banner while the companion radio is offline;
|
||||
// the main and chat screens swap in the Connect button and the
|
||||
// read-only composer bar.
|
||||
for (final entry in _screens.entries)
|
||||
if (entry.key.startsWith('Repeater') || entry.key == 'Neighbors')
|
||||
if (entry.key.startsWith('Repeater') ||
|
||||
const {
|
||||
'Neighbors',
|
||||
'Channels',
|
||||
'Contacts',
|
||||
'Map',
|
||||
'Chat',
|
||||
'ChannelChat',
|
||||
'Settings',
|
||||
}.contains(entry.key))
|
||||
(entry, true),
|
||||
];
|
||||
for (final (entry, offline) in variants) {
|
||||
|
||||
@@ -77,12 +77,16 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('short replies repeated by the same sender are not duplicates', () {
|
||||
test('short texts repeated by the same sender are duplicates', () {
|
||||
final tracker = DuplicateTracker();
|
||||
for (final text in ['ok', 'test', 'yes sir', 'ok']) {
|
||||
tracker.check(channelId: 'c', sender: 'Alice', text: text, at: t0);
|
||||
for (final text in ['hello', 'test', 'yes sir']) {
|
||||
expect(
|
||||
tracker.check(channelId: 'c', sender: 'Alice', text: text, at: t0),
|
||||
isNull,
|
||||
reason: text,
|
||||
);
|
||||
}
|
||||
for (final text in ['@[Bob] ok', 'test', 'yes sir']) {
|
||||
for (final text in ['Hello!', 'test', 'yes sir']) {
|
||||
expect(
|
||||
tracker.check(
|
||||
channelId: 'c',
|
||||
@@ -90,12 +94,36 @@ void main() {
|
||||
text: text,
|
||||
at: t0.add(const Duration(minutes: 5)),
|
||||
),
|
||||
isNull,
|
||||
FilterReason.duplicate,
|
||||
reason: text,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('short texts use the same send count as long ones', () {
|
||||
final tracker = DuplicateTracker(sameSenderSends: 3);
|
||||
FilterReason? send(int minute) => tracker.check(
|
||||
channelId: 'c',
|
||||
sender: 'Alice',
|
||||
text: 'hello',
|
||||
at: t0.add(Duration(minutes: minute)),
|
||||
);
|
||||
expect(send(0), isNull);
|
||||
expect(send(1), isNull);
|
||||
expect(send(2), FilterReason.duplicate);
|
||||
});
|
||||
|
||||
test('a short text from many senders is not a repeat', () {
|
||||
final tracker = DuplicateTracker();
|
||||
for (final sender in ['Alice', 'Bob', 'Carol', 'Dave']) {
|
||||
expect(
|
||||
tracker.check(channelId: 'c', sender: sender, text: 'hello', at: t0),
|
||||
isNull,
|
||||
reason: sender,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('same sender repeat after the window is not a duplicate', () {
|
||||
final tracker = DuplicateTracker();
|
||||
tracker.check(channelId: 'c', sender: 'Bob', text: 'Hello', at: t0);
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/storage/last_radio_store.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
Future<void> _init([Map<String, Object> values = const {}]) async {
|
||||
SharedPreferences.setMockInitialValues(values);
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
}
|
||||
|
||||
const _key = 'aabbccddeeff00112233445566778899aabbccddeeff00112233445566778899';
|
||||
|
||||
void main() {
|
||||
test('save and load round-trip a BLE radio', () async {
|
||||
await _init();
|
||||
final store = LastRadioStore();
|
||||
final saved = LastRadio(
|
||||
publicKeyHex: _key,
|
||||
name: 'Base',
|
||||
transport: LastRadio.transportBle,
|
||||
bleRemoteId: 'AA:BB:CC:DD:EE:FF',
|
||||
bleDisplayName: 'MeshCore-Base',
|
||||
savedAt: DateTime.fromMillisecondsSinceEpoch(1234),
|
||||
);
|
||||
await store.save(saved);
|
||||
|
||||
final loaded = store.load()!;
|
||||
expect(loaded.publicKeyHex, _key);
|
||||
expect(loaded.name, 'Base');
|
||||
expect(loaded.transport, LastRadio.transportBle);
|
||||
expect(loaded.bleRemoteId, 'AA:BB:CC:DD:EE:FF');
|
||||
expect(loaded.bleDisplayName, 'MeshCore-Base');
|
||||
expect(loaded.tcpHost, isNull);
|
||||
expect(loaded.savedAt.millisecondsSinceEpoch, 1234);
|
||||
expect(loaded.canReconnectBle, isTrue);
|
||||
expect(loaded.canReconnectTcp, isFalse);
|
||||
});
|
||||
|
||||
test('TCP radio keeps host and port', () async {
|
||||
await _init();
|
||||
final store = LastRadioStore();
|
||||
await store.save(
|
||||
LastRadio(
|
||||
publicKeyHex: _key,
|
||||
name: 'Roof',
|
||||
transport: LastRadio.transportTcp,
|
||||
tcpHost: '192.168.1.5',
|
||||
tcpPort: 5000,
|
||||
savedAt: DateTime.now(),
|
||||
),
|
||||
);
|
||||
final loaded = store.load()!;
|
||||
expect(loaded.tcpHost, '192.168.1.5');
|
||||
expect(loaded.tcpPort, 5000);
|
||||
expect(loaded.canReconnectTcp, isTrue);
|
||||
expect(loaded.canReconnectBle, isFalse);
|
||||
});
|
||||
|
||||
test('clear removes the record', () async {
|
||||
await _init();
|
||||
final store = LastRadioStore();
|
||||
await store.save(
|
||||
LastRadio(
|
||||
publicKeyHex: _key,
|
||||
name: 'x',
|
||||
transport: LastRadio.transportUsb,
|
||||
savedAt: DateTime.now(),
|
||||
),
|
||||
);
|
||||
await store.clear();
|
||||
expect(store.load(), isNull);
|
||||
});
|
||||
|
||||
test('tolerates missing, corrupt and partial records', () async {
|
||||
await _init();
|
||||
expect(LastRadioStore().load(), isNull);
|
||||
|
||||
await _init({LastRadioStore.prefsKey: '{not json'});
|
||||
expect(LastRadioStore().load(), isNull);
|
||||
|
||||
await _init({
|
||||
LastRadioStore.prefsKey: jsonEncode([1, 2, 3]),
|
||||
});
|
||||
expect(LastRadioStore().load(), isNull);
|
||||
|
||||
await _init({
|
||||
LastRadioStore.prefsKey: jsonEncode({'publicKeyHex': 'abc'}),
|
||||
});
|
||||
expect(LastRadioStore().load(), isNull);
|
||||
|
||||
await _init({
|
||||
LastRadioStore.prefsKey: jsonEncode({
|
||||
'publicKeyHex': _key,
|
||||
'transport': 'carrier-pigeon',
|
||||
'tcpPort': '80',
|
||||
'savedAt': 'yesterday',
|
||||
}),
|
||||
});
|
||||
final loaded = LastRadioStore().load()!;
|
||||
expect(loaded.publicKeyHex, _key);
|
||||
expect(loaded.name, '');
|
||||
expect(loaded.transport, LastRadio.transportBle);
|
||||
expect(loaded.tcpPort, isNull);
|
||||
expect(loaded.canReconnectBle, isFalse);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||
|
||||
Widget _segments(double width, List<String> labels) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: SegmentedButton<int>(
|
||||
showSelectedIcon: false,
|
||||
segments: [
|
||||
for (var i = 0; i < labels.length; i++)
|
||||
ButtonSegment(value: i, label: MeshSegmentLabel(labels[i])),
|
||||
],
|
||||
selected: const {0},
|
||||
onSelectionChanged: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('short labels lay out on one line at full size', (tester) async {
|
||||
await tester.pumpWidget(_segments(360, ['Auto', 'Flood', 'Manual']));
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.bySemanticsLabel('Flood'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('long labels in narrow segments do not overflow', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_segments(240, [
|
||||
'Padrão do sistema',
|
||||
'Inundação',
|
||||
'Automatisch',
|
||||
'Manual',
|
||||
]),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
final labels = find.byType(MeshSegmentLabel);
|
||||
final multi = tester.getSize(labels.at(0));
|
||||
final longWord = tester.getSize(labels.at(1));
|
||||
final single = tester.getSize(labels.at(3));
|
||||
// The multi-word label wraps at its space instead of shrinking further;
|
||||
// a single long word stays on one line.
|
||||
expect(multi.height, greaterThan(single.height));
|
||||
expect(longWord.height, lessThanOrEqualTo(single.height));
|
||||
for (var i = 0; i < 4; i++) {
|
||||
final box = tester.renderObject<RenderBox>(labels.at(i));
|
||||
final parent = box.parent! as RenderBox;
|
||||
expect(box.size.width, lessThanOrEqualTo(parent.size.width));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/image_codec_support.dart';
|
||||
import 'package:meshcore_open/services/image_chunk_transport.dart';
|
||||
import 'package:meshcore_open/widgets/image_send_codec_binding.dart';
|
||||
@@ -81,6 +82,8 @@ Future<void> _pumpBubble(
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: ReceivedImageMessage(
|
||||
streamId: streamId,
|
||||
@@ -112,6 +115,8 @@ void main() {
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: ReceivedImageMessage(
|
||||
streamId: entry.streamId,
|
||||
@@ -146,6 +151,8 @@ void main() {
|
||||
await store2.load();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: ReceivedImageMessage(
|
||||
streamId: 'incoming',
|
||||
@@ -159,7 +166,7 @@ void main() {
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text('AI-reconstructed'), findsOneWidget);
|
||||
expect(find.textContaining('Fine detail is generated'), findsOneWidget);
|
||||
expect(find.textContaining('fine detail is generated'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('receiving state shows the packet count', (tester) async {
|
||||
@@ -178,6 +185,8 @@ void main() {
|
||||
expect(entry!.state, ReceivedImageState.receiving);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: ReceivedImageMessage(
|
||||
streamId: entry.streamId,
|
||||
@@ -215,6 +224,8 @@ void main() {
|
||||
final store = await _awaitingStore(bytes: 209, packets: 3);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: ReceivedImageMessage(
|
||||
streamId: 'await1',
|
||||
@@ -412,8 +423,8 @@ void main() {
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('AI-reconstructed'), findsOneWidget);
|
||||
expect(find.textContaining('Reconstructed by an AI model'), findsOneWidget);
|
||||
expect(find.textContaining('Fine detail is generated'), findsOneWidget);
|
||||
expect(find.textContaining('AI-reconstructed from'), findsOneWidget);
|
||||
expect(find.textContaining('fine detail is generated'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the caption quotes the real bitstream size, not a nominal one', (
|
||||
@@ -498,7 +509,7 @@ void main() {
|
||||
await tester.pump();
|
||||
|
||||
final caption = tester.widget<Text>(
|
||||
find.textContaining('Reconstructed by an AI model'),
|
||||
find.textContaining('AI-reconstructed from'),
|
||||
);
|
||||
expect(caption.maxLines, isNull, reason: 'the sentence must wrap in full');
|
||||
expect(caption.overflow, isNot(TextOverflow.ellipsis));
|
||||
|
||||
Reference in new issue
Block a user