From 92dadb0d3a6b2f2d2161f983c9268358e64a068b Mon Sep 17 00:00:00 2001 From: zjs81 Date: Fri, 20 Nov 2026 16:04:50 -0700 Subject: [PATCH 1/2] Fix stale map labels, avatar initials and offline bubble widths - Map node labels follow light/dark theme changes. - Avatar initials use only letters and digits; hop avatars fall back to the hash prefix. - Incoming channel bubbles are the same width connected and offline. - Day separators wrap instead of overflowing with large text. --- documentation/design.md | 2 +- lib/screens/channel_chat_screen.dart | 4 +- lib/screens/channel_message_path_screen.dart | 28 +- lib/screens/map_screen.dart | 9 +- lib/utils/platform_info.dart | 7 +- lib/widgets/chat_day_separator.dart | 41 ++- lib/widgets/contact_visuals.dart | 35 ++ lib/widgets/mesh_ui.dart | 25 +- .../channel_message_path_avatar_test.dart | 84 +++++ test/screens/chat_bubble_width_test.dart | 321 ++++++++++++++++++ test/screens/map_rebuild_scope_test.dart | 61 +++- test/widgets/avatar_initials_test.dart | 73 ++++ 12 files changed, 642 insertions(+), 48 deletions(-) create mode 100644 test/screens/channel_message_path_avatar_test.dart create mode 100644 test/screens/chat_bubble_width_test.dart create mode 100644 test/widgets/avatar_initials_test.dart diff --git a/documentation/design.md b/documentation/design.md index 423b53aa..8262ed87 100644 --- a/documentation/design.md +++ b/documentation/design.md @@ -102,7 +102,7 @@ Minimum sizes: no hard-coded `fontSize` below 12 exists in `lib/screens` or `lib | Sheet header | padding 20, 8, 8, 4 (LTRB), 36×4 drag handle | `BottomSheetHeader` | | Radii | `MeshRadii.xs` 6, `sm` 10, `md` 14 (cards, inputs, menus, snackbars, list tiles), `lg` 18 (sheets, dialogs), `xl` 24, `pill` 999 (buttons, chips, FAB) | `MeshRadii` | | Default icon size | 22 | `iconTheme` | -| Avatar | 40 | `AvatarCircle` | +| Avatar | 40; initials from letters and digits only (`avatarInitials`), else a person icon. Pass a hop's hex prefix, not a "(AB) Name" label | `AvatarCircle` | | List bottom padding under a FAB | 88 | `channels_screen.dart` | Icon sizes in use: 24 for tile and banner icons, 20 for menu icons and small action buttons, 18 for inline refresh icons and spinners. Keep tappable icons at 20 or more. diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index 67a397ab..618602a4 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -3958,8 +3958,10 @@ class _SwipeReplyBubbleState extends State<_SwipeReplyBubble> { onPointerMove: _handleSwipePointerMove, onPointerUp: (event) => _handleSwipePointerUp(event.position), onPointerCancel: (_) => _resetSwipe(), + // Same insets as the plain row in _buildMessageBubble, so a bubble is + // as wide whether or not it can be swiped (offline, desktop, outgoing). child: Padding( - padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 8), + padding: const EdgeInsets.symmetric(vertical: 3), child: Stack( alignment: Alignment.center, children: [ diff --git a/lib/screens/channel_message_path_screen.dart b/lib/screens/channel_message_path_screen.dart index e99917a1..bdd415ba 100644 --- a/lib/screens/channel_message_path_screen.dart +++ b/lib/screens/channel_message_path_screen.dart @@ -21,6 +21,7 @@ import '../models/display_path.dart'; import '../models/path_playback.dart'; import '../theme/mesh_theme.dart'; import '../widgets/adaptive_app_bar_title.dart'; +import '../widgets/contact_visuals.dart'; import '../widgets/mesh_ui.dart'; import '../widgets/path_map_scaffold.dart'; import '../widgets/path_map_ui.dart'; @@ -356,7 +357,7 @@ class ChannelMessagePathScreen extends StatelessWidget { Stack( clipBehavior: Clip.none, children: [ - AvatarCircle(name: hop.displayLabel, size: 36), + AvatarCircle(name: hop.avatarName, size: 36), Positioned( right: -4, top: -4, @@ -1616,14 +1617,23 @@ class _PathHop { bool get hasLocation => position != null; - String get displayLabel { - final prefixLabel = hopBytes != null && hopBytes!.isNotEmpty - ? hopBytes! - .map((b) => b.toRadixString(16).padLeft(2, '0')) - .join('') - .toUpperCase() - : _formatPrefix(prefix); - return '($prefixLabel) ${_resolveName(contact, l10n)}'; + String get prefixLabel => hopBytes != null && hopBytes!.isNotEmpty + ? hopBytes! + .map((b) => b.toRadixString(16).padLeft(2, '0')) + .join('') + .toUpperCase() + : _formatPrefix(prefix); + + String get displayLabel => '($prefixLabel) ${_resolveName(contact, l10n)}'; + + /// Avatar source: the repeater's own name, or the hop's hex prefix when + /// the hop is unresolved or its name has nothing to make initials from. + String get avatarName { + final name = contact?.name.trim() ?? ''; + if (name.toLowerCase() == 'unknown' || avatarInitials(name) == null) { + return prefixLabel; + } + return name; } } diff --git a/lib/screens/map_screen.dart b/lib/screens/map_screen.dart index 018b7ec8..b3270202 100644 --- a/lib/screens/map_screen.dart +++ b/lib/screens/map_screen.dart @@ -1198,6 +1198,9 @@ class _MapScreenState extends State with WidgetsBindingObserver { showOtherNodes: settings.mapShowOtherNodes, isBuildingPathTrace: _isBuildingPathTrace, clusterNodes: settings.mapClusterNodes, + // Node labels bake in the overlay colors, so a light/dark or theme + // switch must rebuild them. + colorScheme: Theme.of(context).colorScheme, ); if (key != _nodeMarkersCacheKey) { _nodeMarkersCacheKey = key; @@ -4385,6 +4388,7 @@ class _NodeMarkersCacheKey { final bool showOtherNodes; final bool isBuildingPathTrace; final bool clusterNodes; + final ColorScheme colorScheme; const _NodeMarkersCacheKey({ required this.contactsSignature, @@ -4405,6 +4409,7 @@ class _NodeMarkersCacheKey { required this.showOtherNodes, required this.isBuildingPathTrace, required this.clusterNodes, + required this.colorScheme, }); @override @@ -4427,7 +4432,8 @@ class _NodeMarkersCacheKey { showChatNodes == other.showChatNodes && showOtherNodes == other.showOtherNodes && isBuildingPathTrace == other.isBuildingPathTrace && - clusterNodes == other.clusterNodes; + clusterNodes == other.clusterNodes && + colorScheme == other.colorScheme; } @override @@ -4450,6 +4456,7 @@ class _NodeMarkersCacheKey { showOtherNodes, isBuildingPathTrace, clusterNodes, + colorScheme, ); } diff --git a/lib/utils/platform_info.dart b/lib/utils/platform_info.dart index a388932a..6132474d 100644 --- a/lib/utils/platform_info.dart +++ b/lib/utils/platform_info.dart @@ -32,7 +32,12 @@ class PlatformInfo { static bool get isMobile => isAndroid || isIOS; /// Whether the app is running on a desktop platform (macOS, Windows, or Linux). - static bool get isDesktop => isMacOS || isWindows || isLinux; + static bool get isDesktop => + debugIsDesktopOverride ?? (isMacOS || isWindows || isLinux); + + /// Lets widget tests exercise the mobile layout on a desktop test host. + @visibleForTesting + static bool? debugIsDesktopOverride; /// Whether the current platform supports a native USB serial backend. static bool get supportsNativeUsbSerial => diff --git a/lib/widgets/chat_day_separator.dart b/lib/widgets/chat_day_separator.dart index a6d9bcad..0ca0b26c 100644 --- a/lib/widgets/chat_day_separator.dart +++ b/lib/widgets/chat_day_separator.dart @@ -44,21 +44,34 @@ class ChatDaySeparator extends StatelessWidget { ); return Padding( padding: const EdgeInsets.symmetric(vertical: 10), - child: Row( - children: [ - line, - const SizedBox(width: 10), - Text( - formatChatDayLabel(context, day), - style: MeshTheme.mono( - fontSize: 12, - fontWeight: FontWeight.w600, - color: color, + child: LayoutBuilder( + // Large text on a narrow phone wraps the label instead of overflowing; + // each rule keeps at least 16dp. + builder: (context, constraints) => Row( + children: [ + line, + const SizedBox(width: 10), + ConstrainedBox( + constraints: BoxConstraints( + maxWidth: (constraints.maxWidth - 2 * (10 + 16)).clamp( + 0.0, + double.infinity, + ), + ), + child: Text( + formatChatDayLabel(context, day), + textAlign: TextAlign.center, + style: MeshTheme.mono( + fontSize: 12, + fontWeight: FontWeight.w600, + color: color, + ), + ), ), - ), - const SizedBox(width: 10), - line, - ], + const SizedBox(width: 10), + line, + ], + ), ), ); } diff --git a/lib/widgets/contact_visuals.dart b/lib/widgets/contact_visuals.dart index cc9c4319..2caf6bb1 100644 --- a/lib/widgets/contact_visuals.dart +++ b/lib/widgets/contact_visuals.dart @@ -5,6 +5,7 @@ import '../l10n/app_localizations.dart'; import '../models/contact.dart'; import '../theme/mesh_theme.dart'; import '../theme/theme_icons.dart'; +import '../utils/emoji_utils.dart'; /// Shared node-type visuals and last-seen formatting for contact lists /// (contacts, discovery, nearby-node scan). @@ -41,6 +42,40 @@ ThemeIconSlot? contactTypeIconSlot(int type) { } } +final RegExp _letterOrDigit = RegExp(r'^[\p{L}\p{N}]', unicode: true); + +/// Avatar initials for a display name, or null when the name has nothing +/// usable so the caller can show an icon or key prefix instead. +/// +/// Only letters and digits count: punctuation such as `-`, `(` or `[` splits +/// words but never becomes an initial, so "(Base) Node" gives "BN" and +/// "- Relay" gives "RE". Characters are whole grapheme clusters, so accented +/// letters and emoji are never cut in half. A name with no letters or digits +/// but an emoji shows that emoji. +String? avatarInitials(String name) { + final words = []; + final current = StringBuffer(); + String? emoji; + for (final cluster in name.characters) { + if (_letterOrDigit.hasMatch(cluster)) { + current.write(cluster); + continue; + } + if (current.isNotEmpty) { + words.add(current.toString()); + current.clear(); + } + emoji ??= firstEmoji(cluster); + } + if (current.isNotEmpty) words.add(current.toString()); + + if (words.isEmpty) return emoji; + if (words.length == 1) { + return words.first.characters.take(2).toString().toUpperCase(); + } + return (words[0].characters.first + words[1].characters.first).toUpperCase(); +} + /// The most recent activity for [contact]: for chat nodes this includes the /// last message, for other node types only the last advert or telemetry fix. DateTime resolveContactLastSeen(Contact contact) { diff --git a/lib/widgets/mesh_ui.dart b/lib/widgets/mesh_ui.dart index 8bef6c59..e15905eb 100644 --- a/lib/widgets/mesh_ui.dart +++ b/lib/widgets/mesh_ui.dart @@ -7,6 +7,7 @@ import 'package:flutter/services.dart'; import '../l10n/l10n.dart'; import '../theme/mesh_theme.dart'; import '../theme/theme_icons.dart'; +import 'contact_visuals.dart'; /// MeshCore shared design kit. /// @@ -283,7 +284,8 @@ class StatTile extends StatelessWidget { /// Initials avatar with a deterministic per-name hue, or a fixed [color] /// for node-type coloring. Optional [icon] or themeable [iconSlot] replaces -/// initials. +/// initials. Initials come from [avatarInitials]; a name with no letters, +/// digits or emoji shows a generic person icon instead. class AvatarCircle extends StatelessWidget { final String name; final double size; @@ -320,7 +322,7 @@ class AvatarCircle extends StatelessWidget { @override Widget build(BuildContext context) { final accent = color ?? _colorFor(name); - final initials = _initials(name); + final initials = avatarInitials(name); final background = _tintedCardBackground(context, accent, 0.14); // A theme picture (e.g. a holiday marker) fills the whole circle, the // same as on the map, rather than sitting small inside the tint. @@ -360,9 +362,9 @@ class AvatarCircle extends StatelessWidget { size: size * 0.55, color: readableAccent(accent, background, minContrast: 3), ) - : icon != null + : icon != null || initials == null ? Icon( - icon, + icon ?? Icons.person_outline, size: size * 0.5, color: readableAccent(accent, background, minContrast: 3), ) @@ -376,21 +378,6 @@ class AvatarCircle extends StatelessWidget { ), ); } - - static String _initials(String name) { - final words = name - .trim() - .split(RegExp(r'\s+')) - .where((w) => w.isNotEmpty) - .toList(); - if (words.isEmpty) return '?'; - if (words.length == 1) { - return words.first.characters.take(2).toString().toUpperCase(); - } - return (words.first.characters.take(1).toString() + - words[1].characters.take(1).toString()) - .toUpperCase(); - } } /// Four-bar signal strength indicator driven by an SNR value (dB), colored diff --git a/test/screens/channel_message_path_avatar_test.dart b/test/screens/channel_message_path_avatar_test.dart new file mode 100644 index 00000000..cf34f0ba --- /dev/null +++ b/test/screens/channel_message_path_avatar_test.dart @@ -0,0 +1,84 @@ +import 'dart:typed_data'; + +import 'package:flutter/material.dart'; +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/l10n/app_localizations.dart'; +import 'package:meshcore_open/models/channel_message.dart'; +import 'package:meshcore_open/models/contact.dart'; +import 'package:meshcore_open/screens/channel_message_path_screen.dart'; +import 'package:meshcore_open/widgets/mesh_ui.dart'; +import 'package:provider/provider.dart'; + +class _FakeConnector extends MeshCoreConnector { + _FakeConnector(this.hopContacts); + + final List hopContacts; + + @override + List get allContacts => hopContacts; + + @override + double? get selfLatitude => null; + + @override + double? get selfLongitude => null; +} + +void main() { + testWidgets('hop avatars use the repeater name or the hex prefix', ( + tester, + ) async { + final connector = _FakeConnector([ + Contact( + publicKey: Uint8List(32)..first = 0xAA, + name: '(Base) Hilltop', + type: advTypeRepeater, + pathLength: 0, + path: Uint8List(0), + lastSeen: DateTime.utc(2026), + ), + ]); + final message = ChannelMessage( + senderName: 'Alice', + text: 'hello', + timestamp: DateTime.utc(2026), + isOutgoing: false, + pathBytes: Uint8List.fromList([0xAA, 0xBC]), + channelIndex: 0, + ); + + await tester.pumpWidget( + ChangeNotifierProvider.value( + value: connector, + child: MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + home: ChannelMessagePathScreen( + message: message, + channelMessage: true, + ), + ), + ), + ); + await tester.pumpAndSettle(); + + final avatarNames = tester + .widgetList(find.byType(AvatarCircle)) + .map((avatar) => avatar.name) + .toList(); + expect(avatarNames, containsAll(['(Base) Hilltop', 'BC'])); + expect( + find.descendant(of: find.byType(AvatarCircle), matching: find.text('BH')), + findsOneWidget, + ); + expect( + find.descendant( + of: find.byType(AvatarCircle), + matching: find.textContaining('('), + ), + findsNothing, + ); + }); +} diff --git a/test/screens/chat_bubble_width_test.dart b/test/screens/chat_bubble_width_test.dart new file mode 100644 index 00000000..e8e6cfc3 --- /dev/null +++ b/test/screens/chat_bubble_width_test.dart @@ -0,0 +1,321 @@ +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/screens/channel_chat_screen.dart'; +import 'package:meshcore_open/screens/chat_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/utils/platform_info.dart'; +import 'package:meshcore_open/widgets/message_bubble_frame.dart'; + +final _radioKey = Uint8List.fromList(List.generate(32, (i) => 0xA0 + i)); +final _radioHex = pubKeyToHex(_radioKey); +final _aliceKey = Uint8List.fromList(List.generate(32, (i) => 0x10 + i)); +final _psk = Uint8List.fromList(List.generate(16, (i) => 0x40 + i)); + +const _long = + 'The ridge trail is washed out past the second bridge, so take the ' + 'lower path along the river and meet us at the old ranger station.'; + +/// Shows the saved radio as connected or offline without a transport, so +/// both states render exactly the same stored transcript. +class _ToggleConnector extends MeshCoreConnector { + bool connected = false; + + @override + bool get isConnected => connected; +} + +DateTime _at(int seconds) => + DateTime.fromMillisecondsSinceEpoch(1700000000000 + seconds * 1000); + +Future _seedRadio() async { + final alice = Contact( + publicKey: _aliceKey, + name: 'Alice', + type: advTypeChat, + pathLength: 1, + path: Uint8List.fromList([0x22]), + lastSeen: _at(0), + ); + 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!}); + + ChannelMessage channelMessage( + int second, + String text, { + required bool outgoing, + String? translated, + }) => ChannelMessage( + senderName: outgoing ? 'Base' : 'Bob', + text: text, + translatedText: translated, + timestamp: _at(second), + isOutgoing: outgoing, + status: ChannelMessageStatus.sent, + channelIndex: 0, + ); + await (ChannelMessageStore()..setPublicKeyHex = _radioHex) + .saveChannelMessages(channel.storageId!, [ + channelMessage(1, 'ok', outgoing: false), + channelMessage(2, _long, outgoing: false), + channelMessage(3, 'on my way', outgoing: true), + channelMessage(4, _long, outgoing: true), + channelMessage( + 5, + 'Der Weg ist frei', + outgoing: false, + translated: 'The path is clear', + ), + ]); + + Message directMessage( + int second, + String text, { + required bool outgoing, + String? translated, + }) => Message( + senderKey: _aliceKey, + text: text, + translatedText: translated, + timestamp: _at(second), + isOutgoing: outgoing, + status: MessageStatus.delivered, + ); + await (MessageStore()..setPublicKeyHex = _radioHex) + .saveMessages(alice.publicKeyHex, [ + directMessage(1, 'hi', outgoing: false), + directMessage(2, _long, outgoing: false), + directMessage(3, 'see you', outgoing: true), + directMessage(4, _long, outgoing: true), + directMessage( + 5, + 'Der Weg ist frei', + outgoing: false, + translated: 'The path is clear', + ), + ]); + await LastRadioStore().save( + LastRadio( + publicKeyHex: _radioHex, + name: 'Base', + transport: LastRadio.transportBle, + bleRemoteId: 'AA:BB:CC:DD:EE:FF', + savedAt: _at(0), + ), + ); +} + +Future _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 _settle(WidgetTester tester) async { + for (var i = 0; i < 10; i++) { + await tester.pump(const Duration(milliseconds: 100)); + } +} + +/// Horizontal extent of every rendered bubble, in transcript order. +List _bubbleExtents(WidgetTester tester) { + final frames = find.byType(MessageBubbleFrame); + expect(frames, findsWidgets); + return [ + for (final element in frames.evaluate()) + () { + final rect = tester.getRect(find.byWidget(element.widget)); + return '${rect.left.toStringAsFixed(1)}..' + '${rect.right.toStringAsFixed(1)}'; + }(), + ]; +} + +Future> _render( + WidgetTester tester, + _ToggleConnector connector, + Widget Function() screen, { + required bool connected, +}) async { + connector.connected = connected; + await tester.pumpWidget(await _app(tester, connector, screen())); + await _settle(tester); + final extents = _bubbleExtents(tester); + await tester.pumpWidget(const SizedBox()); + await tester.pump(const Duration(seconds: 1)); + return extents; +} + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + final tempDir = Directory.systemTemp.createTempSync('bubble_width_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(); + }); + + // On phones, incoming channel bubbles are swipeable (reply) only while + // connected; that must not change their size or position. Day separators + // and bubbles must also fit 320dp at large text sizes. + for (final desktop in [false, true]) { + for (final scale in [1.0, 1.3, 2.0]) { + final label = '${desktop ? 'desktop' : 'phone'}, 320dp, ${scale}x text'; + + testWidgets('channel bubbles match connected vs offline ($label)', ( + tester, + ) async { + PlatformInfo.debugIsDesktopOverride = desktop; + addTearDown(() => PlatformInfo.debugIsDesktopOverride = null); + tester.view.physicalSize = const Size(320, 4000); + tester.view.devicePixelRatio = 1; + tester.platformDispatcher.textScaleFactorTestValue = scale; + addTearDown(tester.view.reset); + addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); + + final connector = _ToggleConnector(); + addTearDown(connector.dispose); + await tester.runAsync(connector.restoreLastRadio); + final channel = connector.channels.single; + + final offline = await _render( + tester, + connector, + () => ChannelChatScreen(channel: channel), + connected: false, + ); + final connected = await _render( + tester, + connector, + () => ChannelChatScreen(channel: channel), + connected: true, + ); + expect(offline, hasLength(5)); + expect(connected, offline); + }); + + testWidgets('DM bubbles match connected vs offline ($label)', ( + tester, + ) async { + PlatformInfo.debugIsDesktopOverride = desktop; + addTearDown(() => PlatformInfo.debugIsDesktopOverride = null); + tester.view.physicalSize = const Size(320, 4000); + tester.view.devicePixelRatio = 1; + tester.platformDispatcher.textScaleFactorTestValue = scale; + addTearDown(tester.view.reset); + addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); + + final connector = _ToggleConnector(); + addTearDown(connector.dispose); + await tester.runAsync(connector.restoreLastRadio); + final alice = connector.contacts.single; + + final offline = await _render( + tester, + connector, + () => ChatScreen(contact: alice), + connected: false, + ); + final connected = await _render( + tester, + connector, + () => ChatScreen(contact: alice), + connected: true, + ); + expect(offline, hasLength(5)); + expect(connected, offline); + }); + } + } +} diff --git a/test/screens/map_rebuild_scope_test.dart b/test/screens/map_rebuild_scope_test.dart index 03c94d08..200db19e 100644 --- a/test/screens/map_rebuild_scope_test.dart +++ b/test/screens/map_rebuild_scope_test.dart @@ -95,7 +95,11 @@ void main() { viewState.dispose(); }); - Future openMap(WidgetTester tester) async { + Future openMap( + WidgetTester tester, { + ThemeMode themeMode = ThemeMode.light, + LatLng? highlight, + }) async { await tester.pumpWidget( MultiProvider( providers: [ @@ -107,9 +111,11 @@ void main() { ], child: MaterialApp( theme: MeshTheme.light(), + darkTheme: MeshTheme.dark(), + themeMode: themeMode, localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, - home: const MapScreen(), + home: MapScreen(highlightPosition: highlight), ), ), ); @@ -185,4 +191,55 @@ void main() { expect(markerPoints(tester), contains(const LatLng(35, -112))); await tester.pumpWidget(const SizedBox.shrink()); }); + + testWidgets('node labels follow a system light/dark switch', (tester) async { + addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue); + tester.platformDispatcher.platformBrightnessTestValue = Brightness.light; + connector.nodes = [_node()]; + // Zoomed in past the label threshold so node names are drawn. + await openMap( + tester, + themeMode: ThemeMode.system, + highlight: const LatLng(35, -112), + ); + + Color? labelColor() => tester + .widget( + find.descendant( + of: find.byType(MarkerLayer), + matching: find.text('Repeater'), + ), + ) + .style + ?.color; + + expect(labelColor(), MeshTheme.light().colorScheme.onSurface); + + tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark; + await tester.pumpAndSettle(); + expect(labelColor(), MapPalette.textPrimary); + + tester.platformDispatcher.platformBrightnessTestValue = Brightness.light; + await tester.pumpAndSettle(); + expect(labelColor(), MeshTheme.light().colorScheme.onSurface); + await tester.pumpWidget(const SizedBox.shrink()); + }); + + testWidgets('a fixed light theme ignores the system switch', (tester) async { + addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue); + tester.platformDispatcher.platformBrightnessTestValue = Brightness.light; + connector.nodes = [_node()]; + await openMap(tester, highlight: const LatLng(35, -112)); + + tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark; + await tester.pumpAndSettle(); + final label = tester.widget( + find.descendant( + of: find.byType(MarkerLayer), + matching: find.text('Repeater'), + ), + ); + expect(label.style?.color, MeshTheme.light().colorScheme.onSurface); + await tester.pumpWidget(const SizedBox.shrink()); + }); } diff --git a/test/widgets/avatar_initials_test.dart b/test/widgets/avatar_initials_test.dart new file mode 100644 index 00000000..9d09d163 --- /dev/null +++ b/test/widgets/avatar_initials_test.dart @@ -0,0 +1,73 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:meshcore_open/widgets/contact_visuals.dart'; +import 'package:meshcore_open/widgets/mesh_ui.dart'; + +void main() { + group('avatarInitials', () { + test('empty and whitespace-only names have no initials', () { + expect(avatarInitials(''), isNull); + expect(avatarInitials(' '), isNull); + }); + + test('punctuation-only names have no initials', () { + expect(avatarInitials('-'), isNull); + expect(avatarInitials('(--) [ ]'), isNull); + }); + + test('punctuation never becomes an initial', () { + expect(avatarInitials('(Base) Node'), 'BN'); + expect(avatarInitials('- Relay'), 'RE'); + expect(avatarInitials('[AB12] Hilltop'), 'AH'); + expect(avatarInitials('Node-1'), 'N1'); + }); + + test('plain names keep the existing two-letter shape', () { + expect(avatarInitials('Alice Smith'), 'AS'); + expect(avatarInitials('tower'), 'TO'); + expect(avatarInitials('A1B2C3D4'), 'A1'); + }); + + test('Cyrillic names use their letters', () { + expect(avatarInitials('Иван Петров'), 'ИП'); + expect(avatarInitials('(ретранслятор)'), 'РЕ'); + }); + + test('CJK names use their characters', () { + expect(avatarInitials('東京 中継'), '東中'); + expect(avatarInitials('「大阪」'), '大阪'); + }); + + test('emoji is kept whole and skipped when letters exist', () { + expect(avatarInitials('🔥 Fire Node'), 'FN'); + expect(avatarInitials('Fire🔥Node'), 'FN'); + expect(avatarInitials('🔥'), '🔥'); + expect(avatarInitials('👨‍👩‍👧 -'), '👨‍👩‍👧'); + }); + + test('combining accents stay with their letter', () { + expect(avatarInitials('école'), 'ÉC'); + }); + }); + + testWidgets('AvatarCircle shows an icon when the name has no initials', ( + tester, + ) async { + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: Column( + children: [ + AvatarCircle(name: '(--)'), + AvatarCircle(name: '(Base) Node'), + ], + ), + ), + ), + ); + + expect(find.byIcon(Icons.person_outline), findsOneWidget); + expect(find.text('BN'), findsOneWidget); + expect(find.textContaining('('), findsNothing); + }); +} From b649d8373d2808ff2d318ab15f0335d560199e32 Mon Sep 17 00:00:00 2001 From: zjs81 <30362347+zjs81@users.noreply.github.com> Date: Sat, 21 Nov 2026 02:41:05 -0700 Subject: [PATCH 2/2] Wrap channel bubble metadata row on narrow screens --- lib/screens/channel_chat_screen.dart | 47 ++++++++++++------------ test/screens/chat_bubble_width_test.dart | 5 ++- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index f552dd3d..2fac04d9 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -1423,8 +1423,10 @@ class _ChannelChatScreenState extends State { bottom: 4, ) : EdgeInsets.zero, - child: Row( - mainAxisSize: MainAxisSize.min, + child: Wrap( + spacing: 4, + runSpacing: 2, + crossAxisAlignment: WrapCrossAlignment.center, children: [ Text( formatChatTime(context, message.timestamp), @@ -1433,30 +1435,30 @@ class _ChannelChatScreenState extends State { color: metaColor, ), ), - if (message.hasFutureTimestamp) ...[ - const SizedBox(width: 4), + if (message.hasFutureTimestamp) FutureTimestampIndicator(size: 16 * textScale), - ], if (enableTracing && !isOutgoing && - message.repeatCount > 0) ...[ - const SizedBox(width: 6), - Icon( - Icons.repeat, - size: 14 * textScale, - color: metaColor, + message.repeatCount > 0) + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + Icons.repeat, + size: 14 * textScale, + color: metaColor, + ), + const SizedBox(width: 2), + Text( + '${message.repeatCount}', + style: MeshTheme.mono( + fontSize: 12 * textScale, + color: metaColor, + ), + ), + ], ), - const SizedBox(width: 2), - Text( - '${message.repeatCount}', - style: MeshTheme.mono( - fontSize: 12 * textScale, - color: metaColor, - ), - ), - ], - if (isOutgoing) ...[ - const SizedBox(width: 4), + if (isOutgoing) MessageStatusIcon( size: 16 * textScale, isAcked: false, @@ -1476,7 +1478,6 @@ class _ChannelChatScreenState extends State { ChannelMessageStatus.failed, onColor: metaColor, ), - ], ], ), ), diff --git a/test/screens/chat_bubble_width_test.dart b/test/screens/chat_bubble_width_test.dart index e8e6cfc3..5f17945a 100644 --- a/test/screens/chat_bubble_width_test.dart +++ b/test/screens/chat_bubble_width_test.dart @@ -58,8 +58,9 @@ class _ToggleConnector extends MeshCoreConnector { bool get isConnected => connected; } -DateTime _at(int seconds) => - DateTime.fromMillisecondsSinceEpoch(1700000000000 + seconds * 1000); +// Two-digit local hour (10:13 PM / 22:13) so narrow 2.0x text checks the wide +// timestamp layout regardless of host timezone. +DateTime _at(int seconds) => DateTime(2023, 11, 14, 22, 13, seconds); Future _seedRadio() async { final alice = Contact(