Merge origin/dev into fix/visual-consistency
This commit is contained in:
commit
96b8ff5cf7
85 files changed
+8433
-1331
No files matched your search
@@ -0,0 +1,584 @@
|
||||
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: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/custom_theme.dart';
|
||||
import 'package:meshcore_open/models/message.dart';
|
||||
import 'package:meshcore_open/screens/app_settings_screen.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/history_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/message_bubble_frame.dart';
|
||||
import 'package:meshcore_open/widgets/message_status_icon.dart';
|
||||
import 'package:provider/provider.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));
|
||||
final _l10n = lookupAppLocalizations(const Locale('en'));
|
||||
|
||||
Future<void> _seedMessages() 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 (MessageStore()..setPublicKeyHex = _radioHex)
|
||||
.saveMessages(alice.publicKeyHex, [
|
||||
Message(
|
||||
senderKey: _aliceKey,
|
||||
text: 'DM incoming compressed',
|
||||
timestamp: DateTime(2026, 11, 21, 10, 11),
|
||||
receivedAt: DateTime(2026, 11, 21, 10, 11),
|
||||
isOutgoing: false,
|
||||
isSmazCompressed: true,
|
||||
status: MessageStatus.delivered,
|
||||
),
|
||||
Message(
|
||||
senderKey: _aliceKey,
|
||||
text: 'DM incoming plain',
|
||||
timestamp: DateTime(2026, 11, 21, 10, 12),
|
||||
receivedAt: DateTime(2026, 11, 21, 10, 12),
|
||||
isOutgoing: false,
|
||||
isSmazCompressed: false,
|
||||
status: MessageStatus.delivered,
|
||||
),
|
||||
Message(
|
||||
senderKey: _aliceKey,
|
||||
text: 'DM outgoing plain',
|
||||
timestamp: DateTime(2026, 11, 21, 10, 13),
|
||||
receivedAt: DateTime(2026, 11, 21, 10, 13),
|
||||
isOutgoing: true,
|
||||
isSmazCompressed: false,
|
||||
status: MessageStatus.delivered,
|
||||
),
|
||||
Message(
|
||||
senderKey: _aliceKey,
|
||||
text: 'DM outgoing compressed',
|
||||
timestamp: DateTime(2026, 11, 21, 10, 14),
|
||||
receivedAt: DateTime(2026, 11, 21, 10, 14),
|
||||
isOutgoing: true,
|
||||
isSmazCompressed: true,
|
||||
status: MessageStatus.delivered,
|
||||
),
|
||||
]);
|
||||
|
||||
await (ChannelMessageStore()..setPublicKeyHex = _radioHex)
|
||||
.saveChannelMessages(channel.storageId!, [
|
||||
ChannelMessage(
|
||||
senderName: 'Bob',
|
||||
text: 'Channel incoming compressed',
|
||||
timestamp: DateTime(2026, 11, 21, 11, 11),
|
||||
receivedAt: DateTime(2026, 11, 21, 11, 11),
|
||||
isOutgoing: false,
|
||||
isSmazCompressed: true,
|
||||
status: ChannelMessageStatus.sent,
|
||||
channelIndex: 0,
|
||||
),
|
||||
ChannelMessage(
|
||||
senderName: 'Bob',
|
||||
text: 'Channel incoming plain',
|
||||
timestamp: DateTime(2026, 11, 21, 11, 12),
|
||||
receivedAt: DateTime(2026, 11, 21, 11, 12),
|
||||
isOutgoing: false,
|
||||
isSmazCompressed: false,
|
||||
status: ChannelMessageStatus.sent,
|
||||
channelIndex: 0,
|
||||
),
|
||||
ChannelMessage(
|
||||
senderName: 'Me',
|
||||
text: 'Channel outgoing plain',
|
||||
timestamp: DateTime(2026, 11, 21, 11, 13),
|
||||
receivedAt: DateTime(2026, 11, 21, 11, 13),
|
||||
isOutgoing: true,
|
||||
isSmazCompressed: false,
|
||||
repeatCount: 1,
|
||||
status: ChannelMessageStatus.sent,
|
||||
channelIndex: 0,
|
||||
),
|
||||
ChannelMessage(
|
||||
senderName: 'Me',
|
||||
text: 'Channel outgoing compressed',
|
||||
timestamp: DateTime(2026, 11, 21, 11, 14),
|
||||
receivedAt: DateTime(2026, 11, 21, 11, 14),
|
||||
isOutgoing: true,
|
||||
isSmazCompressed: true,
|
||||
repeatCount: 2,
|
||||
status: ChannelMessageStatus.sent,
|
||||
channelIndex: 0,
|
||||
),
|
||||
]);
|
||||
|
||||
await LastRadioStore().save(
|
||||
LastRadio(
|
||||
publicKeyHex: _radioHex,
|
||||
name: 'Base',
|
||||
transport: LastRadio.transportBle,
|
||||
bleRemoteId: 'AA:BB:CC:DD:EE:FF',
|
||||
savedAt: DateTime.fromMillisecondsSinceEpoch(1700000000000),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _Harness {
|
||||
final MeshCoreConnector connector;
|
||||
final AppSettingsService settings;
|
||||
final List<dynamic> disposables;
|
||||
|
||||
_Harness(this.connector, this.settings, this.disposables);
|
||||
|
||||
List<ChangeNotifierProvider<ChangeNotifier>> get _unused => const [];
|
||||
|
||||
Widget wrap(Widget home, {ThemeData? theme, double textScale = 1.0}) {
|
||||
final storage = StorageService();
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[0] as MessageRetryService,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[1] as PathHistoryService,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[2] as BleDebugLogService,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[3] as AppDebugLogService,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[4] as ChatTextScaleService,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[5] as TranslationService,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[6] as UiViewStateService,
|
||||
),
|
||||
Provider.value(value: storage),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[7] as MapTileCacheService,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[8] as TimeoutPredictionService,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[9] as ImageCodecService,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[10] as ReceivedImageStore,
|
||||
),
|
||||
ChangeNotifierProvider.value(
|
||||
value: disposables[11] as NetworkMapUploadService,
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: theme ?? MeshTheme.light(),
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaler: TextScaler.linear(textScale),
|
||||
alwaysUse24HourFormat: true,
|
||||
),
|
||||
child: child!,
|
||||
),
|
||||
home: home,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
assert(_unused.isEmpty);
|
||||
connector.dispose();
|
||||
settings.dispose();
|
||||
for (final d in disposables) {
|
||||
if (d is ChangeNotifier) d.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<_Harness> _createHarness({bool showIndicator = false}) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
HistoryStore.reset();
|
||||
MessageStore().forgetArchive();
|
||||
ChannelMessageStore().forgetArchive();
|
||||
await _seedMessages();
|
||||
|
||||
final storage = StorageService();
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
if (showIndicator) {
|
||||
await settings.setShowCompressionIndicator(true);
|
||||
}
|
||||
final connector = MeshCoreConnector();
|
||||
final retry = MessageRetryService();
|
||||
final pathHistory = PathHistoryService(storage);
|
||||
final bleLog = BleDebugLogService();
|
||||
final appLog = AppDebugLogService();
|
||||
final textScale = ChatTextScaleService();
|
||||
final translation = TranslationService(settings);
|
||||
final uiView = UiViewStateService();
|
||||
final tileCache = MapTileCacheService(appSettingsService: settings);
|
||||
final timeoutPred = TimeoutPredictionService(storage);
|
||||
final imageCodec = ImageCodecService(settings);
|
||||
final receivedImage = ReceivedImageStore();
|
||||
final networkMap = NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
);
|
||||
await connector.restoreLastRadio();
|
||||
return _Harness(connector, settings, [
|
||||
retry,
|
||||
pathHistory,
|
||||
bleLog,
|
||||
appLog,
|
||||
textScale,
|
||||
translation,
|
||||
uiView,
|
||||
tileCache,
|
||||
timeoutPred,
|
||||
imageCodec,
|
||||
receivedImage,
|
||||
networkMap,
|
||||
]);
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final tempDir = Directory.systemTemp.createTempSync(
|
||||
'compression_indicator_test',
|
||||
);
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('plugins.flutter.io/path_provider'),
|
||||
(call) async => tempDir.path,
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'AppSettingsScreen shows Compression indicator switch and toggles',
|
||||
(tester) async {
|
||||
late _Harness harness;
|
||||
await tester.runAsync(() async {
|
||||
harness = await _createHarness();
|
||||
await harness.settings.setAutoRouteRotationEnabled(false);
|
||||
});
|
||||
addTearDown(harness.dispose);
|
||||
|
||||
tester.view.physicalSize = const Size(390, 720);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
await tester.pumpWidget(harness.wrap(const AppSettingsScreen()));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final tileFinder = find.widgetWithText(
|
||||
SwitchListTile,
|
||||
_l10n.appSettings_showCompressionIndicator,
|
||||
);
|
||||
await tester.scrollUntilVisible(
|
||||
tileFinder,
|
||||
60,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final tile = tester.widget<SwitchListTile>(tileFinder);
|
||||
expect(tile.value, isFalse);
|
||||
expect(
|
||||
find.descendant(of: tileFinder, matching: find.byIcon(Icons.compress)),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(tileFinder);
|
||||
await tester.pumpAndSettle();
|
||||
expect(harness.settings.settings.showCompressionIndicator, isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'DM ChatScreen hides icon when off, shows only on compressed when on',
|
||||
(tester) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
try {
|
||||
late _Harness harness;
|
||||
await tester.runAsync(() async {
|
||||
harness = await _createHarness(showIndicator: false);
|
||||
});
|
||||
addTearDown(harness.dispose);
|
||||
|
||||
final contact = harness.connector.contacts.first;
|
||||
await tester.pumpWidget(harness.wrap(ChatScreen(contact: contact)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CompressionIndicator), findsNothing);
|
||||
|
||||
await tester.runAsync(
|
||||
() => harness.settings.setShowCompressionIndicator(true),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Two compressed messages (1 incoming, 1 outgoing); two plain have none.
|
||||
expect(find.byType(CompressionIndicator), findsNWidgets(2));
|
||||
expect(
|
||||
find.byTooltip(_l10n.messageMeta_smazCompressed),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
expect(
|
||||
find.bySemanticsLabel(RegExp(_l10n.messageMeta_smazCompressed)),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
|
||||
// Incoming compressed message: CompressionIndicator sits after timestamp, no ticks.
|
||||
final incomingBubble = find.ancestor(
|
||||
of: find.text('DM incoming compressed'),
|
||||
matching: find.byType(MessageBubbleFrame),
|
||||
);
|
||||
final incomingIndicator = find.descendant(
|
||||
of: incomingBubble,
|
||||
matching: find.byType(CompressionIndicator),
|
||||
);
|
||||
final incomingTime = find.descendant(
|
||||
of: incomingBubble,
|
||||
matching: find.text('10:11'),
|
||||
);
|
||||
expect(incomingIndicator, findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(incomingIndicator).dx,
|
||||
greaterThan(tester.getTopRight(incomingTime).dx),
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: incomingBubble,
|
||||
matching: find.byType(MessageStatusIcon),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
|
||||
// Outgoing compressed message: CompressionIndicator sits between timestamp and ticks.
|
||||
final outgoingBubble = find.ancestor(
|
||||
of: find.text('DM outgoing compressed'),
|
||||
matching: find.byType(MessageBubbleFrame),
|
||||
);
|
||||
final outgoingIndicator = find.descendant(
|
||||
of: outgoingBubble,
|
||||
matching: find.byType(CompressionIndicator),
|
||||
);
|
||||
final outgoingTime = find.descendant(
|
||||
of: outgoingBubble,
|
||||
matching: find.text('10:14'),
|
||||
);
|
||||
final outgoingTicks = find.descendant(
|
||||
of: outgoingBubble,
|
||||
matching: find.byType(MessageStatusIcon),
|
||||
);
|
||||
expect(outgoingIndicator, findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(outgoingIndicator).dx,
|
||||
greaterThan(tester.getTopRight(outgoingTime).dx),
|
||||
);
|
||||
expect(
|
||||
tester.getTopRight(outgoingIndicator).dx,
|
||||
lessThanOrEqualTo(tester.getTopLeft(outgoingTicks).dx),
|
||||
);
|
||||
|
||||
// Plain messages never show the icon.
|
||||
final plainBubble = find.ancestor(
|
||||
of: find.text('DM outgoing plain'),
|
||||
matching: find.byType(MessageBubbleFrame),
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: plainBubble,
|
||||
matching: find.byType(CompressionIndicator),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
} finally {
|
||||
semantics.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'ChannelChatScreen hides icon when off, shows between time and ticks when on',
|
||||
(tester) async {
|
||||
late _Harness harness;
|
||||
await tester.runAsync(() async {
|
||||
harness = await _createHarness(showIndicator: false);
|
||||
});
|
||||
addTearDown(harness.dispose);
|
||||
|
||||
final channel = harness.connector.channels.first;
|
||||
await tester.pumpWidget(
|
||||
harness.wrap(ChannelChatScreen(channel: channel)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CompressionIndicator), findsNothing);
|
||||
|
||||
await tester.runAsync(
|
||||
() => harness.settings.setShowCompressionIndicator(true),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CompressionIndicator), findsNWidgets(2));
|
||||
|
||||
// Outgoing compressed channel message: icon between timestamp and repeat ticks.
|
||||
final outgoingBubble = find.ancestor(
|
||||
of: find.text('Channel outgoing compressed'),
|
||||
matching: find.byType(MessageBubbleFrame),
|
||||
);
|
||||
final outgoingIndicator = find.descendant(
|
||||
of: outgoingBubble,
|
||||
matching: find.byType(CompressionIndicator),
|
||||
);
|
||||
final outgoingTime = find.descendant(
|
||||
of: outgoingBubble,
|
||||
matching: find.text('11:14'),
|
||||
);
|
||||
final outgoingTicks = find.descendant(
|
||||
of: outgoingBubble,
|
||||
matching: find.byType(MessageStatusIcon),
|
||||
);
|
||||
expect(outgoingIndicator, findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(outgoingIndicator).dx,
|
||||
greaterThan(tester.getTopRight(outgoingTime).dx),
|
||||
);
|
||||
expect(
|
||||
tester.getTopRight(outgoingIndicator).dx,
|
||||
lessThanOrEqualTo(tester.getTopLeft(outgoingTicks).dx),
|
||||
);
|
||||
|
||||
// Incoming compressed channel message: icon right after timestamp.
|
||||
final incomingBubble = find.ancestor(
|
||||
of: find.text('Channel incoming compressed'),
|
||||
matching: find.byType(MessageBubbleFrame),
|
||||
);
|
||||
final incomingIndicator = find.descendant(
|
||||
of: incomingBubble,
|
||||
matching: find.byType(CompressionIndicator),
|
||||
);
|
||||
final incomingTime = find.descendant(
|
||||
of: incomingBubble,
|
||||
matching: find.text('11:11'),
|
||||
);
|
||||
expect(incomingIndicator, findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(incomingIndicator).dx,
|
||||
greaterThan(tester.getTopRight(incomingTime).dx),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('No overflow at 320dp width and 2.0x text scale across themes', (
|
||||
tester,
|
||||
) async {
|
||||
late _Harness harness;
|
||||
await tester.runAsync(() async {
|
||||
harness = await _createHarness(showIndicator: true);
|
||||
});
|
||||
addTearDown(harness.dispose);
|
||||
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final overflows = <String>[];
|
||||
final previous = FlutterError.onError;
|
||||
FlutterError.onError = (details) {
|
||||
final text = details.exceptionAsString();
|
||||
if (text.contains('overflowed')) {
|
||||
overflows.add(text.split('\n').first);
|
||||
} else {
|
||||
previous?.call(details);
|
||||
}
|
||||
};
|
||||
addTearDown(() => FlutterError.onError = previous);
|
||||
|
||||
final contact = harness.connector.contacts.first;
|
||||
final channel = harness.connector.channels.first;
|
||||
|
||||
final themes = [
|
||||
MeshTheme.light(),
|
||||
MeshTheme.dark(),
|
||||
MeshTheme.fromCustom(CustomTheme.presets.first),
|
||||
];
|
||||
|
||||
for (final theme in themes) {
|
||||
await tester.pumpWidget(
|
||||
harness.wrap(
|
||||
ChatScreen(contact: contact),
|
||||
theme: theme,
|
||||
textScale: 2.0,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(CompressionIndicator), findsAtLeastNWidgets(1));
|
||||
|
||||
await tester.pumpWidget(
|
||||
harness.wrap(
|
||||
ChannelChatScreen(channel: channel),
|
||||
theme: theme,
|
||||
textScale: 2.0,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(CompressionIndicator), findsAtLeastNWidgets(1));
|
||||
}
|
||||
|
||||
FlutterError.onError = previous;
|
||||
expect(overflows, isEmpty, reason: overflows.join('\n'));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,831 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/image_codec_support.dart';
|
||||
import 'package:meshcore_open/models/translation_support.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/image_codec_service.dart';
|
||||
import 'package:meshcore_open/services/image_codec_settings_store.dart';
|
||||
import 'package:meshcore_open/services/translation_file_store.dart';
|
||||
import 'package:meshcore_open/services/translation_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/widgets/image_codec_models_section.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_nav_tile.dart';
|
||||
import 'package:meshcore_open/widgets/model_download_list.dart';
|
||||
import 'package:meshcore_open/widgets/settings_reveal.dart';
|
||||
import 'package:meshcore_open/widgets/translation_settings_section.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:provider/single_child_widget.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class _MemoryTranslationFileStore extends TranslationFileStore {
|
||||
final Map<String, int> _files = {};
|
||||
|
||||
@override
|
||||
Future<String> modelDirectoryPath() async => '/memory/translation_models';
|
||||
|
||||
@override
|
||||
Future<List<TranslationModelRecord>> scanDownloadedModels() async => const [];
|
||||
|
||||
@override
|
||||
Future<void> deleteModel(TranslationModelRecord model) async {
|
||||
_files.remove(model.localPath);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteFile(String path) async {
|
||||
_files.remove(path);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DownloadedModelFile> writeModelBytes({
|
||||
required String fileName,
|
||||
required Stream<List<int>> chunks,
|
||||
}) async {
|
||||
var total = 0;
|
||||
await for (final chunk in chunks) {
|
||||
total += chunk.length;
|
||||
}
|
||||
final path = '/memory/translation_models/$fileName';
|
||||
_files[path] = total;
|
||||
return DownloadedModelFile(localPath: path, fileSizeBytes: total);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
Future<void> pump(
|
||||
WidgetTester tester,
|
||||
Widget home, {
|
||||
List<SingleChildWidget> providers = const [],
|
||||
double textScale = 1,
|
||||
Size size = const Size(400, 900),
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final app = MaterialApp(
|
||||
theme: MeshTheme.dark(),
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: child!,
|
||||
),
|
||||
home: Scaffold(body: SingleChildScrollView(child: home)),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
providers.isEmpty ? app : MultiProvider(providers: providers, child: app),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('rows share name, size, status and one action', (tester) async {
|
||||
var downloaded = 0;
|
||||
var cancelled = 0;
|
||||
var removed = 0;
|
||||
var selected = 0;
|
||||
await pump(
|
||||
tester,
|
||||
ModelDownloadList(
|
||||
items: [
|
||||
ModelDownloadItem(
|
||||
id: 'new',
|
||||
name: 'Preset model',
|
||||
sizeBytes: 958 * 1024 * 1024,
|
||||
status: ModelDownloadStatus.notDownloaded,
|
||||
onDownload: () => downloaded++,
|
||||
),
|
||||
ModelDownloadItem(
|
||||
id: 'busy',
|
||||
name: 'Preset model',
|
||||
sizeBytes: 958 * 1024 * 1024,
|
||||
status: ModelDownloadStatus.downloading,
|
||||
progress: 0.4,
|
||||
downloadedBytes: 400 * 1024 * 1024,
|
||||
totalBytes: 958 * 1024 * 1024,
|
||||
onCancel: () => cancelled++,
|
||||
),
|
||||
ModelDownloadItem(
|
||||
id: 'ready',
|
||||
name: 'Installed model',
|
||||
sizeBytes: 1100 * 1024 * 1024,
|
||||
status: ModelDownloadStatus.ready,
|
||||
selected: true,
|
||||
onDelete: () => removed++,
|
||||
onSelect: () => selected++,
|
||||
),
|
||||
ModelDownloadItem(
|
||||
id: 'bad',
|
||||
name: 'Broken model',
|
||||
status: ModelDownloadStatus.error,
|
||||
detail: 'HTTP 404',
|
||||
onDownload: () => downloaded++,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.textContaining('958 MB'), findsWidgets);
|
||||
expect(find.textContaining('Not downloaded'), findsOneWidget);
|
||||
expect(find.textContaining('Downloading'), findsOneWidget);
|
||||
expect(find.textContaining('Ready'), findsOneWidget);
|
||||
expect(find.textContaining('Active'), findsOneWidget);
|
||||
expect(find.textContaining("Couldn't download"), findsOneWidget);
|
||||
expect(find.text('HTTP 404'), findsOneWidget);
|
||||
expect(find.textContaining('400.0 / 958.0 MB (40%)'), findsOneWidget);
|
||||
expect(find.byType(LinearProgressIndicator), findsOneWidget);
|
||||
expect(find.textContaining('http'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('model-download-new')));
|
||||
await tester.tap(find.byKey(const ValueKey('model-cancel-busy')));
|
||||
await tester.tap(find.byKey(const ValueKey('model-remove-ready')));
|
||||
await tester.tap(find.text('Installed model'));
|
||||
expect(downloaded, 1);
|
||||
expect(cancelled, 1);
|
||||
expect(removed, 1);
|
||||
// The ready row is already selected, so onSelect is still wired here and
|
||||
// the row tap invokes it. Callers omit onSelect once it is active.
|
||||
expect(selected, 1);
|
||||
});
|
||||
|
||||
testWidgets('a long row wraps at 320dp and text scale 2', (tester) async {
|
||||
final overflows = <String>[];
|
||||
final previous = FlutterError.onError;
|
||||
FlutterError.onError = (details) {
|
||||
if (details.exceptionAsString().contains('overflowed')) {
|
||||
overflows.add(details.exceptionAsString().split('\n').first);
|
||||
return;
|
||||
}
|
||||
previous?.call(details);
|
||||
};
|
||||
addTearDown(() => FlutterError.onError = previous);
|
||||
|
||||
await pump(
|
||||
tester,
|
||||
ModelDownloadList(
|
||||
items: [
|
||||
ModelDownloadItem(
|
||||
id: 'long',
|
||||
name: 'Tencent HY-MT 1.5 1.8B Q4_K_M',
|
||||
sizeBytes: 1140000000,
|
||||
status: ModelDownloadStatus.downloading,
|
||||
progress: 0.2,
|
||||
downloadedBytes: 200 * 1024 * 1024,
|
||||
totalBytes: 1140000000,
|
||||
onCancel: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
textScale: 2,
|
||||
size: const Size(320, 568),
|
||||
);
|
||||
expect(overflows, isEmpty);
|
||||
expect(find.text('Tencent HY-MT 1.5 1.8B Q4_K_M'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('translation presets and installs share one list', (
|
||||
tester,
|
||||
) async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setTranslationEnabled(true);
|
||||
final preset = translationPresetModels.first;
|
||||
final other = translationPresetModels[1];
|
||||
await settings.setTranslationDownloadedModels([
|
||||
TranslationModelRecord(
|
||||
id: preset.id,
|
||||
name: preset.name,
|
||||
sourceUrl: preset.sourceUrl,
|
||||
localPath: '/tmp/model.gguf',
|
||||
downloadedAt: DateTime.utc(2026, 1, 1),
|
||||
fileSizeBytes: 1140000000,
|
||||
),
|
||||
TranslationModelRecord(
|
||||
id: other.id,
|
||||
name: other.name,
|
||||
sourceUrl: other.sourceUrl,
|
||||
localPath: '/tmp/other.gguf',
|
||||
downloadedAt: DateTime.utc(2026, 1, 2),
|
||||
fileSizeBytes: 1400 * 1024 * 1024,
|
||||
),
|
||||
]);
|
||||
await settings.setTranslationSelectedModelId(preset.id);
|
||||
final translation = TranslationService(settings);
|
||||
|
||||
await pump(
|
||||
tester,
|
||||
const TranslationSettingsSection(),
|
||||
providers: [
|
||||
ChangeNotifierProvider<AppSettingsService>.value(value: settings),
|
||||
ChangeNotifierProvider<TranslationService>.value(value: translation),
|
||||
],
|
||||
);
|
||||
|
||||
expect(find.text('Tencent HY-MT 1.5 1.8B Q4_K_M'), findsOneWidget);
|
||||
expect(find.text('Tencent HY-MT 1.5 1.8B Q6_K'), findsOneWidget);
|
||||
expect(find.textContaining('Ready'), findsNWidgets(2));
|
||||
expect(find.textContaining('Active'), findsOneWidget);
|
||||
expect(find.textContaining('Not downloaded'), findsNothing);
|
||||
expect(find.text('Downloaded model'), findsNothing);
|
||||
expect(find.text('Preset Hugging Face model'), findsNothing);
|
||||
expect(find.text('Manual model URL'), findsOneWidget);
|
||||
expect(find.textContaining('huggingface.co'), findsNothing);
|
||||
expect(find.textContaining('.gguf'), findsNothing);
|
||||
|
||||
await tester.tap(find.text('Tencent HY-MT 1.5 1.8B Q6_K'));
|
||||
await tester.pump();
|
||||
expect(settings.settings.translationSelectedModelId, other.id);
|
||||
|
||||
await tester.tap(find.byKey(ValueKey('model-remove-${preset.id}')));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
expect(
|
||||
settings.settings.translationDownloadedModels.map((model) => model.id),
|
||||
[other.id],
|
||||
);
|
||||
expect(find.textContaining('Not downloaded'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a custom download stays visible after settings is reopened', (
|
||||
tester,
|
||||
) async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setTranslationEnabled(true);
|
||||
final translation = TranslationService(settings);
|
||||
addTearDown(translation.dispose);
|
||||
// The page that started the download is gone. Only the service still
|
||||
// knows which file is in flight.
|
||||
translation.debugSetActiveDownload(
|
||||
sourceUrl: 'http://127.0.0.1/Tencent-demo.gguf',
|
||||
fileName: 'Tencent-demo.gguf',
|
||||
downloadedBytes: 400 * 1024,
|
||||
totalBytes: 1024 * 1024,
|
||||
);
|
||||
|
||||
final providers = <SingleChildWidget>[
|
||||
ChangeNotifierProvider<AppSettingsService>.value(value: settings),
|
||||
ChangeNotifierProvider<TranslationService>.value(value: translation),
|
||||
];
|
||||
await pump(
|
||||
tester,
|
||||
const TranslationSettingsSection(),
|
||||
providers: providers,
|
||||
);
|
||||
expect(find.text('Tencent-demo'), findsOneWidget);
|
||||
expect(find.textContaining('Downloading'), findsOneWidget);
|
||||
expect(find.textContaining('0.4 / 1.0 MB (39%)'), findsOneWidget);
|
||||
expect(find.byTooltip('Cancel'), findsOneWidget);
|
||||
|
||||
await pump(tester, const SizedBox.shrink(), providers: providers);
|
||||
await pump(
|
||||
tester,
|
||||
const TranslationSettingsSection(),
|
||||
providers: providers,
|
||||
);
|
||||
expect(find.text('Tencent-demo'), findsOneWidget);
|
||||
expect(find.textContaining('Downloading'), findsOneWidget);
|
||||
expect(find.byTooltip('Cancel'), findsOneWidget);
|
||||
expect(find.text('Tencent HY-MT 1.5 1.8B Q4_K_M'), findsOneWidget);
|
||||
|
||||
final preset = translationPresetModels.first;
|
||||
translation.debugSetActiveDownload(
|
||||
sourceUrl: preset.sourceUrl,
|
||||
fileName: preset.name,
|
||||
modelId: preset.id,
|
||||
displayedFileName: 'Merging chunks...',
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Tencent-demo'), findsNothing);
|
||||
expect(find.textContaining('Downloading'), findsOneWidget);
|
||||
expect(find.textContaining('Merging downloaded chunks'), findsOneWidget);
|
||||
expect(find.byTooltip('Cancel'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'reopening settings during a custom download supports cancel, completion, and failure',
|
||||
(tester) async {
|
||||
StreamController<List<int>>? getStream;
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setTranslationEnabled(true);
|
||||
final translation = TranslationService(
|
||||
settings,
|
||||
fileStore: _MemoryTranslationFileStore(),
|
||||
clientFactory: () => MockClient.streaming((request, _) async {
|
||||
if (request.method == 'HEAD') {
|
||||
return http.StreamedResponse(
|
||||
const Stream<List<int>>.empty(),
|
||||
200,
|
||||
contentLength: 1024,
|
||||
);
|
||||
}
|
||||
final controller = StreamController<List<int>>();
|
||||
getStream = controller;
|
||||
return http.StreamedResponse(
|
||||
controller.stream,
|
||||
200,
|
||||
contentLength: 1024,
|
||||
);
|
||||
}),
|
||||
);
|
||||
addTearDown(translation.dispose);
|
||||
|
||||
final providers = <SingleChildWidget>[
|
||||
ChangeNotifierProvider<AppSettingsService>.value(value: settings),
|
||||
ChangeNotifierProvider<TranslationService>.value(value: translation),
|
||||
];
|
||||
|
||||
Future<void> startCustomDownload(String url) async {
|
||||
await pump(
|
||||
tester,
|
||||
const TranslationSettingsSection(),
|
||||
providers: providers,
|
||||
);
|
||||
await tester.ensureVisible(find.byType(TextField));
|
||||
await tester.enterText(find.byType(TextField), url);
|
||||
await tester.pump();
|
||||
final urlFieldDownload = find.descendant(
|
||||
of: find.byType(TextField),
|
||||
matching: find.byTooltip('Download'),
|
||||
);
|
||||
await tester.ensureVisible(urlFieldDownload);
|
||||
await tester.tap(urlFieldDownload);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> leaveAndReopen() async {
|
||||
await pump(tester, const SizedBox.shrink(), providers: providers);
|
||||
await pump(
|
||||
tester,
|
||||
const TranslationSettingsSection(),
|
||||
providers: providers,
|
||||
);
|
||||
}
|
||||
|
||||
// 1. Cancel after reopen.
|
||||
await startCustomDownload('https://example.com/Custom-Cancel.gguf');
|
||||
await tester.pump(Duration.zero);
|
||||
getStream!.add(List<int>.filled(512, 1));
|
||||
await tester.pump(Duration.zero);
|
||||
expect(translation.downloadedBytes, 512);
|
||||
await leaveAndReopen();
|
||||
expect(find.text('Custom-Cancel'), findsOneWidget);
|
||||
expect(find.textContaining('Downloading'), findsOneWidget);
|
||||
expect(find.byTooltip('Cancel'), findsOneWidget);
|
||||
expect(
|
||||
find.byKey(
|
||||
ValueKey('model-download-${translationPresetModels.first.id}'),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(
|
||||
find.descendant(
|
||||
of: find.byType(TextField),
|
||||
matching: find.byType(IconButton),
|
||||
),
|
||||
)
|
||||
.onPressed,
|
||||
isNull,
|
||||
);
|
||||
|
||||
await tester.ensureVisible(find.byTooltip('Cancel'));
|
||||
await tester.tap(find.byTooltip('Cancel'));
|
||||
await tester.pump();
|
||||
expect(translation.lastError, 'Download stopped.');
|
||||
getStream!.add(List<int>.filled(16, 1));
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 20)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(translation.isDownloading, isFalse);
|
||||
expect(find.text('Custom-Cancel'), findsNothing);
|
||||
expect(find.text('Download stopped.'), findsNothing);
|
||||
|
||||
// 2. Complete after reopen.
|
||||
await startCustomDownload('https://example.com/Custom-Complete.gguf');
|
||||
await tester.pump(Duration.zero);
|
||||
getStream!.add(List<int>.filled(512, 2));
|
||||
await tester.pump(Duration.zero);
|
||||
await leaveAndReopen();
|
||||
expect(find.text('Custom-Complete'), findsOneWidget);
|
||||
expect(find.textContaining('Downloading'), findsOneWidget);
|
||||
|
||||
getStream!.add(List<int>.filled(512, 2));
|
||||
unawaited(getStream!.close());
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 20)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Custom-Complete'), findsOneWidget);
|
||||
expect(find.textContaining('Ready'), findsOneWidget);
|
||||
expect(find.textContaining('Active'), findsOneWidget);
|
||||
|
||||
// 3. Failure after reopen.
|
||||
await startCustomDownload('https://example.com/Custom-Fail.gguf');
|
||||
await tester.pump(Duration.zero);
|
||||
getStream!.add(List<int>.filled(256, 3));
|
||||
await tester.pump(Duration.zero);
|
||||
await leaveAndReopen();
|
||||
expect(find.text('Custom-Fail'), findsOneWidget);
|
||||
expect(find.textContaining('Downloading'), findsOneWidget);
|
||||
|
||||
getStream!.addError(http.ClientException('Connection reset'));
|
||||
unawaited(getStream!.close());
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 20)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text('Custom-Fail'), findsOneWidget);
|
||||
expect(find.textContaining("Couldn't download"), findsOneWidget);
|
||||
expect(find.textContaining('Connection reset'), findsOneWidget);
|
||||
// Error is shown in the model row detail, not duplicated below the URL field.
|
||||
expect(find.text('ClientException: Connection reset'), findsNothing);
|
||||
expect(
|
||||
find.byKey(
|
||||
const ValueKey('model-download-https://example.com/Custom-Fail.gguf'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('an installed image bundle is one ready row', (tester) async {
|
||||
final spec = imageCodecPresetModels.single;
|
||||
final settings = AppSettingsService();
|
||||
final store = InMemoryImageCodecSettingsStore(
|
||||
ImageCodecPreferences(
|
||||
enabled: true,
|
||||
selectedModelId: spec.id,
|
||||
downloadedModels: [
|
||||
ImageCodecModelRecord(
|
||||
id: spec.id,
|
||||
name: spec.fileName,
|
||||
sourceUrl: spec.graph.sourceUrl,
|
||||
localPath: '/tmp/${spec.fileName}',
|
||||
downloadedAt: DateTime.utc(2026, 1, 1),
|
||||
fileSizeBytes: spec.totalSizeBytes,
|
||||
assetFileNames: [for (final asset in spec.assets) asset.fileName],
|
||||
assetRoles: {
|
||||
for (final asset in spec.assets) asset.fileName: asset.role,
|
||||
},
|
||||
bundleVersion: kImageCodecBundleVersion,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
final codec = ImageCodecService(settings, settingsStore: store);
|
||||
|
||||
await pump(
|
||||
tester,
|
||||
const ImageCodecModelsSection(),
|
||||
providers: [
|
||||
ChangeNotifierProvider<ImageCodecService>.value(value: codec),
|
||||
],
|
||||
);
|
||||
|
||||
expect(find.text(spec.label), findsOneWidget);
|
||||
expect(find.textContaining(spec.fileName), findsNothing);
|
||||
expect(find.textContaining('.onnx'), findsNothing);
|
||||
expect(find.textContaining('958 MB'), findsOneWidget);
|
||||
expect(find.textContaining('Ready'), findsOneWidget);
|
||||
expect(find.textContaining('Active'), findsOneWidget);
|
||||
expect(find.byTooltip('Remove model'), findsOneWidget);
|
||||
expect(find.byTooltip('Download'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a partial image bundle stays on the preset row', (tester) async {
|
||||
final spec = imageCodecPresetModels.single;
|
||||
final settings = AppSettingsService();
|
||||
final store = InMemoryImageCodecSettingsStore(
|
||||
ImageCodecPreferences(
|
||||
enabled: true,
|
||||
downloadedModels: [
|
||||
ImageCodecModelRecord(
|
||||
id: spec.id,
|
||||
name: spec.fileName,
|
||||
sourceUrl: spec.graph.sourceUrl,
|
||||
localPath: '/tmp/${spec.fileName}',
|
||||
downloadedAt: DateTime.utc(2026, 1, 1),
|
||||
fileSizeBytes: spec.graph.sizeBytes,
|
||||
assetFileNames: [spec.fileName],
|
||||
bundleVersion: 0,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
final codec = ImageCodecService(settings, settingsStore: store);
|
||||
|
||||
await pump(
|
||||
tester,
|
||||
const ImageCodecModelsSection(),
|
||||
providers: [
|
||||
ChangeNotifierProvider<ImageCodecService>.value(value: codec),
|
||||
],
|
||||
);
|
||||
|
||||
expect(find.text(spec.label), findsOneWidget);
|
||||
expect(find.textContaining(spec.fileName), findsNothing);
|
||||
expect(find.textContaining('Incomplete'), findsOneWidget);
|
||||
expect(find.byTooltip('Download'), findsOneWidget);
|
||||
expect(find.byTooltip('Remove model'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'notDownloaded uses non-download leading icon and aligns icons cleanly',
|
||||
(tester) async {
|
||||
await pump(
|
||||
tester,
|
||||
ModelDownloadList(
|
||||
items: [
|
||||
ModelDownloadItem(
|
||||
id: 'new',
|
||||
name: 'Uninstalled model',
|
||||
sizeBytes: 958 * 1024 * 1024,
|
||||
status: ModelDownloadStatus.notDownloaded,
|
||||
onDownload: () {},
|
||||
),
|
||||
ModelDownloadItem(
|
||||
id: 'incomplete',
|
||||
name: 'Partial model',
|
||||
sizeBytes: 500 * 1024 * 1024,
|
||||
status: ModelDownloadStatus.notDownloaded,
|
||||
statusLabel: 'Incomplete',
|
||||
onDownload: () {},
|
||||
onDelete: () {},
|
||||
),
|
||||
ModelDownloadItem(
|
||||
id: 'busy',
|
||||
name: 'Downloading model',
|
||||
sizeBytes: 958 * 1024 * 1024,
|
||||
status: ModelDownloadStatus.downloading,
|
||||
progress: 0.4,
|
||||
downloadedBytes: 400 * 1024 * 1024,
|
||||
totalBytes: 958 * 1024 * 1024,
|
||||
onCancel: () {},
|
||||
),
|
||||
ModelDownloadItem(
|
||||
id: 'active',
|
||||
name: 'Active model',
|
||||
sizeBytes: 1100 * 1024 * 1024,
|
||||
status: ModelDownloadStatus.ready,
|
||||
selected: true,
|
||||
onDelete: () {},
|
||||
),
|
||||
ModelDownloadItem(
|
||||
id: 'bad',
|
||||
name: 'Failed model',
|
||||
status: ModelDownloadStatus.error,
|
||||
detail:
|
||||
'Download failed because the server closed the connection unexpectedly.',
|
||||
onDownload: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final newRow = find.byKey(const ValueKey('model-row-new'));
|
||||
final newLeading = find.descendant(
|
||||
of: newRow,
|
||||
matching: find.byIcon(Icons.memory_outlined),
|
||||
);
|
||||
expect(newLeading, findsOneWidget);
|
||||
final newTrailingButton = find.byKey(
|
||||
const ValueKey('model-download-new'),
|
||||
);
|
||||
final newTrailingIcon = find.descendant(
|
||||
of: newTrailingButton,
|
||||
matching: find.byIcon(Icons.download_outlined),
|
||||
);
|
||||
expect(newTrailingIcon, findsOneWidget);
|
||||
// Leading icon must differ from trailing download icon.
|
||||
expect(
|
||||
tester.widget<Icon>(newLeading).icon,
|
||||
isNot(tester.widget<Icon>(newTrailingIcon).icon),
|
||||
);
|
||||
expect(tester.getSize(newLeading), const Size(24, 24));
|
||||
expect(
|
||||
tester.getCenter(newLeading).dy,
|
||||
closeTo(tester.getCenter(newTrailingIcon).dy, 1.0),
|
||||
);
|
||||
|
||||
for (final (rowKey, buttonKey) in [
|
||||
('model-row-incomplete', 'model-download-incomplete'),
|
||||
('model-row-busy', 'model-cancel-busy'),
|
||||
('model-row-active', 'model-remove-active'),
|
||||
('model-row-bad', 'model-download-bad'),
|
||||
]) {
|
||||
final row = find.byKey(ValueKey(rowKey));
|
||||
final button = find.byKey(ValueKey(buttonKey));
|
||||
final title = find
|
||||
.descendant(of: row, matching: find.byType(Text))
|
||||
.first;
|
||||
final leading = find
|
||||
.descendant(of: row, matching: find.byType(Icon))
|
||||
.first;
|
||||
final spinner = find.descendant(
|
||||
of: row,
|
||||
matching: find.byType(CircularProgressIndicator),
|
||||
);
|
||||
final leadingFinder = spinner.evaluate().isNotEmpty ? spinner : leading;
|
||||
expect(
|
||||
tester.getRect(leadingFinder).right,
|
||||
lessThan(tester.getRect(title).left),
|
||||
);
|
||||
expect(
|
||||
tester.getCenter(leadingFinder).dy,
|
||||
closeTo(tester.getCenter(button).dy, 1.0),
|
||||
reason: '$rowKey leading indicator and trailing button must center',
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'TranslationSettingsSection hides sub-options when off, reveals on enable, and aligns rows',
|
||||
(tester) async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
final translation = TranslationService(settings);
|
||||
addTearDown(translation.dispose);
|
||||
|
||||
await pump(
|
||||
tester,
|
||||
const TranslationSettingsSection(),
|
||||
providers: [
|
||||
ChangeNotifierProvider<AppSettingsService>.value(value: settings),
|
||||
ChangeNotifierProvider<TranslationService>.value(value: translation),
|
||||
],
|
||||
);
|
||||
|
||||
final context = tester.element(find.byType(TranslationSettingsSection));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
expect(find.text(l10n.translation_enableTitle), findsOneWidget);
|
||||
expect(find.text(l10n.translation_autoIncomingTitle), findsNothing);
|
||||
expect(find.text(l10n.translation_composerTitle), findsNothing);
|
||||
expect(find.text(l10n.translation_targetLanguage), findsNothing);
|
||||
expect(find.text('Tencent HY-MT 1.5 1.8B Q4_K_M'), findsNothing);
|
||||
expect(find.text(l10n.translation_manualUrlLabel), findsNothing);
|
||||
|
||||
await tester.tap(find.text(l10n.translation_enableTitle));
|
||||
await tester.pump();
|
||||
await tester.pump(RevealOnEnable.duration);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(l10n.translation_autoIncomingTitle), findsOneWidget);
|
||||
expect(find.text(l10n.translation_composerTitle), findsOneWidget);
|
||||
expect(find.text(l10n.translation_targetLanguage), findsOneWidget);
|
||||
expect(find.text('Tencent HY-MT 1.5 1.8B Q4_K_M'), findsOneWidget);
|
||||
expect(find.text(l10n.translation_manualUrlLabel), findsOneWidget);
|
||||
|
||||
final revealFinder = find.byType(SettingsReveal);
|
||||
expect(revealFinder, findsOneWidget);
|
||||
final revealMaterial = tester.widget<Material>(
|
||||
find
|
||||
.descendant(of: revealFinder, matching: find.byType(Material))
|
||||
.first,
|
||||
);
|
||||
expect(
|
||||
revealMaterial.color,
|
||||
Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
);
|
||||
|
||||
// Switches and Target language row are enabled when visible.
|
||||
final autoIncomingSwitch = tester.widget<SwitchListTile>(
|
||||
find.ancestor(
|
||||
of: find.text(l10n.translation_autoIncomingTitle),
|
||||
matching: find.byType(SwitchListTile),
|
||||
),
|
||||
);
|
||||
expect(autoIncomingSwitch.onChanged, isNotNull);
|
||||
|
||||
// Leading icons, titles, and trailing icons align across Target language
|
||||
// (MeshNavTile) and revealed ModelDownloadList rows.
|
||||
final targetTile = find.ancestor(
|
||||
of: find.text(l10n.translation_targetLanguage),
|
||||
matching: find.byType(MeshNavTile),
|
||||
);
|
||||
final targetIcon = find.descendant(
|
||||
of: targetTile,
|
||||
matching: find.byIcon(Icons.language),
|
||||
);
|
||||
final targetChevron = find.descendant(
|
||||
of: targetTile,
|
||||
matching: find.byIcon(Icons.chevron_right),
|
||||
);
|
||||
|
||||
final firstPreset = translationPresetModels.first;
|
||||
final modelRow = find.byKey(ValueKey('model-row-${firstPreset.id}'));
|
||||
final modelLeadingIcon = find.descendant(
|
||||
of: modelRow,
|
||||
matching: find.byIcon(Icons.memory_outlined),
|
||||
);
|
||||
final modelTitle = find.descendant(
|
||||
of: modelRow,
|
||||
matching: find.text('Tencent HY-MT 1.5 1.8B Q4_K_M'),
|
||||
);
|
||||
final modelDownloadIcon = find.descendant(
|
||||
of: find.byKey(ValueKey('model-download-${firstPreset.id}')),
|
||||
matching: find.byIcon(Icons.download_outlined),
|
||||
);
|
||||
|
||||
expect(modelLeadingIcon, findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(modelLeadingIcon).left,
|
||||
closeTo(tester.getRect(targetIcon).left, 0.5),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(modelTitle).left,
|
||||
closeTo(
|
||||
tester.getRect(find.text(l10n.translation_targetLanguage)).left,
|
||||
0.5,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(modelDownloadIcon).right,
|
||||
closeTo(tester.getRect(targetChevron).right, 0.5),
|
||||
);
|
||||
|
||||
// Toggling off hides sub-options again.
|
||||
await tester.tap(find.text(l10n.translation_enableTitle));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(l10n.translation_autoIncomingTitle), findsNothing);
|
||||
expect(find.text(l10n.translation_targetLanguage), findsNothing);
|
||||
expect(find.text(l10n.translation_manualUrlLabel), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
for (final scale in [1.3, 2.0]) {
|
||||
testWidgets(
|
||||
'translation section and two-action model rows fit 320dp at ${scale}x',
|
||||
(tester) async {
|
||||
final overflows = <String>[];
|
||||
final previous = FlutterError.onError;
|
||||
FlutterError.onError = (details) {
|
||||
if (details.exceptionAsString().contains('overflowed')) {
|
||||
overflows.add(details.exceptionAsString().split('\n').first);
|
||||
return;
|
||||
}
|
||||
previous?.call(details);
|
||||
};
|
||||
addTearDown(() => FlutterError.onError = previous);
|
||||
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setTranslationEnabled(true);
|
||||
final translation = TranslationService(settings);
|
||||
addTearDown(translation.dispose);
|
||||
|
||||
await pump(
|
||||
tester,
|
||||
Column(
|
||||
children: [
|
||||
const TranslationSettingsSection(),
|
||||
ModelDownloadList(
|
||||
items: [
|
||||
ModelDownloadItem(
|
||||
id: 'incomplete',
|
||||
name: 'Tencent HY-MT 1.5 1.8B Q4_K_M',
|
||||
sizeBytes: 958 * 1024 * 1024,
|
||||
status: ModelDownloadStatus.notDownloaded,
|
||||
statusLabel: 'Incomplete',
|
||||
onDownload: () {},
|
||||
onDelete: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
providers: [
|
||||
ChangeNotifierProvider<AppSettingsService>.value(value: settings),
|
||||
ChangeNotifierProvider<TranslationService>.value(
|
||||
value: translation,
|
||||
),
|
||||
],
|
||||
textScale: scale,
|
||||
size: const Size(320, 568),
|
||||
);
|
||||
expect(overflows, isEmpty);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,512 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/widgets/path_editor_sheet.dart';
|
||||
|
||||
Contact _repeater(String name, List<int> prefix) {
|
||||
final key = Uint8List(32);
|
||||
for (var i = 0; i < prefix.length; i++) {
|
||||
key[i] = prefix[i];
|
||||
}
|
||||
return Contact(
|
||||
publicKey: key,
|
||||
name: name,
|
||||
type: advTypeRepeater,
|
||||
pathLength: -1,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
);
|
||||
}
|
||||
|
||||
final _contacts = [
|
||||
_repeater('100 Acre', [0x11, 0x22]),
|
||||
_repeater('Acreage North', [0x33, 0x44]),
|
||||
_repeater('My Acre Site', [0x55, 0x66]),
|
||||
_repeater('2E0HQR-R', [0x2E, 0x0A]),
|
||||
_repeater('CR1', [0x60, 0x60]),
|
||||
for (var i = 0; i < 24; i++) _repeater('Repeater $i', [0xA0, i]),
|
||||
];
|
||||
|
||||
Future<void> _pumpSheet(
|
||||
WidgetTester tester, {
|
||||
Size size = const Size(400, 700),
|
||||
double keyboard = 0,
|
||||
double textScale = 1.0,
|
||||
List<int> initialPath = const [],
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(
|
||||
size: size,
|
||||
viewInsets: EdgeInsets.only(bottom: keyboard),
|
||||
textScaler: TextScaler.linear(textScale),
|
||||
),
|
||||
child: Scaffold(
|
||||
body: SizedBox(
|
||||
width: size.width,
|
||||
height: size.height - keyboard,
|
||||
child: PathEditorSheet(
|
||||
key: UniqueKey(),
|
||||
availableContacts: _contacts,
|
||||
initialPath: initialPath,
|
||||
pathHashByteWidth: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Finder _fallbackScrollable() {
|
||||
return find.byElementPredicate((element) {
|
||||
if (element.widget is! Scrollable) return false;
|
||||
var hasHex = false;
|
||||
void visit(Element node) {
|
||||
node.visitChildren((child) {
|
||||
if (child.widget.key == const Key('path-editor-hex-field')) {
|
||||
hasHex = true;
|
||||
}
|
||||
visit(child);
|
||||
});
|
||||
}
|
||||
|
||||
visit(element);
|
||||
return hasHex;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _revealInFallback(
|
||||
WidgetTester tester,
|
||||
Finder scrollable,
|
||||
Finder target,
|
||||
) async {
|
||||
final state = tester.state<ScrollableState>(scrollable);
|
||||
final view = tester.getRect(
|
||||
find.byKey(const Key('path-editor-scroll-fallback')),
|
||||
);
|
||||
final step = (view.height / 2).clamp(2.0, 24.0);
|
||||
for (var i = 0; i < 400; i++) {
|
||||
final rect = tester.getRect(target);
|
||||
if (rect.center.dy >= view.top && rect.center.dy <= view.bottom) return;
|
||||
final next = (state.position.pixels + step).clamp(
|
||||
0.0,
|
||||
state.position.maxScrollExtent,
|
||||
);
|
||||
expect(next, greaterThan(state.position.pixels));
|
||||
state.position.jumpTo(next);
|
||||
await tester.pump();
|
||||
}
|
||||
fail(
|
||||
'Could not scroll $target into $view (last rect=${tester.getRect(target)}, pixels=${state.position.pixels})',
|
||||
);
|
||||
}
|
||||
|
||||
List<String> _repeaterNames(WidgetTester tester) {
|
||||
return tester
|
||||
.widgetList<Text>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('path-editor-repeater-list')),
|
||||
matching: find.byType(Text),
|
||||
),
|
||||
)
|
||||
.map((text) => text.data)
|
||||
.whereType<String>()
|
||||
.where((text) => !text.contains('•'))
|
||||
.toList();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('prefix matches are listed before other substring matches', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpSheet(tester);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('path-editor-search-field')),
|
||||
'acre',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final visible = _repeaterNames(tester);
|
||||
expect(visible.first, 'Acreage North');
|
||||
expect(visible[1], '100 Acre');
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('My Acre Site'),
|
||||
80,
|
||||
scrollable: find.descendant(
|
||||
of: find.byKey(const Key('path-editor-repeater-list')),
|
||||
matching: find.byType(Scrollable),
|
||||
),
|
||||
);
|
||||
expect(find.text('My Acre Site'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('search matches a hop hash the name does not contain', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpSheet(tester);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('path-editor-search-field')),
|
||||
'6060',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('No repeaters or room servers found.'), findsNothing);
|
||||
expect(_repeaterNames(tester), ['CR1']);
|
||||
});
|
||||
|
||||
testWidgets('hex entry is reachable without scrolling the repeater list', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpSheet(tester, size: const Size(400, 900));
|
||||
expect(
|
||||
find.byKey(const Key('path-editor-hex-field')).hitTestable(),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Hex prefixes'), findsOneWidget);
|
||||
expect(
|
||||
find.text('4 hex characters per hop, separated by commas'),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('an added hop stays fully visible with the keyboard open', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpSheet(
|
||||
tester,
|
||||
size: const Size(390, 640),
|
||||
keyboard: 320,
|
||||
initialPath: [0x60, 0x60],
|
||||
);
|
||||
|
||||
final tile = find.ancestor(
|
||||
of: find.byIcon(Icons.remove_circle_outline),
|
||||
matching: find.byType(ListTile),
|
||||
);
|
||||
expect(tile.hitTestable(), findsOneWidget);
|
||||
final title = tester.getRect(find.text('Build Path'));
|
||||
final hopRect = tester.getRect(tile);
|
||||
final sheet = tester.getRect(find.byType(PathEditorSheet));
|
||||
expect(hopRect.top, greaterThanOrEqualTo(title.bottom));
|
||||
expect(hopRect.bottom, lessThanOrEqualTo(sheet.bottom));
|
||||
expect(hopRect.height, greaterThanOrEqualTo(48));
|
||||
expect(find.text('CR1').hitTestable(), findsWidgets);
|
||||
expect(find.text('6060').hitTestable(), findsWidgets);
|
||||
expect(
|
||||
find.byKey(const Key('path-editor-hex-field')).hitTestable(),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byKey(const Key('path-editor-scroll-fallback')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('an invalid hex path does not overflow a keyboard-height sheet', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpSheet(
|
||||
tester,
|
||||
size: const Size(390, 640),
|
||||
keyboard: 320,
|
||||
initialPath: [0x60, 0x60, 0x11, 0x22],
|
||||
);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('path-editor-hex-field')),
|
||||
'ZZ',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('Invalid'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(
|
||||
find.byIcon(Icons.remove_circle_outline).hitTestable(),
|
||||
findsWidgets,
|
||||
);
|
||||
final button = tester.getRect(find.text('Use this path'));
|
||||
final sheet = tester.getRect(find.byType(PathEditorSheet));
|
||||
expect(button.bottom, lessThanOrEqualTo(sheet.bottom + 1));
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'3-line hex error on a 320px keyboard sheet keeps controls scrollable',
|
||||
(tester) async {
|
||||
await _pumpSheet(
|
||||
tester,
|
||||
size: const Size(390, 640),
|
||||
keyboard: 320,
|
||||
initialPath: [0x60, 0x60, 0x11, 0x22],
|
||||
);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('path-editor-hex-field')),
|
||||
'AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(
|
||||
find.byKey(const Key('path-editor-scroll-fallback')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<TextField>(find.byKey(const Key('path-editor-hex-field')))
|
||||
.focusNode
|
||||
?.hasFocus,
|
||||
isTrue,
|
||||
);
|
||||
final scrollable = _fallbackScrollable();
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
scrollable,
|
||||
find.textContaining('Invalid', skipOffstage: false),
|
||||
);
|
||||
expect(find.textContaining('Invalid').hitTestable(), findsOneWidget);
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
scrollable,
|
||||
find.byKey(const Key('path-editor-search-field'), skipOffstage: false),
|
||||
);
|
||||
expect(
|
||||
find.byKey(const Key('path-editor-search-field')).hitTestable(),
|
||||
findsOneWidget,
|
||||
);
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
scrollable,
|
||||
find.text('Acreage North', skipOffstage: false),
|
||||
);
|
||||
expect(find.text('Acreage North').hitTestable(), findsOneWidget);
|
||||
final button = tester.getRect(find.text('Use this path'));
|
||||
final sheet = tester.getRect(find.byType(PathEditorSheet));
|
||||
expect(button.bottom, lessThanOrEqualTo(sheet.bottom + 1));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a landscape keyboard sheet scrolls instead of overflowing', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpSheet(
|
||||
tester,
|
||||
size: const Size(800, 180),
|
||||
initialPath: [0x60, 0x60, 0x11, 0x22],
|
||||
);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(
|
||||
find.byKey(const Key('path-editor-scroll-fallback')),
|
||||
findsOneWidget,
|
||||
);
|
||||
final scrollable = _fallbackScrollable();
|
||||
await tester.scrollUntilVisible(
|
||||
find.byKey(const Key('path-editor-hex-field')),
|
||||
40,
|
||||
scrollable: scrollable,
|
||||
);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('path-editor-hex-field')),
|
||||
'ZZ',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.textContaining('Invalid'), findsOneWidget);
|
||||
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
scrollable,
|
||||
find.byKey(const Key('path-editor-search-field'), skipOffstage: false),
|
||||
);
|
||||
expect(
|
||||
find.byKey(const Key('path-editor-search-field')).hitTestable(),
|
||||
findsOneWidget,
|
||||
);
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
scrollable,
|
||||
find.text('Acreage North', skipOffstage: false),
|
||||
);
|
||||
expect(find.text('Acreage North').hitTestable(), findsOneWidget);
|
||||
final button = tester.getRect(find.text('Use this path'));
|
||||
final sheet = tester.getRect(find.byType(PathEditorSheet));
|
||||
expect(button.bottom, lessThanOrEqualTo(sheet.bottom + 1));
|
||||
});
|
||||
|
||||
testWidgets('an empty landscape keyboard sheet scrolls cleanly at 180px', (
|
||||
tester,
|
||||
) async {
|
||||
for (final size in [const Size(800, 180), const Size(640, 220)]) {
|
||||
await _pumpSheet(tester, size: size);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(
|
||||
find.byKey(const Key('path-editor-scroll-fallback')),
|
||||
findsOneWidget,
|
||||
);
|
||||
final scrollable = _fallbackScrollable();
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
scrollable,
|
||||
find.byKey(const Key('path-editor-hex-field'), skipOffstage: false),
|
||||
);
|
||||
expect(
|
||||
find.byKey(const Key('path-editor-hex-field')).hitTestable(),
|
||||
findsOneWidget,
|
||||
);
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
scrollable,
|
||||
find.byKey(const Key('path-editor-search-field'), skipOffstage: false),
|
||||
);
|
||||
expect(
|
||||
find.byKey(const Key('path-editor-search-field')).hitTestable(),
|
||||
findsOneWidget,
|
||||
);
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
scrollable,
|
||||
find.text('Acreage North', skipOffstage: false),
|
||||
);
|
||||
expect(find.text('Acreage North').hitTestable(), findsOneWidget);
|
||||
final button = tester.getRect(find.text('Use this path'));
|
||||
final sheet = tester.getRect(find.byType(PathEditorSheet));
|
||||
expect(button.bottom, lessThanOrEqualTo(sheet.bottom + 1));
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('320dp width fits at 1.3x and 2.0x text scale without overflow', (
|
||||
tester,
|
||||
) async {
|
||||
for (final scale in [1.3, 2.0]) {
|
||||
for (final keyboard in [0.0, 320.0]) {
|
||||
await _pumpSheet(
|
||||
tester,
|
||||
size: const Size(320, 640),
|
||||
keyboard: keyboard,
|
||||
textScale: scale,
|
||||
initialPath: [0x60, 0x60, 0x11, 0x22],
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
if (find
|
||||
.byKey(const Key('path-editor-scroll-fallback'))
|
||||
.evaluate()
|
||||
.isNotEmpty) {
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
_fallbackScrollable(),
|
||||
find.byKey(const Key('path-editor-hex-field'), skipOffstage: false),
|
||||
);
|
||||
}
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('path-editor-hex-field')),
|
||||
'AA, BB, CC, DD, EE, FF, GG, HH, II, JJ',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
if (find
|
||||
.byKey(const Key('path-editor-scroll-fallback'))
|
||||
.evaluate()
|
||||
.isNotEmpty) {
|
||||
await _revealInFallback(
|
||||
tester,
|
||||
_fallbackScrollable(),
|
||||
find.textContaining('Invalid', skipOffstage: false),
|
||||
);
|
||||
}
|
||||
expect(find.textContaining('Invalid').hitTestable(), findsOneWidget);
|
||||
|
||||
if (find.text('Use this path').evaluate().isEmpty) {
|
||||
final state = tester.state<ScrollableState>(_fallbackScrollable());
|
||||
state.position.jumpTo(state.position.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
final button = tester.getRect(find.text('Use this path'));
|
||||
final sheet = tester.getRect(find.byType(PathEditorSheet));
|
||||
expect(button.bottom, lessThanOrEqualTo(sheet.bottom + 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('action buttons stay below the repeater list on a short sheet', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpSheet(
|
||||
tester,
|
||||
size: const Size(400, 560),
|
||||
initialPath: [0x60, 0x60, 0x11, 0x22],
|
||||
);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
final button = tester.getRect(find.text('Use this path'));
|
||||
final list = tester.getRect(
|
||||
find.byKey(const Key('path-editor-repeater-list')),
|
||||
);
|
||||
expect(button.top, greaterThanOrEqualTo(list.bottom - 1));
|
||||
});
|
||||
|
||||
testWidgets('the title sits at the top of the sheet', (tester) async {
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
// A phone status bar. The sheet may pad for it, and must not add another
|
||||
// empty band above the handle.
|
||||
tester.view.padding = const FakeViewPadding(top: 47);
|
||||
tester.view.viewPadding = const FakeViewPadding(top: 47);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.view.resetPadding);
|
||||
addTearDown(tester.view.resetViewPadding);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () => PathEditorSheet.show(
|
||||
context,
|
||||
availableContacts: _contacts,
|
||||
pathHashByteWidth: 2,
|
||||
),
|
||||
child: const Text('open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final sheetTop = tester.getTopLeft(find.byType(BottomSheet)).dy;
|
||||
final titleTop = tester.getTopLeft(find.text('Build Path')).dy;
|
||||
// Header only: 8px padding, a 4px handle, and a 10px gap. The status-bar
|
||||
// inset stays outside the sheet, and there is no extra empty band.
|
||||
expect(titleTop - sheetTop, inInclusiveRange(16, 36));
|
||||
});
|
||||
|
||||
testWidgets('tapping a repeater adds a visible hop', (tester) async {
|
||||
await _pumpSheet(tester);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('path-editor-search-field')),
|
||||
'6060',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(ListTile, 'CR1'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('1 of 64 hops'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.remove_circle_outline), findsOneWidget);
|
||||
expect(find.text('CR1').hitTestable(), findsWidgets);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/image_codec_support.dart';
|
||||
import 'package:meshcore_open/screens/app_settings_screen.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/image_codec_service.dart';
|
||||
import 'package:meshcore_open/services/image_codec_settings_store.dart';
|
||||
import 'package:meshcore_open/services/network_map/network_map_upload_service.dart';
|
||||
import 'package:meshcore_open/services/translation_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/widgets/image_codec_models_section.dart';
|
||||
import 'package:meshcore_open/widgets/settings_reveal.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
testWidgets('SettingsReveal hides children when off and reveals with tint', (
|
||||
tester,
|
||||
) async {
|
||||
var visible = false;
|
||||
late StateSetter setHostState;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: MeshTheme.dark(),
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
setHostState = setState;
|
||||
return SettingsReveal(
|
||||
visible: visible,
|
||||
children: const [Text('Nested option')],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Nested option'), findsNothing);
|
||||
|
||||
setHostState(() => visible = true);
|
||||
await tester.pump();
|
||||
await tester.pump(RevealOnEnable.duration);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Nested option'), findsOneWidget);
|
||||
final context = tester.element(find.byType(SettingsReveal));
|
||||
final material = tester.widget<Material>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(SettingsReveal),
|
||||
matching: find.byType(Material),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(
|
||||
material.color,
|
||||
Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
);
|
||||
|
||||
final padding = tester.widget<Padding>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(SettingsReveal),
|
||||
matching: find.byType(Padding),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(padding.padding, const EdgeInsets.only(left: 16));
|
||||
|
||||
setHostState(() => visible = false);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Nested option'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'AppSettingsScreen hides Image Messages sub-options until enabled and uses SettingsReveal',
|
||||
(tester) async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setAutoRouteRotationEnabled(false);
|
||||
final connector = MeshCoreConnector();
|
||||
final translation = TranslationService(settings);
|
||||
final codec = ImageCodecService(
|
||||
settings,
|
||||
settingsStore: InMemoryImageCodecSettingsStore(
|
||||
const ImageCodecPreferences(),
|
||||
),
|
||||
);
|
||||
final uploads = NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
);
|
||||
addTearDown(connector.dispose);
|
||||
addTearDown(translation.dispose);
|
||||
addTearDown(codec.dispose);
|
||||
addTearDown(uploads.dispose);
|
||||
|
||||
tester.view.physicalSize = const Size(400, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: codec),
|
||||
ChangeNotifierProvider.value(value: uploads),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.dark(),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const AppSettingsScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(find.byType(AppSettingsScreen));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final spec = imageCodecPresetModels.single;
|
||||
|
||||
await tester.scrollUntilVisible(
|
||||
find.text(l10n.imageMessages_enableTitle),
|
||||
300,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(l10n.imageMessages_enableTitle), findsOneWidget);
|
||||
expect(find.text(l10n.imageMessages_autoProcessTitle), findsNothing);
|
||||
expect(find.text(l10n.imageMessages_modelSectionTitle), findsNothing);
|
||||
expect(find.text(spec.label), findsNothing);
|
||||
|
||||
await tester.tap(find.text(l10n.imageMessages_enableTitle));
|
||||
await tester.pump();
|
||||
await tester.pump(RevealOnEnable.duration);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.scrollUntilVisible(
|
||||
find.text(spec.label),
|
||||
200,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(l10n.imageMessages_autoProcessTitle), findsOneWidget);
|
||||
expect(find.text(l10n.imageMessages_modelSectionTitle), findsOneWidget);
|
||||
expect(find.text(spec.label), findsOneWidget);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(ImageCodecModelsSection),
|
||||
matching: find.byIcon(Icons.memory_outlined),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
final imageReveal = find.ancestor(
|
||||
of: find.byType(ImageCodecModelsSection),
|
||||
matching: find.byType(SettingsReveal),
|
||||
);
|
||||
expect(imageReveal, findsOneWidget);
|
||||
|
||||
await tester.ensureVisible(find.text(l10n.imageMessages_enableTitle));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(l10n.imageMessages_enableTitle));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(l10n.imageMessages_autoProcessTitle), findsNothing);
|
||||
expect(find.text(spec.label), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
for (final scale in [1.3, 2.0]) {
|
||||
testWidgets(
|
||||
'AppSettingsScreen with Image Messages and Translation expanded fits 320dp at ${scale}x',
|
||||
(tester) async {
|
||||
final overflows = <String>[];
|
||||
final previous = FlutterError.onError;
|
||||
FlutterError.onError = (details) {
|
||||
if (details.exceptionAsString().contains('overflowed')) {
|
||||
overflows.add(details.exceptionAsString().split('\n').first);
|
||||
return;
|
||||
}
|
||||
previous?.call(details);
|
||||
};
|
||||
addTearDown(() => FlutterError.onError = previous);
|
||||
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setImageMessagesEnabled(true);
|
||||
await settings.setTranslationEnabled(true);
|
||||
final connector = MeshCoreConnector();
|
||||
final translation = TranslationService(settings);
|
||||
final codec = ImageCodecService(
|
||||
settings,
|
||||
settingsStore: InMemoryImageCodecSettingsStore(
|
||||
const ImageCodecPreferences(enabled: true),
|
||||
),
|
||||
);
|
||||
final uploads = NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
);
|
||||
addTearDown(connector.dispose);
|
||||
addTearDown(translation.dispose);
|
||||
addTearDown(codec.dispose);
|
||||
addTearDown(uploads.dispose);
|
||||
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: codec),
|
||||
ChangeNotifierProvider.value(value: uploads),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(scale)),
|
||||
child: child!,
|
||||
),
|
||||
home: const AppSettingsScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(overflows, isEmpty);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user