Merge origin/dev into feat/group-editor-members-first
This commit is contained in:
commit
0cc5fd4e1f
88 files changed
+5799
-742
No files matched your search
@@ -0,0 +1,238 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.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/models/contact.dart';
|
||||
import 'package:meshcore_open/models/path_history.dart';
|
||||
import 'package:meshcore_open/models/path_selection.dart';
|
||||
import 'package:meshcore_open/review_mode/review_radio.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/message_retry_service.dart';
|
||||
import 'package:meshcore_open/services/path_history_service.dart';
|
||||
import 'package:meshcore_open/services/storage_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
|
||||
Contact _directContact() {
|
||||
return Contact(
|
||||
publicKey: Uint8List.fromList(List<int>.generate(32, (i) => i + 1)),
|
||||
name: 'Hill',
|
||||
type: 1,
|
||||
pathLength: 1,
|
||||
path: Uint8List.fromList(const [0x11]),
|
||||
lastSeen: DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
class _ControllablePathStorage extends StorageService {
|
||||
Completer<ContactPathHistory?>? loadGate;
|
||||
|
||||
@override
|
||||
Future<ContactPathHistory?> loadPathHistory(String contactPubKeyHex) {
|
||||
final gate = loadGate;
|
||||
if (gate != null && !gate.isCompleted) {
|
||||
return gate.future;
|
||||
}
|
||||
return Future<ContactPathHistory?>.value(null);
|
||||
}
|
||||
}
|
||||
|
||||
class _RecordingReviewRadio extends ReviewRadio {
|
||||
final List<Uint8List> sent = [];
|
||||
|
||||
_RecordingReviewRadio()
|
||||
: super(
|
||||
scheduledMessageInterval: const Duration(hours: 1),
|
||||
// Long ACK delay so retry attempts run on timeout in tests.
|
||||
ackDelay: const Duration(hours: 1),
|
||||
);
|
||||
|
||||
@override
|
||||
void handle(Uint8List frame) {
|
||||
sent.add(frame);
|
||||
super.handle(frame);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _waitFor(bool Function() condition, {int seconds = 8}) async {
|
||||
final end = DateTime.now().add(Duration(seconds: seconds));
|
||||
while (!condition()) {
|
||||
if (DateTime.now().isAfter(end)) fail('Timed out waiting for condition');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 25));
|
||||
}
|
||||
}
|
||||
|
||||
// NotificationService is a process-wide singleton whose reply stream can be
|
||||
// listened to once, so every test shares one connector and reconnects it to a
|
||||
// fresh radio.
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
late MeshCoreConnector connector;
|
||||
late _ControllablePathStorage storage;
|
||||
late PathHistoryService history;
|
||||
late MessageRetryService retries;
|
||||
late AppSettingsService settings;
|
||||
|
||||
setUpAll(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
connector = MeshCoreConnector();
|
||||
storage = _ControllablePathStorage();
|
||||
history = PathHistoryService(storage);
|
||||
retries = MessageRetryService(
|
||||
sentWatchdogGrace: const Duration(milliseconds: 5),
|
||||
);
|
||||
connector.initialize(
|
||||
retryService: retries,
|
||||
pathHistoryService: history,
|
||||
appSettingsService: settings,
|
||||
);
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
connector.dispose();
|
||||
history.dispose();
|
||||
retries.dispose();
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
storage.loadGate = null;
|
||||
await settings.resetRoutingSettingsToDefault();
|
||||
});
|
||||
|
||||
test('flood attempts do not wait for route history', () async {
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: true,
|
||||
directRetries: 0,
|
||||
floodRetries: 1,
|
||||
),
|
||||
);
|
||||
|
||||
final flooded = await connector.preparePathForContactSend(_directContact());
|
||||
expect(flooded.useFlood, isTrue);
|
||||
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(directRetries: 2, floodRetries: 1),
|
||||
);
|
||||
final direct = await connector.preparePathForContactSend(_directContact());
|
||||
expect(direct.useFlood, isFalse);
|
||||
expect(direct.hopCount, 1);
|
||||
expect(direct.pathBytes, [0x11]);
|
||||
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(directRetries: 0, floodRetries: 0),
|
||||
);
|
||||
final zeroBudget = await connector.preparePathForContactSend(
|
||||
_directContact(),
|
||||
);
|
||||
expect(zeroBudget.useFlood, isFalse);
|
||||
expect(zeroBudget.hopCount, 1);
|
||||
expect(zeroBudget.pathBytes, [0x11]);
|
||||
});
|
||||
|
||||
test(
|
||||
'sendMessage with directRetries 0 and floodRetries 1 floods even when route history is loading',
|
||||
() async {
|
||||
final gate = Completer<ContactPathHistory?>();
|
||||
storage.loadGate = gate;
|
||||
|
||||
final radio = _RecordingReviewRadio();
|
||||
connector.reviewRadioFactoryForTest = () => radio;
|
||||
await connector.connectReview();
|
||||
addTearDown(connector.disconnect);
|
||||
await _waitFor(() => connector.contacts.isNotEmpty);
|
||||
|
||||
final directContact = connector.contacts.firstWhere(
|
||||
(c) => c.pathLength > 0,
|
||||
);
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: true,
|
||||
directRetries: 0,
|
||||
floodRetries: 1,
|
||||
),
|
||||
);
|
||||
|
||||
radio.sent.clear();
|
||||
await connector.sendMessage(directContact, 'flood only');
|
||||
await _waitFor(
|
||||
() => radio.sent.any((frame) => frame[0] == cmdSendTxtMsg),
|
||||
);
|
||||
|
||||
final opCodes = radio.sent
|
||||
.map((frame) => frame[0])
|
||||
.where(
|
||||
(code) =>
|
||||
code == cmdResetPath ||
|
||||
code == cmdAddUpdateContact ||
|
||||
code == cmdSendTxtMsg,
|
||||
)
|
||||
.toList();
|
||||
expect(opCodes, [cmdResetPath, cmdSendTxtMsg]);
|
||||
|
||||
gate.complete(null);
|
||||
storage.loadGate = null;
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'sendMessage with directRetries > 0 rotates through cached paths before flooding',
|
||||
() async {
|
||||
final radio = _RecordingReviewRadio();
|
||||
connector.reviewRadioFactoryForTest = () => radio;
|
||||
await connector.connectReview();
|
||||
addTearDown(connector.disconnect);
|
||||
await _waitFor(() => connector.contacts.isNotEmpty);
|
||||
|
||||
final directContact = connector.contacts.firstWhere(
|
||||
(c) => c.pathLength > 0,
|
||||
);
|
||||
history.recordPathResult(
|
||||
directContact.publicKeyHex,
|
||||
const PathSelection(pathBytes: [0x22], hopCount: 1, useFlood: false),
|
||||
success: true,
|
||||
);
|
||||
await pumpEventQueue();
|
||||
history.recordPathResult(
|
||||
directContact.publicKeyHex,
|
||||
const PathSelection(pathBytes: [0x33], hopCount: 1, useFlood: false),
|
||||
success: true,
|
||||
);
|
||||
await pumpEventQueue();
|
||||
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: true,
|
||||
directRetries: 2,
|
||||
floodRetries: 1,
|
||||
),
|
||||
);
|
||||
|
||||
radio.sent.clear();
|
||||
await connector.sendMessage(directContact, 'rotate then flood');
|
||||
await _waitFor(
|
||||
() =>
|
||||
radio.sent.where((frame) => frame[0] == cmdSendTxtMsg).length == 3,
|
||||
seconds: 25,
|
||||
);
|
||||
|
||||
final pathOps = radio.sent
|
||||
.where(
|
||||
(frame) =>
|
||||
frame[0] == cmdResetPath || frame[0] == cmdAddUpdateContact,
|
||||
)
|
||||
.map((frame) => frame[0])
|
||||
.toList();
|
||||
expect(pathOps, [cmdAddUpdateContact, cmdAddUpdateContact, cmdResetPath]);
|
||||
},
|
||||
timeout: const Timeout(Duration(seconds: 45)),
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/bookmarked_message.dart';
|
||||
import 'package:meshcore_open/models/channel_message.dart';
|
||||
|
||||
void main() {
|
||||
@@ -25,5 +26,52 @@ void main() {
|
||||
test('outgoing message without reply has no reply target', () {
|
||||
final message = ChannelMessage.outgoing('hello', 'Me', 0);
|
||||
expect(message.replyToMessageId, isNull);
|
||||
expect(message.fullText, 'hello');
|
||||
});
|
||||
|
||||
test('fullText restores @[username] prefix for stored replies', () {
|
||||
final storedReply = ChannelMessage(
|
||||
senderName: 'Me',
|
||||
text: 'answer',
|
||||
timestamp: DateTime(2026, 1, 1, 12),
|
||||
isOutgoing: true,
|
||||
replyToMessageId: 'msg-1',
|
||||
replyToSenderName: 'Alice',
|
||||
replyToText: 'question',
|
||||
);
|
||||
|
||||
expect(storedReply.fullText, '@[Alice] answer');
|
||||
|
||||
final bookmark = BookmarkedMessage.fromChannel(
|
||||
message: storedReply,
|
||||
channelId: 'ch-0',
|
||||
channelName: 'Public',
|
||||
senderName: 'Me',
|
||||
);
|
||||
expect(bookmark.text, '@[Alice] answer');
|
||||
});
|
||||
|
||||
test('fullText preserves nested mention and special payloads in replies', () {
|
||||
final nestedReply = ChannelMessage(
|
||||
senderName: 'Bob',
|
||||
text: '@[Alice] nested',
|
||||
timestamp: DateTime(2026, 1, 1, 12),
|
||||
isOutgoing: false,
|
||||
replyToMessageId: 'msg-1',
|
||||
replyToSenderName: 'Alice',
|
||||
replyToText: 'original',
|
||||
);
|
||||
expect(nestedReply.fullText, '@[Alice] @[Alice] nested');
|
||||
|
||||
final gifReply = ChannelMessage(
|
||||
senderName: 'Bob',
|
||||
text: 'g:abc123',
|
||||
timestamp: DateTime(2026, 1, 1, 12),
|
||||
isOutgoing: false,
|
||||
replyToMessageId: 'msg-1',
|
||||
replyToSenderName: 'Alice',
|
||||
replyToText: 'original',
|
||||
);
|
||||
expect(gifReply.fullText, '@[Alice] g:abc123');
|
||||
});
|
||||
}
|
||||
@@ -404,7 +404,9 @@ void main() {
|
||||
expect(settings.initialRouteWeight, equals(3.0));
|
||||
expect(settings.routeWeightSuccessIncrement, equals(0.5));
|
||||
expect(settings.routeWeightFailureDecrement, equals(0.2));
|
||||
expect(settings.maxMessageRetries, equals(5));
|
||||
expect(settings.directRetries, equals(4));
|
||||
expect(settings.floodRetries, equals(1));
|
||||
expect(settings.loginAttempts, equals(5));
|
||||
expect(settings.evictDiscoveredContactsEnabled, isTrue);
|
||||
});
|
||||
|
||||
@@ -415,13 +417,17 @@ void main() {
|
||||
expect(json.containsKey('initial_route_weight'), isTrue);
|
||||
expect(json.containsKey('route_weight_success_increment'), isTrue);
|
||||
expect(json.containsKey('route_weight_failure_decrement'), isTrue);
|
||||
expect(json.containsKey('max_message_retries'), isTrue);
|
||||
expect(json.containsKey('max_direct_retries'), isTrue);
|
||||
expect(json.containsKey('max_flood_retries'), isTrue);
|
||||
expect(json.containsKey('login_attempts'), isTrue);
|
||||
expect(json.containsKey('evict_discovered_contacts_enabled'), isTrue);
|
||||
expect(json['max_route_weight'], equals(5.0));
|
||||
expect(json['initial_route_weight'], equals(3.0));
|
||||
expect(json['route_weight_success_increment'], equals(0.5));
|
||||
expect(json['route_weight_failure_decrement'], equals(0.2));
|
||||
expect(json['max_message_retries'], equals(5));
|
||||
expect(json['max_direct_retries'], equals(4));
|
||||
expect(json['max_flood_retries'], equals(1));
|
||||
expect(json['login_attempts'], equals(5));
|
||||
expect(json['evict_discovered_contacts_enabled'], isTrue);
|
||||
});
|
||||
|
||||
@@ -431,7 +437,9 @@ void main() {
|
||||
'initial_route_weight': 2.0,
|
||||
'route_weight_success_increment': 1.0,
|
||||
'route_weight_failure_decrement': 1.5,
|
||||
'max_message_retries': 8,
|
||||
'max_direct_retries': 8,
|
||||
'max_flood_retries': 3,
|
||||
'login_attempts': 7,
|
||||
'evict_discovered_contacts_enabled': false,
|
||||
};
|
||||
final settings = AppSettings.fromJson(json);
|
||||
@@ -439,7 +447,9 @@ void main() {
|
||||
expect(settings.initialRouteWeight, equals(2.0));
|
||||
expect(settings.routeWeightSuccessIncrement, equals(1.0));
|
||||
expect(settings.routeWeightFailureDecrement, equals(1.5));
|
||||
expect(settings.maxMessageRetries, equals(8));
|
||||
expect(settings.directRetries, equals(8));
|
||||
expect(settings.floodRetries, equals(3));
|
||||
expect(settings.loginAttempts, equals(7));
|
||||
expect(settings.evictDiscoveredContactsEnabled, isFalse);
|
||||
});
|
||||
|
||||
@@ -503,7 +513,9 @@ void main() {
|
||||
expect(settings.initialRouteWeight, equals(3.0));
|
||||
expect(settings.routeWeightSuccessIncrement, equals(0.5));
|
||||
expect(settings.routeWeightFailureDecrement, equals(0.2));
|
||||
expect(settings.maxMessageRetries, equals(5));
|
||||
expect(settings.directRetries, equals(4));
|
||||
expect(settings.floodRetries, equals(1));
|
||||
expect(settings.loginAttempts, equals(5));
|
||||
},
|
||||
);
|
||||
|
||||
@@ -513,7 +525,7 @@ void main() {
|
||||
expect(updated.maxRouteWeight, equals(8.0));
|
||||
// Other fields should be unchanged
|
||||
expect(updated.initialRouteWeight, equals(settings.initialRouteWeight));
|
||||
expect(updated.maxMessageRetries, equals(settings.maxMessageRetries));
|
||||
expect(updated.directRetries, equals(settings.directRetries));
|
||||
});
|
||||
|
||||
test('copyWith works for initialRouteWeight', () {
|
||||
@@ -543,10 +555,10 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('copyWith works for maxMessageRetries', () {
|
||||
test('copyWith works for directRetries', () {
|
||||
final settings = AppSettings();
|
||||
final updated = settings.copyWith(maxMessageRetries: 10);
|
||||
expect(updated.maxMessageRetries, equals(10));
|
||||
final updated = settings.copyWith(directRetries: 10);
|
||||
expect(updated.directRetries, equals(10));
|
||||
expect(updated.maxRouteWeight, equals(settings.maxRouteWeight));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:meshcore_open/models/app_settings.dart';
|
||||
import 'package:meshcore_open/models/send_attempt_plan.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
|
||||
void main() {
|
||||
group('SendAttemptPlan', () {
|
||||
const rotating = SendAttemptPlan(
|
||||
directRetries: 4,
|
||||
floodRetries: 1,
|
||||
rotateRoutes: true,
|
||||
);
|
||||
const fixed = SendAttemptPlan(
|
||||
directRetries: 4,
|
||||
floodRetries: 2,
|
||||
rotateRoutes: false,
|
||||
);
|
||||
|
||||
test('rotation spends direct attempts then flood attempts', () {
|
||||
expect(rotating.attemptLimit(floodPath: false), 5);
|
||||
expect(rotating.attemptLimit(floodPath: true), 5);
|
||||
expect(rotating.floodFromAttempt, 4);
|
||||
});
|
||||
|
||||
test('a fixed path uses only that path kind', () {
|
||||
expect(fixed.attemptLimit(floodPath: false), 4);
|
||||
expect(fixed.attemptLimit(floodPath: true), 2);
|
||||
expect(fixed.floodFromAttempt, isNull);
|
||||
});
|
||||
|
||||
test('both limits at zero still send once and do not switch to flood', () {
|
||||
const plan = SendAttemptPlan(
|
||||
directRetries: 0,
|
||||
floodRetries: 0,
|
||||
rotateRoutes: true,
|
||||
);
|
||||
expect(plan.attemptLimit(floodPath: false), 1);
|
||||
expect(plan.floodFromAttempt, isNull);
|
||||
});
|
||||
|
||||
test('direct zero with rotation floods from the first attempt', () {
|
||||
const plan = SendAttemptPlan(
|
||||
directRetries: 0,
|
||||
floodRetries: 3,
|
||||
rotateRoutes: true,
|
||||
);
|
||||
expect(plan.attemptLimit(floodPath: false), 3);
|
||||
expect(plan.floodFromAttempt, 0);
|
||||
});
|
||||
|
||||
test('flood zero with rotation never switches to flood', () {
|
||||
const plan = SendAttemptPlan(
|
||||
directRetries: 6,
|
||||
floodRetries: 0,
|
||||
rotateRoutes: true,
|
||||
);
|
||||
expect(plan.attemptLimit(floodPath: true), 6);
|
||||
expect(plan.floodFromAttempt, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('AppSettings retry migration', () {
|
||||
test('a saved single retry limit becomes direct plus one flood', () {
|
||||
final settings = AppSettings.fromJson({'max_message_retries': 5});
|
||||
expect(settings.directRetries, 4);
|
||||
expect(settings.floodRetries, 1);
|
||||
expect(settings.toJson().containsKey('max_message_retries'), isFalse);
|
||||
});
|
||||
|
||||
test('the old maximum of 10 keeps nine direct attempts and one flood', () {
|
||||
final settings = AppSettings.fromJson({'max_message_retries': 10});
|
||||
expect(settings.directRetries, 9);
|
||||
expect(settings.floodRetries, 1);
|
||||
});
|
||||
|
||||
test('new keys win over a leftover single limit and are clamped', () {
|
||||
final settings = AppSettings.fromJson({
|
||||
'max_message_retries': 5,
|
||||
'max_direct_retries': 40,
|
||||
'max_flood_retries': -2,
|
||||
'login_attempts': 0,
|
||||
});
|
||||
expect(settings.directRetries, SendAttemptPlan.maxDirectRetries);
|
||||
expect(settings.floodRetries, SendAttemptPlan.minFloodRetries);
|
||||
expect(settings.loginAttempts, SendAttemptPlan.minLoginAttempts);
|
||||
});
|
||||
|
||||
test('round trip keeps the split limits', () {
|
||||
final saved = AppSettings(
|
||||
directRetries: 12,
|
||||
floodRetries: 7,
|
||||
loginAttempts: 3,
|
||||
clearPathOnMaxRetry: true,
|
||||
autoRouteRotationEnabled: false,
|
||||
channelMinHopsEnabled: true,
|
||||
).toJson();
|
||||
final restored = AppSettings.fromJson(saved);
|
||||
expect(restored.directRetries, 12);
|
||||
expect(restored.floodRetries, 7);
|
||||
expect(restored.loginAttempts, 3);
|
||||
expect(restored.clearPathOnMaxRetry, isTrue);
|
||||
expect(restored.autoRouteRotationEnabled, isFalse);
|
||||
expect(restored.channelMinHopsEnabled, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
test('reset routing settings restores the moved controls', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await PrefsManager.initialize();
|
||||
final service = AppSettingsService();
|
||||
await service.loadSettings();
|
||||
await service.updateSettings(
|
||||
service.settings.copyWith(
|
||||
clearPathOnMaxRetry: true,
|
||||
autoRouteRotationEnabled: false,
|
||||
directRetries: 15,
|
||||
floodRetries: 10,
|
||||
loginAttempts: 9,
|
||||
channelMinHopsEnabled: true,
|
||||
channelMinHops: 6,
|
||||
channelMinHopsRetries: 4,
|
||||
channelMinHopsCountRepeaters: true,
|
||||
maxRouteWeight: 9,
|
||||
),
|
||||
);
|
||||
|
||||
await service.resetRoutingSettingsToDefault();
|
||||
final settings = service.settings;
|
||||
expect(settings.clearPathOnMaxRetry, isFalse);
|
||||
expect(settings.autoRouteRotationEnabled, isTrue);
|
||||
expect(settings.directRetries, SendAttemptPlan.defaultDirectRetries);
|
||||
expect(settings.floodRetries, SendAttemptPlan.defaultFloodRetries);
|
||||
expect(settings.loginAttempts, 9);
|
||||
expect(settings.channelMinHopsEnabled, isFalse);
|
||||
expect(settings.channelMinHops, 2);
|
||||
expect(settings.channelMinHopsRetries, 1);
|
||||
expect(settings.channelMinHopsCountRepeaters, isFalse);
|
||||
expect(settings.maxRouteWeight, AppSettings.defaultMaxRouteWeight);
|
||||
|
||||
final reloaded = AppSettingsService();
|
||||
await reloaded.loadSettings();
|
||||
expect(
|
||||
reloaded.settings.directRetries,
|
||||
SendAttemptPlan.defaultDirectRetries,
|
||||
);
|
||||
expect(reloaded.settings.floodRetries, SendAttemptPlan.defaultFloodRetries);
|
||||
expect(reloaded.settings.loginAttempts, 9);
|
||||
});
|
||||
|
||||
test('reset repeater and room settings restores that section', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await PrefsManager.initialize();
|
||||
final service = AppSettingsService();
|
||||
await service.loadSettings();
|
||||
await service.updateSettings(
|
||||
service.settings.copyWith(
|
||||
clockSyncAfterLogin: true,
|
||||
loginPasswordAutofocus: true,
|
||||
autoFetchRepeaterSettings: true,
|
||||
loginAttempts: 8,
|
||||
directRetries: 12,
|
||||
),
|
||||
);
|
||||
|
||||
await service.resetRepeaterRoomSettingsToDefault();
|
||||
final settings = service.settings;
|
||||
expect(settings.clockSyncAfterLogin, isFalse);
|
||||
expect(settings.loginPasswordAutofocus, isFalse);
|
||||
expect(settings.autoFetchRepeaterSettings, isFalse);
|
||||
expect(settings.loginAttempts, SendAttemptPlan.defaultLoginAttempts);
|
||||
expect(settings.directRetries, 12);
|
||||
});
|
||||
}
|
||||
@@ -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<Contact> hopContacts;
|
||||
|
||||
@override
|
||||
List<Contact> 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<MeshCoreConnector>.value(
|
||||
value: connector,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: ChannelMessagePathScreen(
|
||||
message: message,
|
||||
channelMessage: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final avatarNames = tester
|
||||
.widgetList<AvatarCircle>(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,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,419 @@
|
||||
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<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));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// 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<void> _seedRadio({
|
||||
bool smazCompressed = false,
|
||||
int repeatCount = 0,
|
||||
}) 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,
|
||||
isSmazCompressed: smazCompressed,
|
||||
repeatCount: repeatCount,
|
||||
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,
|
||||
isSmazCompressed: smazCompressed,
|
||||
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<Widget> _app(
|
||||
WidgetTester tester,
|
||||
MeshCoreConnector connector,
|
||||
Widget home, {
|
||||
bool showCompressionIndicator = false,
|
||||
bool enableMessageTracing = false,
|
||||
}) async {
|
||||
final storage = StorageService();
|
||||
final settings = AppSettingsService();
|
||||
await tester.runAsync(() async {
|
||||
await settings.loadSettings();
|
||||
if (showCompressionIndicator) {
|
||||
await settings.setShowCompressionIndicator(true);
|
||||
}
|
||||
if (enableMessageTracing) {
|
||||
await settings.setEnableMessageTracing(true);
|
||||
}
|
||||
});
|
||||
final translation = TranslationService(settings);
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: MessageRetryService()),
|
||||
ChangeNotifierProvider.value(value: PathHistoryService(storage)),
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: BleDebugLogService()),
|
||||
ChangeNotifierProvider.value(value: AppDebugLogService()),
|
||||
ChangeNotifierProvider.value(value: ChatTextScaleService()),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: UiViewStateService()),
|
||||
Provider.value(value: storage),
|
||||
ChangeNotifierProvider.value(
|
||||
value: MapTileCacheService(appSettingsService: settings),
|
||||
),
|
||||
ChangeNotifierProvider.value(value: TimeoutPredictionService(storage)),
|
||||
ChangeNotifierProvider.value(value: ImageCodecService(settings)),
|
||||
ChangeNotifierProvider.value(value: ReceivedImageStore()),
|
||||
ChangeNotifierProvider.value(
|
||||
value: NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: home,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _settle(WidgetTester tester) async {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
/// Horizontal extent of every rendered bubble, in transcript order.
|
||||
List<String> _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<List<String>> _render(
|
||||
WidgetTester tester,
|
||||
_ToggleConnector connector,
|
||||
Widget Function() screen, {
|
||||
required bool connected,
|
||||
bool showCompressionIndicator = false,
|
||||
bool enableMessageTracing = false,
|
||||
bool expectCompressionIndicator = false,
|
||||
}) async {
|
||||
connector.connected = connected;
|
||||
await tester.pumpWidget(
|
||||
await _app(
|
||||
tester,
|
||||
connector,
|
||||
screen(),
|
||||
showCompressionIndicator: showCompressionIndicator,
|
||||
enableMessageTracing: enableMessageTracing,
|
||||
),
|
||||
);
|
||||
await _settle(tester);
|
||||
if (expectCompressionIndicator) {
|
||||
expect(find.byType(CompressionIndicator), findsNWidgets(5));
|
||||
}
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'channel and DM bubbles with SMAZ compression indicator fit 320dp, 2.0x text',
|
||||
(tester) async {
|
||||
ChannelMessageStore().forgetArchive();
|
||||
MessageStore().forgetArchive();
|
||||
await _seedRadio(smazCompressed: true, repeatCount: 2);
|
||||
ChannelMessageStore().forgetArchive();
|
||||
MessageStore().forgetArchive();
|
||||
|
||||
PlatformInfo.debugIsDesktopOverride = false;
|
||||
addTearDown(() => PlatformInfo.debugIsDesktopOverride = null);
|
||||
tester.view.physicalSize = const Size(320, 4000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2.0;
|
||||
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 alice = connector.contacts.single;
|
||||
|
||||
final channelOffline = await _render(
|
||||
tester,
|
||||
connector,
|
||||
() => ChannelChatScreen(channel: channel),
|
||||
connected: false,
|
||||
showCompressionIndicator: true,
|
||||
enableMessageTracing: true,
|
||||
expectCompressionIndicator: true,
|
||||
);
|
||||
final channelConnected = await _render(
|
||||
tester,
|
||||
connector,
|
||||
() => ChannelChatScreen(channel: channel),
|
||||
connected: true,
|
||||
showCompressionIndicator: true,
|
||||
enableMessageTracing: true,
|
||||
expectCompressionIndicator: true,
|
||||
);
|
||||
expect(channelOffline, hasLength(5));
|
||||
expect(channelConnected, channelOffline);
|
||||
|
||||
final dmOffline = await _render(
|
||||
tester,
|
||||
connector,
|
||||
() => ChatScreen(contact: alice),
|
||||
connected: false,
|
||||
showCompressionIndicator: true,
|
||||
enableMessageTracing: true,
|
||||
expectCompressionIndicator: true,
|
||||
);
|
||||
final dmConnected = await _render(
|
||||
tester,
|
||||
connector,
|
||||
() => ChatScreen(contact: alice),
|
||||
connected: true,
|
||||
showCompressionIndicator: true,
|
||||
enableMessageTracing: true,
|
||||
expectCompressionIndicator: true,
|
||||
);
|
||||
expect(dmOffline, hasLength(5));
|
||||
expect(dmConnected, dmOffline);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,619 @@
|
||||
import 'dart:convert';
|
||||
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:provider/single_child_widget.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/helpers/message_url_image_helper.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/image_codec_support.dart';
|
||||
import 'package:meshcore_open/review_mode/review_frames.dart';
|
||||
import 'package:meshcore_open/review_mode/review_radio.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/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/prefs_manager.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/widgets/gif_message.dart';
|
||||
import 'package:meshcore_open/widgets/message_bubble_frame.dart';
|
||||
import 'package:meshcore_open/widgets/received_image_message.dart';
|
||||
import 'package:meshcore_open/widgets/shared_contact_card.dart';
|
||||
|
||||
final _l10n = lookupAppLocalizations(const Locale('en'));
|
||||
|
||||
const _contactShareHex =
|
||||
'50ba28f599799142622d188469a63f3890d495cdcedd24239052abd364c0283d';
|
||||
const _contactShareToken = '<$_contactShareHex:1:Bob>';
|
||||
const _gifToken = 'g:testgif123';
|
||||
const _markerToken = 'm:45.515232,-122.678385|Camp|poi';
|
||||
const _urlText = 'Check https://example.com/photo.png';
|
||||
const _png1x1 =
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFAAH/q842iQAAAABJRU5ErkJggg==';
|
||||
|
||||
(MeshCoreConnector, List<SingleChildWidget>, ReceivedImageStore)? _shared;
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final tempDir = Directory.systemTemp.createTempSync('copy_messages_test');
|
||||
String? copiedText;
|
||||
late bool previousLoadLinkImages;
|
||||
|
||||
setUpAll(() async {
|
||||
previousLoadLinkImages = MessageUrlImageHelper.loadLinkImages.value;
|
||||
MessageUrlImageHelper.loadLinkImages.value = false;
|
||||
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('plugins.flutter.io/path_provider'),
|
||||
(call) async => tempDir.path,
|
||||
);
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copiedText =
|
||||
(call.arguments as Map<dynamic, dynamic>)['text'] as String?;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
MessageUrlImageHelper.loadLinkImages.value = previousLoadLinkImages;
|
||||
_shared = null;
|
||||
if (tempDir.existsSync()) {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
copiedText = null;
|
||||
});
|
||||
|
||||
/// Scrolls the reversed chat ListView upward toward older items until
|
||||
/// [target] is built and centered in the viewport.
|
||||
Future<void> scrollToTarget(WidgetTester tester, Finder target) async {
|
||||
final scrollable = find.byType(Scrollable).first;
|
||||
if (target.evaluate().isEmpty) {
|
||||
await tester.dragUntilVisible(
|
||||
target,
|
||||
scrollable,
|
||||
const Offset(0, 200),
|
||||
maxIteration: 30,
|
||||
);
|
||||
}
|
||||
await Scrollable.ensureVisible(tester.element(target), alignment: 0.5);
|
||||
await _settle(tester);
|
||||
}
|
||||
|
||||
/// Opens the message action sheet by long-pressing the bubble padding
|
||||
/// (outside desktop SelectableLinkify) and taps Copy.
|
||||
Future<void> copyFromBubbleContaining(
|
||||
WidgetTester tester,
|
||||
Finder contentFinder,
|
||||
) async {
|
||||
await scrollToTarget(tester, contentFinder);
|
||||
final bubble = find.ancestor(
|
||||
of: contentFinder,
|
||||
matching: find.byType(MessageBubbleFrame),
|
||||
);
|
||||
await tester.longPressAt(tester.getTopLeft(bubble) + const Offset(8, 8));
|
||||
await _settle(tester);
|
||||
await tester.tap(find.text(_l10n.common_copy));
|
||||
await _settle(tester);
|
||||
}
|
||||
|
||||
/// Opens the action sheet on a non-text special widget and taps Copy.
|
||||
Future<void> copyFromWidget(WidgetTester tester, Finder widgetFinder) async {
|
||||
await scrollToTarget(tester, widgetFinder);
|
||||
await tester.longPressAt(tester.getCenter(widgetFinder));
|
||||
await _settle(tester);
|
||||
await tester.tap(find.text(_l10n.common_copy));
|
||||
await _settle(tester);
|
||||
}
|
||||
|
||||
group('ChannelChatScreen & ChatScreen copy', () {
|
||||
testWidgets('copies special channel messages (contact, GIF, location, URL) '
|
||||
'and image metadata/caption', (tester) async {
|
||||
final (connector, providers, imageStore) = _shared ??= await _connect(
|
||||
tester,
|
||||
);
|
||||
final channel = connector.channels[2];
|
||||
final nowSecs = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
await tester.runAsync(() async {
|
||||
await connector.sendChannelMessage(channel, _contactShareToken);
|
||||
await connector.sendChannelMessage(channel, _gifToken);
|
||||
await connector.sendChannelMessage(channel, _markerToken);
|
||||
await connector.sendChannelMessage(channel, _urlText);
|
||||
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Maya',
|
||||
message: _contactShareToken,
|
||||
timestampSecs: nowSecs - 40,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Maya',
|
||||
message: _gifToken,
|
||||
timestampSecs: nowSecs - 30,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Maya',
|
||||
message: _markerToken,
|
||||
timestampSecs: nowSecs - 20,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Maya',
|
||||
message: _urlText,
|
||||
timestampSecs: nowSecs - 10,
|
||||
),
|
||||
);
|
||||
|
||||
await imageStore.registerOutgoing(
|
||||
channelIndex: channel.index,
|
||||
channelId: channel.storageId,
|
||||
senderPrefix: 0x1234,
|
||||
imgId: 1,
|
||||
previewPng: Uint8List.fromList(base64Decode(_png1x1)),
|
||||
rate: AeicRatePoint.ft32,
|
||||
chunkCount: 2,
|
||||
synthesized: true,
|
||||
payloadBytes: 156,
|
||||
);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
});
|
||||
|
||||
await _pump(tester, providers, ChannelChatScreen(channel: channel));
|
||||
|
||||
// Image message (newest, at bottom): long-press -> Copy copies metadata
|
||||
// + R6 caption.
|
||||
final imageBubble = find.byType(ReceivedImageMessage);
|
||||
expect(imageBubble, findsOneWidget);
|
||||
await copyFromWidget(tester, imageBubble);
|
||||
expect(copiedText, contains(_l10n.receivedImage_awaiting(156, 2)));
|
||||
expect(copiedText, contains(_l10n.receivedImage_shareCaption(156)));
|
||||
|
||||
// Received special messages
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find
|
||||
.textContaining('https://example.com/photo.png', findRichText: true)
|
||||
.first,
|
||||
);
|
||||
expect(copiedText, _urlText);
|
||||
|
||||
await copyFromWidget(tester, find.text(_l10n.chat_poiShared).first);
|
||||
expect(copiedText, _markerToken);
|
||||
|
||||
await copyFromWidget(tester, find.byType(GifMessage).first);
|
||||
expect(copiedText, _gifToken);
|
||||
|
||||
await copyFromWidget(tester, find.byType(SharedContactCard).first);
|
||||
expect(copiedText, _contactShareToken);
|
||||
|
||||
// Sent special messages (further up the transcript)
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find
|
||||
.textContaining('https://example.com/photo.png', findRichText: true)
|
||||
.last,
|
||||
);
|
||||
expect(copiedText, _urlText);
|
||||
|
||||
await copyFromWidget(tester, find.text(_l10n.chat_poiShared).last);
|
||||
expect(copiedText, _markerToken);
|
||||
|
||||
await copyFromWidget(tester, find.byType(GifMessage).last);
|
||||
expect(copiedText, _gifToken);
|
||||
|
||||
await copyFromWidget(tester, find.byType(SharedContactCard).last);
|
||||
expect(copiedText, _contactShareToken);
|
||||
|
||||
// Verify image action sheet fits 320dp at 1.3x and 2.0x text scale.
|
||||
for (final scale in [1.3, 2.0]) {
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: MediaQueryData(
|
||||
size: const Size(320, 568),
|
||||
textScaler: TextScaler.linear(scale),
|
||||
),
|
||||
child: MultiProvider(
|
||||
providers: providers,
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: ChannelChatScreen(channel: channel),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await _settle(tester);
|
||||
await scrollToTarget(tester, find.byType(ReceivedImageMessage));
|
||||
await tester.longPress(find.byType(ReceivedImageMessage));
|
||||
await _settle(tester);
|
||||
expect(find.text(_l10n.common_copy), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
Navigator.of(tester.element(find.text(_l10n.common_copy))).pop();
|
||||
await _settle(tester);
|
||||
}
|
||||
tester.view.resetPhysicalSize();
|
||||
tester.view.resetDevicePixelRatio();
|
||||
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('copies regular, @[username], and special DM messages '
|
||||
'(sent and received)', (tester) async {
|
||||
final (connector, providers, _) = _shared ??= await _connect(tester);
|
||||
final contact = connector.contacts.firstWhere(
|
||||
(c) => c.type == advTypeChat,
|
||||
);
|
||||
final nowSecs = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
await tester.runAsync(() async {
|
||||
await connector.sendMessage(contact, '@[Maya] DM mention sent');
|
||||
await connector.sendMessage(contact, _contactShareToken);
|
||||
await connector.sendMessage(contact, _gifToken);
|
||||
await connector.sendMessage(contact, _markerToken);
|
||||
await connector.sendMessage(contact, _urlText);
|
||||
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.contactMessage(
|
||||
senderPublicKey: contact.publicKey,
|
||||
text: 'Regular DM received',
|
||||
timestampSecs: nowSecs - 50,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.contactMessage(
|
||||
senderPublicKey: contact.publicKey,
|
||||
text: '@[Review Radio] DM mention received',
|
||||
timestampSecs: nowSecs - 40,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.contactMessage(
|
||||
senderPublicKey: contact.publicKey,
|
||||
text: _contactShareToken,
|
||||
timestampSecs: nowSecs - 30,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.contactMessage(
|
||||
senderPublicKey: contact.publicKey,
|
||||
text: _gifToken,
|
||||
timestampSecs: nowSecs - 20,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.contactMessage(
|
||||
senderPublicKey: contact.publicKey,
|
||||
text: _markerToken,
|
||||
timestampSecs: nowSecs - 10,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.contactMessage(
|
||||
senderPublicKey: contact.publicKey,
|
||||
text: _urlText,
|
||||
timestampSecs: nowSecs - 5,
|
||||
),
|
||||
);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
});
|
||||
|
||||
await _pump(tester, providers, ChatScreen(contact: contact));
|
||||
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find
|
||||
.textContaining('https://example.com/photo.png', findRichText: true)
|
||||
.first,
|
||||
);
|
||||
expect(copiedText, _urlText);
|
||||
|
||||
await copyFromWidget(tester, find.text(_l10n.chat_poiShared).first);
|
||||
expect(copiedText, _markerToken);
|
||||
|
||||
await copyFromWidget(tester, find.byType(GifMessage).first);
|
||||
expect(copiedText, _gifToken);
|
||||
|
||||
await copyFromWidget(tester, find.byType(SharedContactCard).first);
|
||||
expect(copiedText, _contactShareToken);
|
||||
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find.textContaining('DM mention received', findRichText: true),
|
||||
);
|
||||
expect(copiedText, '@[Review Radio] DM mention received');
|
||||
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find.textContaining('Regular DM received', findRichText: true),
|
||||
);
|
||||
expect(copiedText, 'Regular DM received');
|
||||
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find
|
||||
.textContaining('https://example.com/photo.png', findRichText: true)
|
||||
.last,
|
||||
);
|
||||
expect(copiedText, _urlText);
|
||||
|
||||
await copyFromWidget(tester, find.text(_l10n.chat_poiShared).last);
|
||||
expect(copiedText, _markerToken);
|
||||
|
||||
await copyFromWidget(tester, find.byType(GifMessage).last);
|
||||
expect(copiedText, _gifToken);
|
||||
|
||||
await copyFromWidget(tester, find.byType(SharedContactCard).last);
|
||||
expect(copiedText, _contactShareToken);
|
||||
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find.textContaining('DM mention sent', findRichText: true),
|
||||
);
|
||||
expect(copiedText, '@[Maya] DM mention sent');
|
||||
|
||||
await _tearDown(tester);
|
||||
});
|
||||
|
||||
testWidgets('copies sent and received channel replies with @[username] '
|
||||
'and leaves regular messages unchanged', (tester) async {
|
||||
final (connector, providers, _) = _shared ??= await _connect(tester);
|
||||
final channel = connector.channels[1];
|
||||
final nowSecs = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
await tester.runAsync(() async {
|
||||
await connector.sendChannelMessage(channel, 'Plain outgoing');
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Maya',
|
||||
message: 'Regular channel hello',
|
||||
timestampSecs: nowSecs - 40,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Jordan',
|
||||
message: '@[Maya] Matched channel reply',
|
||||
timestampSecs: nowSecs - 30,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Sam',
|
||||
message: '@[GhostNode] Unmatched channel reply',
|
||||
timestampSecs: nowSecs - 20,
|
||||
),
|
||||
);
|
||||
connector.handleFrameForTest(
|
||||
ReviewFrames.channelMessage(
|
||||
channelIndex: channel.index,
|
||||
sender: 'Ranger Pat',
|
||||
message: 'Reply target message',
|
||||
timestampSecs: nowSecs - 10,
|
||||
),
|
||||
);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
});
|
||||
|
||||
await _pump(tester, providers, ChannelChatScreen(channel: channel));
|
||||
|
||||
// Reply to Ranger Pat's message via UI composer and send.
|
||||
final replyTargetText = find.textContaining(
|
||||
'Reply target message',
|
||||
findRichText: true,
|
||||
);
|
||||
await scrollToTarget(tester, replyTargetText);
|
||||
final targetBubble = find.ancestor(
|
||||
of: replyTargetText,
|
||||
matching: find.byType(MessageBubbleFrame),
|
||||
);
|
||||
await tester.longPressAt(
|
||||
tester.getTopLeft(targetBubble) + const Offset(8, 8),
|
||||
);
|
||||
await _settle(tester);
|
||||
await tester.tap(find.text(_l10n.chat_reply));
|
||||
await _settle(tester);
|
||||
await tester.enterText(find.byType(TextField), 'Sent reply body');
|
||||
await _settle(tester);
|
||||
await tester.tap(find.byTooltip(_l10n.chat_sendMessage));
|
||||
await _settle(tester);
|
||||
|
||||
// 1. Sent reply includes @[Ranger Pat].
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find.textContaining('Sent reply body', findRichText: true),
|
||||
);
|
||||
expect(copiedText, '@[Ranger Pat] Sent reply body');
|
||||
|
||||
// 2. Bulk copy on the sent reply also includes @[Ranger Pat].
|
||||
final sentReplyBubble = find.ancestor(
|
||||
of: find.textContaining('Sent reply body', findRichText: true),
|
||||
matching: find.byType(MessageBubbleFrame),
|
||||
);
|
||||
await tester.longPressAt(
|
||||
tester.getTopLeft(sentReplyBubble) + const Offset(8, 8),
|
||||
);
|
||||
await _settle(tester);
|
||||
await tester.tap(find.text(_l10n.chat_selectMessages));
|
||||
await _settle(tester);
|
||||
await tester.tap(find.byIcon(Icons.more_vert));
|
||||
await _settle(tester);
|
||||
await tester.tap(find.text(_l10n.common_copy));
|
||||
await _settle(tester);
|
||||
expect(copiedText, '@[Ranger Pat] Sent reply body');
|
||||
|
||||
// 3. Received unmatched reply includes @[GhostNode].
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find.textContaining('Unmatched channel reply', findRichText: true),
|
||||
);
|
||||
expect(copiedText, '@[GhostNode] Unmatched channel reply');
|
||||
|
||||
// 4. Received matched reply includes @[Maya].
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find.textContaining('Matched channel reply', findRichText: true),
|
||||
);
|
||||
expect(copiedText, '@[Maya] Matched channel reply');
|
||||
|
||||
// 5. Regular incoming message unchanged.
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find.textContaining('Regular channel hello', findRichText: true).last,
|
||||
);
|
||||
expect(copiedText, 'Regular channel hello');
|
||||
|
||||
// 6. Regular outgoing message unchanged.
|
||||
await copyFromBubbleContaining(
|
||||
tester,
|
||||
find.textContaining('Plain outgoing', findRichText: true),
|
||||
);
|
||||
expect(copiedText, 'Plain outgoing');
|
||||
|
||||
await _tearDown(tester);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _pump(
|
||||
WidgetTester tester,
|
||||
List<SingleChildWidget> providers,
|
||||
Widget home,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: providers,
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: home,
|
||||
),
|
||||
),
|
||||
);
|
||||
await _settle(tester);
|
||||
}
|
||||
|
||||
Future<void> _settle(WidgetTester tester) async {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _tearDown(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pump(const Duration(hours: 2));
|
||||
}
|
||||
|
||||
Future<(MeshCoreConnector, List<SingleChildWidget>, ReceivedImageStore)>
|
||||
_connect(WidgetTester tester) async {
|
||||
final storage = StorageService();
|
||||
final connector = MeshCoreConnector();
|
||||
final retry = MessageRetryService();
|
||||
final settings = AppSettingsService();
|
||||
final translation = TranslationService(settings);
|
||||
final imageStore = ReceivedImageStore();
|
||||
|
||||
await tester.runAsync(() async {
|
||||
await settings.loadSettings();
|
||||
connector.initialize(
|
||||
retryService: retry,
|
||||
pathHistoryService: PathHistoryService(storage),
|
||||
appSettingsService: settings,
|
||||
translationService: translation,
|
||||
);
|
||||
connector.reviewRadioFactoryForTest = () => ReviewRadio(
|
||||
scheduledMessageInterval: const Duration(hours: 1),
|
||||
ackDelay: const Duration(milliseconds: 50),
|
||||
replyDelay: const Duration(hours: 1),
|
||||
);
|
||||
await connector.connectReview();
|
||||
final end = DateTime.now().add(const Duration(seconds: 8));
|
||||
while ((connector.contacts.isEmpty ||
|
||||
connector.channels.isEmpty ||
|
||||
!connector.channelMapConfirmed) &&
|
||||
DateTime.now().isBefore(end)) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 25));
|
||||
}
|
||||
});
|
||||
expect(connector.channels, isNotEmpty);
|
||||
|
||||
return (
|
||||
connector,
|
||||
<SingleChildWidget>[
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: retry),
|
||||
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: imageStore),
|
||||
],
|
||||
imageStore,
|
||||
);
|
||||
}
|
||||
@@ -95,7 +95,11 @@ void main() {
|
||||
viewState.dispose();
|
||||
});
|
||||
|
||||
Future<void> openMap(WidgetTester tester) async {
|
||||
Future<void> 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<Text>(
|
||||
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<Text>(
|
||||
find.descendant(
|
||||
of: find.byType(MarkerLayer),
|
||||
matching: find.text('Repeater'),
|
||||
),
|
||||
);
|
||||
expect(label.style?.color, MeshTheme.light().colorScheme.onSurface);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,601 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.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/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/models/custom_theme.dart';
|
||||
import 'package:meshcore_open/models/send_attempt_plan.dart';
|
||||
import 'package:meshcore_open/screens/app_settings_screen.dart';
|
||||
import 'package:meshcore_open/screens/repeater_settings_screen.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/network_map/network_map_upload_service.dart';
|
||||
import 'package:meshcore_open/services/storage_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/mesh_ui.dart';
|
||||
import 'package:meshcore_open/widgets/settings_reveal.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'routing settings show both retry limits and reveal channel options',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await PrefsManager.initialize();
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(autoRouteRotationEnabled: false),
|
||||
);
|
||||
|
||||
tester.view.physicalSize = const Size(800, 8000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final connector = MeshCoreConnector();
|
||||
final translation = TranslationService(settings);
|
||||
final uploads = NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
);
|
||||
addTearDown(connector.dispose);
|
||||
addTearDown(translation.dispose);
|
||||
addTearDown(uploads.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: uploads),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: AppSettingsScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(find.byType(AppSettingsScreen));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
expect(find.text(l10n.appSettings_clearPathOnMaxRetry), findsOneWidget);
|
||||
expect(
|
||||
find.text(
|
||||
l10n.appSettings_directRetries(SendAttemptPlan.defaultDirectRetries),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text(
|
||||
l10n.appSettings_floodRetries(SendAttemptPlan.defaultFloodRetries),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text(
|
||||
l10n.appSettings_loginAttempts(SendAttemptPlan.defaultLoginAttempts),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
// Retry limits stay visible while route rotation is off.
|
||||
expect(find.text(l10n.appSettings_autoRouteRotation), findsOneWidget);
|
||||
expect(find.text(l10n.appSettings_channelMinHopsCount(2)), findsNothing);
|
||||
expect(find.text(l10n.appSettings_resetRoutingToDefault), findsOneWidget);
|
||||
expect(
|
||||
find.text(l10n.appSettings_repeatersAndRooms.toUpperCase()),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_clockSyncAfterLogin), findsOneWidget);
|
||||
expect(
|
||||
find.text(l10n.appSettings_loginPasswordAutofocus),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text(l10n.appSettings_autoFetchRepeaterSettings),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
final channelSwitch = find.text(l10n.appSettings_channelMinHops);
|
||||
await tester.tap(channelSwitch);
|
||||
await tester.pump();
|
||||
await tester.pump(RevealOnEnable.duration);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
find.text(l10n.appSettings_channelMinHopsCount(2)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text(l10n.appSettings_channelMinHopsRetries(1)),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(channelSwitch);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(l10n.appSettings_channelMinHopsCount(2)), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'routing and repeaters/rooms rows and clock-sync selector have leading 24px icons with aligned titles',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(channelMinHopsEnabled: true),
|
||||
);
|
||||
|
||||
tester.view.physicalSize = const Size(800, 8000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final connector = MeshCoreConnector();
|
||||
final translation = TranslationService(settings);
|
||||
final uploads = NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
);
|
||||
addTearDown(connector.dispose);
|
||||
addTearDown(translation.dispose);
|
||||
addTearDown(uploads.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: uploads),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
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 topLevelTitles = [
|
||||
l10n.appSettings_clearPathOnMaxRetry,
|
||||
l10n.appSettings_directRetries(settings.settings.directRetries),
|
||||
l10n.appSettings_floodRetries(settings.settings.floodRetries),
|
||||
l10n.appSettings_autoRouteRotation,
|
||||
l10n.appSettings_channelMinHops,
|
||||
l10n.appSettings_resetRoutingToDefault,
|
||||
l10n.appSettings_clockSyncAfterLogin,
|
||||
l10n.appSettings_loginPasswordAutofocus,
|
||||
l10n.appSettings_loginAttempts(settings.settings.loginAttempts),
|
||||
l10n.appSettings_autoFetchRepeaterSettings,
|
||||
l10n.appSettings_resetRepeaterRoomSettings,
|
||||
];
|
||||
final revealedTitles = [
|
||||
l10n.appSettings_channelMinHopsCount(settings.settings.channelMinHops),
|
||||
l10n.appSettings_channelMinHopsRetries(
|
||||
settings.settings.channelMinHopsRetries,
|
||||
),
|
||||
l10n.appSettings_channelMinHopsCountRepeaters,
|
||||
];
|
||||
|
||||
double expectRowLeadingIcon(String title) {
|
||||
final titleFinder = find.text(title);
|
||||
expect(titleFinder, findsOneWidget, reason: 'Missing row "$title"');
|
||||
final tileFinder = find.ancestor(
|
||||
of: titleFinder,
|
||||
matching: find.byType(ListTile),
|
||||
);
|
||||
expect(tileFinder, findsOneWidget, reason: 'No ListTile for "$title"');
|
||||
final iconFinder = find.descendant(
|
||||
of: tileFinder,
|
||||
matching: find.byType(Icon),
|
||||
);
|
||||
final icons = tester.widgetList<Icon>(iconFinder).toList();
|
||||
final titleRect = tester.getRect(titleFinder);
|
||||
final leadingIcons = [
|
||||
for (var i = 0; i < icons.length; i++)
|
||||
if (tester.getRect(iconFinder.at(i)).right < titleRect.left)
|
||||
(icon: icons[i], rect: tester.getRect(iconFinder.at(i))),
|
||||
];
|
||||
expect(
|
||||
leadingIcons,
|
||||
hasLength(1),
|
||||
reason: 'Expected 1 leading icon for "$title"',
|
||||
);
|
||||
expect(
|
||||
leadingIcons.single.icon.size,
|
||||
24,
|
||||
reason: 'Leading icon for "$title" must be 24px',
|
||||
);
|
||||
expect(
|
||||
leadingIcons.single.rect.size,
|
||||
const Size(24, 24),
|
||||
reason: 'Rendered leading icon for "$title" must be 24x24',
|
||||
);
|
||||
return titleRect.left;
|
||||
}
|
||||
|
||||
final topTitleLefts = [
|
||||
for (final title in topLevelTitles) expectRowLeadingIcon(title),
|
||||
];
|
||||
for (final left in topTitleLefts) {
|
||||
expect(left, closeTo(topTitleLefts.first, 0.5));
|
||||
}
|
||||
|
||||
final revealedTitleLefts = [
|
||||
for (final title in revealedTitles) expectRowLeadingIcon(title),
|
||||
];
|
||||
for (final left in revealedTitleLefts) {
|
||||
expect(left, closeTo(topTitleLefts.first + 16, 0.5));
|
||||
}
|
||||
|
||||
// Check the Default / On / Off clock-sync selector on RepeaterSettingsScreen.
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: RepeaterSettingsScreen(
|
||||
repeater: Contact(
|
||||
publicKey: Uint8List(32),
|
||||
name: 'Repeater',
|
||||
type: 2,
|
||||
pathLength: 0,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime(2026),
|
||||
),
|
||||
password: 'x',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
|
||||
final rContext = tester.element(find.byType(RepeaterSettingsScreen));
|
||||
final rL10n = AppLocalizations.of(rContext);
|
||||
final selectorTitle = find.text(rL10n.repeater_clockSyncAfterLogin);
|
||||
await tester.ensureVisible(selectorTitle);
|
||||
await tester.pump();
|
||||
|
||||
expect(
|
||||
find.byType(SegmentedButton<RepeaterClockSyncOverride>),
|
||||
findsOneWidget,
|
||||
);
|
||||
for (final label in [
|
||||
rL10n.repeater_clockSyncDefault,
|
||||
rL10n.repeater_clockSyncOn,
|
||||
rL10n.repeater_clockSyncOff,
|
||||
]) {
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(w) => w is MeshSegmentLabel && w.text == label,
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
|
||||
final clockIconFinder = find.byIcon(Icons.schedule);
|
||||
expect(clockIconFinder, findsOneWidget);
|
||||
final clockIcon = tester.widget<Icon>(clockIconFinder);
|
||||
expect(clockIcon.size, 24);
|
||||
final clockIconRect = tester.getRect(clockIconFinder);
|
||||
final selectorTitleRect = tester.getRect(selectorTitle);
|
||||
expect(clockIconRect.size, const Size(24, 24));
|
||||
expect(selectorTitleRect.left - clockIconRect.right, closeTo(16, 0.5));
|
||||
},
|
||||
);
|
||||
|
||||
for (final scale in [1.3, 2.0]) {
|
||||
testWidgets(
|
||||
'routing, repeaters/rooms, and clock-sync selector fit 320dp at ${scale}x',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(channelMinHopsEnabled: true),
|
||||
);
|
||||
|
||||
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 connector = MeshCoreConnector();
|
||||
final translation = TranslationService(settings);
|
||||
final uploads = NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
);
|
||||
addTearDown(connector.dispose);
|
||||
addTearDown(translation.dispose);
|
||||
addTearDown(uploads.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
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();
|
||||
|
||||
final context = tester.element(find.byType(AppSettingsScreen));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
for (final label in [
|
||||
l10n.appSettings_clearPathOnMaxRetry,
|
||||
l10n.appSettings_directRetries(settings.settings.directRetries),
|
||||
l10n.appSettings_floodRetries(settings.settings.floodRetries),
|
||||
l10n.appSettings_channelMinHopsCount(
|
||||
settings.settings.channelMinHops,
|
||||
),
|
||||
l10n.appSettings_channelMinHopsRetries(
|
||||
settings.settings.channelMinHopsRetries,
|
||||
),
|
||||
l10n.appSettings_channelMinHopsCountRepeaters,
|
||||
l10n.appSettings_resetRoutingToDefault,
|
||||
l10n.appSettings_clockSyncAfterLogin,
|
||||
l10n.appSettings_loginPasswordAutofocus,
|
||||
l10n.appSettings_loginAttempts(settings.settings.loginAttempts),
|
||||
l10n.appSettings_autoFetchRepeaterSettings,
|
||||
l10n.appSettings_resetRepeaterRoomSettings,
|
||||
]) {
|
||||
await tester.scrollUntilVisible(
|
||||
find.text(label),
|
||||
200,
|
||||
maxScrolls: 100,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text(label), findsOneWidget);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
],
|
||||
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: RepeaterSettingsScreen(
|
||||
repeater: Contact(
|
||||
publicKey: Uint8List(32),
|
||||
name: 'Repeater',
|
||||
type: 2,
|
||||
pathLength: 0,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime(2026),
|
||||
),
|
||||
password: 'x',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
|
||||
final rContext = tester.element(find.byType(RepeaterSettingsScreen));
|
||||
final rL10n = AppLocalizations.of(rContext);
|
||||
await tester.scrollUntilVisible(
|
||||
find.text(rL10n.repeater_clockSyncAfterLogin),
|
||||
200,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.text(rL10n.repeater_clockSyncAfterLogin), findsOneWidget);
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(w) =>
|
||||
w is MeshSegmentLabel &&
|
||||
w.text == rL10n.repeater_clockSyncDefault,
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
FlutterError.onError = previous;
|
||||
expect(overflows, isEmpty, reason: overflows.join('\n'));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
for (final entry in <(String, ThemeData)>[
|
||||
('light', MeshTheme.light()),
|
||||
('dark', MeshTheme.dark()),
|
||||
for (final preset in [
|
||||
...CustomTheme.presets,
|
||||
...CustomTheme.holidayPresets,
|
||||
])
|
||||
('custom:${preset.name}', MeshTheme.fromCustom(preset)),
|
||||
]) {
|
||||
testWidgets(
|
||||
'slider inactive track, tick marks, and drag bubble contrast inside SettingsReveal and MeshCard (${entry.$1})',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(channelMinHopsEnabled: true),
|
||||
);
|
||||
|
||||
tester.view.physicalSize = const Size(800, 8000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final connector = MeshCoreConnector();
|
||||
final translation = TranslationService(settings);
|
||||
final uploads = NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
);
|
||||
addTearDown(connector.dispose);
|
||||
addTearDown(translation.dispose);
|
||||
addTearDown(uploads.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: uploads),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: entry.$2,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const AppSettingsScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final screenContext = tester.element(find.byType(AppSettingsScreen));
|
||||
final l10n = AppLocalizations.of(screenContext);
|
||||
final scheme = entry.$2.colorScheme;
|
||||
|
||||
final revealFinder = find.byType(SettingsReveal).first;
|
||||
final revealMaterial = tester.widget<Material>(
|
||||
find
|
||||
.descendant(of: revealFinder, matching: find.byType(Material))
|
||||
.first,
|
||||
);
|
||||
final revealBg = revealMaterial.color!;
|
||||
expect(revealBg, scheme.surfaceContainerHighest);
|
||||
|
||||
final directRowFinder = find.ancestor(
|
||||
of: find.text(
|
||||
l10n.appSettings_directRetries(settings.settings.directRetries),
|
||||
),
|
||||
matching: find.byType(SettingsValueSlider),
|
||||
);
|
||||
final directCardMaterial = tester.widget<Material>(
|
||||
find
|
||||
.ancestor(of: directRowFinder, matching: find.byType(Material))
|
||||
.first,
|
||||
);
|
||||
final cardBg = directCardMaterial.color!;
|
||||
expect(cardBg, scheme.surfaceContainerLow);
|
||||
|
||||
final hopsRowFinder = find.ancestor(
|
||||
of: find.text(
|
||||
l10n.appSettings_channelMinHopsCount(
|
||||
settings.settings.channelMinHops,
|
||||
),
|
||||
),
|
||||
matching: find.byType(SettingsValueSlider),
|
||||
);
|
||||
final revealedSliderFinder = find.descendant(
|
||||
of: hopsRowFinder,
|
||||
matching: find.byType(Slider),
|
||||
);
|
||||
final directSliderFinder = find.descendant(
|
||||
of: directRowFinder,
|
||||
matching: find.byType(Slider),
|
||||
);
|
||||
|
||||
for (final sliderFinder in [revealedSliderFinder, directSliderFinder]) {
|
||||
final sliderContext = tester.element(sliderFinder);
|
||||
final sliderTheme = SliderTheme.of(sliderContext);
|
||||
final inactiveTrack = sliderTheme.inactiveTrackColor!;
|
||||
final inactiveTick = sliderTheme.inactiveTickMarkColor!;
|
||||
final activeTick = sliderTheme.activeTickMarkColor!;
|
||||
final valueIndicator = sliderTheme.valueIndicatorColor!;
|
||||
|
||||
expect(inactiveTrack.a, 1.0);
|
||||
expect(inactiveTrack, isNot(revealBg));
|
||||
expect(inactiveTrack, isNot(cardBg));
|
||||
|
||||
expect(
|
||||
meshContrastRatio(inactiveTrack, revealBg),
|
||||
greaterThanOrEqualTo(2.1),
|
||||
reason: 'Inactive track must stand out on SettingsReveal',
|
||||
);
|
||||
expect(
|
||||
meshContrastRatio(inactiveTrack, cardBg),
|
||||
greaterThanOrEqualTo(2.5),
|
||||
reason: 'Inactive track must stand out on MeshCard',
|
||||
);
|
||||
expect(
|
||||
meshContrastRatio(inactiveTick, inactiveTrack),
|
||||
greaterThanOrEqualTo(2.5),
|
||||
reason: 'Inactive tick marks must stand out on inactive track',
|
||||
);
|
||||
expect(
|
||||
meshContrastRatio(activeTick, sliderTheme.activeTrackColor!),
|
||||
greaterThanOrEqualTo(1.8),
|
||||
reason: 'Active tick marks must stand out on active track',
|
||||
);
|
||||
expect(
|
||||
meshContrastRatio(valueIndicator, revealBg),
|
||||
greaterThanOrEqualTo(3.0),
|
||||
reason: 'Drag bubble must stand out on SettingsReveal',
|
||||
);
|
||||
expect(
|
||||
meshContrastRatio(valueIndicator, cardBg),
|
||||
greaterThanOrEqualTo(3.0),
|
||||
reason: 'Drag bubble must stand out on MeshCard',
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
import 'package:meshcore_open/models/message.dart';
|
||||
import 'package:meshcore_open/models/path_selection.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/message_retry_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
|
||||
Contact _contact({int pathLength = 1, List<int> path = const [0x11]}) =>
|
||||
Contact(
|
||||
publicKey: Uint8List.fromList(List<int>.generate(32, (i) => i + 1)),
|
||||
name: 'Test',
|
||||
type: 1,
|
||||
pathLength: pathLength,
|
||||
path: Uint8List.fromList(path),
|
||||
lastSeen: DateTime.now(),
|
||||
);
|
||||
|
||||
void main() {
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
test('rotation sends direct attempts, then flood, then stops', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: true,
|
||||
directRetries: 1,
|
||||
floodRetries: 1,
|
||||
),
|
||||
);
|
||||
|
||||
final service = MessageRetryService(
|
||||
sentWatchdogGrace: const Duration(milliseconds: 5),
|
||||
);
|
||||
addTearDown(service.dispose);
|
||||
final sends = <int>[];
|
||||
final thresholds = <int>[];
|
||||
service.initialize(
|
||||
RetryServiceConfig(
|
||||
sendMessage: (_, _, attempt, _) async {
|
||||
sends.add(attempt);
|
||||
},
|
||||
addMessage: (_, _) {},
|
||||
updateMessage: (_) {},
|
||||
calculateTimeout: (_, _, {String? contactKey, int? deviceTimeoutMs}) =>
|
||||
15,
|
||||
appSettingsService: settings,
|
||||
selectRetryPath: (_, attemptIndex, directRetries, _) {
|
||||
thresholds.add(directRetries);
|
||||
if (attemptIndex >= directRetries) {
|
||||
return const PathSelection(
|
||||
pathBytes: [],
|
||||
hopCount: -1,
|
||||
useFlood: true,
|
||||
);
|
||||
}
|
||||
return const PathSelection(
|
||||
pathBytes: [0x22],
|
||||
hopCount: 1,
|
||||
useFlood: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
|
||||
await pumpEventQueue();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 1400));
|
||||
|
||||
expect(sends, [0, 1]);
|
||||
expect(thresholds, [1, 1]);
|
||||
});
|
||||
|
||||
test('rotation off keeps retrying a direct path without flooding', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: false,
|
||||
directRetries: 2,
|
||||
floodRetries: 5,
|
||||
),
|
||||
);
|
||||
|
||||
final service = MessageRetryService(
|
||||
sentWatchdogGrace: const Duration(milliseconds: 5),
|
||||
);
|
||||
addTearDown(service.dispose);
|
||||
final sends = <int>[];
|
||||
var picked = false;
|
||||
service.initialize(
|
||||
RetryServiceConfig(
|
||||
sendMessage: (_, _, attempt, _) async {
|
||||
sends.add(attempt);
|
||||
},
|
||||
addMessage: (_, _) {},
|
||||
updateMessage: (_) {},
|
||||
calculateTimeout: (_, _, {String? contactKey, int? deviceTimeoutMs}) =>
|
||||
15,
|
||||
appSettingsService: settings,
|
||||
selectRetryPath: (_, _, _, _) {
|
||||
picked = true;
|
||||
return const PathSelection(
|
||||
pathBytes: [],
|
||||
hopCount: -1,
|
||||
useFlood: true,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
|
||||
await pumpEventQueue();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 1400));
|
||||
|
||||
expect(sends, [0, 1]);
|
||||
expect(picked, isFalse);
|
||||
});
|
||||
|
||||
test('a flood path without rotation stops after the flood budget', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: false,
|
||||
directRetries: 4,
|
||||
floodRetries: 1,
|
||||
),
|
||||
);
|
||||
|
||||
final service = MessageRetryService(
|
||||
sentWatchdogGrace: const Duration(milliseconds: 5),
|
||||
);
|
||||
addTearDown(service.dispose);
|
||||
final latest = <Message>[];
|
||||
final sends = <int>[];
|
||||
service.initialize(
|
||||
RetryServiceConfig(
|
||||
sendMessage: (_, _, attempt, _) async {
|
||||
sends.add(attempt);
|
||||
},
|
||||
addMessage: (_, message) => latest.add(message),
|
||||
updateMessage: (message) => latest.add(message),
|
||||
calculateTimeout: (_, _, {String? contactKey, int? deviceTimeoutMs}) =>
|
||||
15,
|
||||
appSettingsService: settings,
|
||||
),
|
||||
);
|
||||
|
||||
await service.sendMessageWithRetry(
|
||||
contact: _contact(pathLength: -1, path: const []),
|
||||
text: 'hello',
|
||||
);
|
||||
await pumpEventQueue();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||
|
||||
expect(sends, [0]);
|
||||
expect(latest.last.status, MessageStatus.failed);
|
||||
});
|
||||
|
||||
test(
|
||||
'flood-only rotation floods saved direct contact even if selector returns null',
|
||||
() async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: true,
|
||||
directRetries: 0,
|
||||
floodRetries: 1,
|
||||
),
|
||||
);
|
||||
|
||||
final service = MessageRetryService(
|
||||
sentWatchdogGrace: const Duration(milliseconds: 5),
|
||||
);
|
||||
addTearDown(service.dispose);
|
||||
final latest = <Message>[];
|
||||
final sends = <int>[];
|
||||
var clearedCount = 0;
|
||||
var setPathCount = 0;
|
||||
service.initialize(
|
||||
RetryServiceConfig(
|
||||
sendMessage: (_, _, attempt, _) async {
|
||||
sends.add(attempt);
|
||||
},
|
||||
addMessage: (_, message) => latest.add(message),
|
||||
updateMessage: (message) => latest.add(message),
|
||||
clearContactPath: (_) async {
|
||||
clearedCount++;
|
||||
},
|
||||
setContactPath: (_, _, _) async {
|
||||
setPathCount++;
|
||||
},
|
||||
calculateTimeout:
|
||||
(_, _, {String? contactKey, int? deviceTimeoutMs}) => 15,
|
||||
appSettingsService: settings,
|
||||
selectRetryPath: (_, _, _, _) => null,
|
||||
),
|
||||
);
|
||||
|
||||
await service.sendMessageWithRetry(
|
||||
contact: _contact(pathLength: 1, path: const [0x11]),
|
||||
text: 'hello',
|
||||
);
|
||||
await pumpEventQueue();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||
|
||||
expect(sends, [0]);
|
||||
expect(clearedCount, 1);
|
||||
expect(setPathCount, 0);
|
||||
expect(latest.last.pathLength, -1);
|
||||
expect(latest.last.pathBytes, isEmpty);
|
||||
expect(latest.last.status, MessageStatus.failed);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'rotation with direct attempts > 0 tries direct paths before flooding',
|
||||
() async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.updateSettings(
|
||||
settings.settings.copyWith(
|
||||
autoRouteRotationEnabled: true,
|
||||
directRetries: 2,
|
||||
floodRetries: 1,
|
||||
),
|
||||
);
|
||||
|
||||
final service = MessageRetryService(
|
||||
sentWatchdogGrace: const Duration(milliseconds: 5),
|
||||
);
|
||||
addTearDown(service.dispose);
|
||||
final actions = <String>[];
|
||||
final sends = <int>[];
|
||||
service.initialize(
|
||||
RetryServiceConfig(
|
||||
sendMessage: (_, _, attempt, _) async {
|
||||
sends.add(attempt);
|
||||
},
|
||||
addMessage: (_, _) {},
|
||||
updateMessage: (_) {},
|
||||
clearContactPath: (_) async => actions.add('flood'),
|
||||
setContactPath: (_, bytes, _) async =>
|
||||
actions.add('direct:${bytes.join(',')}'),
|
||||
calculateTimeout:
|
||||
(_, _, {String? contactKey, int? deviceTimeoutMs}) => 15,
|
||||
appSettingsService: settings,
|
||||
selectRetryPath: (_, attemptIndex, directRetries, _) {
|
||||
if (attemptIndex >= directRetries) return null;
|
||||
return attemptIndex == 0
|
||||
? const PathSelection(
|
||||
pathBytes: [0x22],
|
||||
hopCount: 1,
|
||||
useFlood: false,
|
||||
)
|
||||
: const PathSelection(
|
||||
pathBytes: [0x33],
|
||||
hopCount: 1,
|
||||
useFlood: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
await service.sendMessageWithRetry(
|
||||
contact: _contact(pathLength: 1, path: const [0x11]),
|
||||
text: 'hello',
|
||||
);
|
||||
await pumpEventQueue();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 3500));
|
||||
|
||||
expect(sends, [0, 1, 2]);
|
||||
expect(actions, ['direct:34', 'direct:51', 'flood']);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -56,7 +56,12 @@ void main() {
|
||||
);
|
||||
|
||||
test('missing RESP_CODE_SENT times out and retries', () async {
|
||||
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
|
||||
// A direct path uses the direct budget (default 4). A flood path would
|
||||
// stop after the default single flood attempt.
|
||||
await service.sendMessageWithRetry(
|
||||
contact: _contact(pathLength: 1, path: const [0x11]),
|
||||
text: 'hello',
|
||||
);
|
||||
await pumpEventQueue();
|
||||
expect(sends.map((s) => s.attempt), [0]);
|
||||
|
||||
@@ -80,7 +85,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('late ACK for an attempt whose SENT was lost still delivers', () async {
|
||||
await service.sendMessageWithRetry(contact: _contact(), text: 'hello');
|
||||
await service.sendMessageWithRetry(
|
||||
contact: _contact(pathLength: 1, path: const [0x11]),
|
||||
text: 'hello',
|
||||
);
|
||||
await pumpEventQueue();
|
||||
|
||||
// Let the watchdog fire; the retry is now waiting on its backoff.
|
||||
|
||||
@@ -121,7 +121,7 @@ void main() {
|
||||
final pick = svc.selectPathForAttempt(
|
||||
pubKey,
|
||||
attemptIndex: attemptIndex,
|
||||
maxRetries: 5,
|
||||
directRetries: 4,
|
||||
recentSelections: recent,
|
||||
);
|
||||
final key = pick.useFlood
|
||||
@@ -139,7 +139,7 @@ void main() {
|
||||
final selection = svc.selectPathForAttempt(
|
||||
pubKey,
|
||||
attemptIndex: 0,
|
||||
maxRetries: 5,
|
||||
directRetries: 4,
|
||||
);
|
||||
expect(selection.useFlood, isTrue);
|
||||
});
|
||||
@@ -150,7 +150,7 @@ void main() {
|
||||
final selection = svc.selectPathForAttempt(
|
||||
pubKey,
|
||||
attemptIndex: 0,
|
||||
maxRetries: 0,
|
||||
directRetries: 0,
|
||||
);
|
||||
expect(selection.useFlood, isTrue);
|
||||
});
|
||||
@@ -163,7 +163,7 @@ void main() {
|
||||
final selection = svc.selectPathForAttempt(
|
||||
pubKey,
|
||||
attemptIndex: i,
|
||||
maxRetries: 5,
|
||||
directRetries: 4,
|
||||
);
|
||||
expect(
|
||||
selection.useFlood,
|
||||
@@ -274,7 +274,7 @@ void main() {
|
||||
final pick = svc.selectPathForAttempt(
|
||||
pubKey,
|
||||
attemptIndex: 0,
|
||||
maxRetries: 5,
|
||||
directRetries: 4,
|
||||
);
|
||||
expect(pick.useFlood, isFalse);
|
||||
expect(pick.hopCount, 0);
|
||||
@@ -299,21 +299,28 @@ void main() {
|
||||
expect(resolved.pathBytes, isEmpty);
|
||||
});
|
||||
|
||||
test('final attempt is always flood regardless of known paths', () async {
|
||||
test('attempts at and after directRetries flood', () async {
|
||||
final pubKey = _hex('ef01');
|
||||
await _seed(svc, pubKey, pathBytes: [0x01], hopCount: 1);
|
||||
|
||||
for (final retries in [1, 2, 5, 10]) {
|
||||
final lastAttempt = svc.selectPathForAttempt(
|
||||
for (final direct in [0, 1, 4, 9]) {
|
||||
final flooded = svc.selectPathForAttempt(
|
||||
pubKey,
|
||||
attemptIndex: retries - 1,
|
||||
maxRetries: retries,
|
||||
attemptIndex: direct,
|
||||
directRetries: direct,
|
||||
);
|
||||
expect(
|
||||
lastAttempt.useFlood,
|
||||
flooded.useFlood,
|
||||
isTrue,
|
||||
reason: 'maxRetries=$retries: last attempt must be flood',
|
||||
reason: 'directRetries=$direct: that attempt floods',
|
||||
);
|
||||
if (direct == 0) continue;
|
||||
final routed = svc.selectPathForAttempt(
|
||||
pubKey,
|
||||
attemptIndex: direct - 1,
|
||||
directRetries: direct,
|
||||
);
|
||||
expect(routed.useFlood, isFalse);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:meshcore_open/services/storage_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
|
||||
void main() {
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
test('a saved on or off overrides the global clock-sync default', () async {
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'repeater_auto_clock_sync_after_login': jsonEncode({
|
||||
'on-node': true,
|
||||
'off-node': false,
|
||||
}),
|
||||
});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
final storage = StorageService();
|
||||
|
||||
expect(
|
||||
await storage.repeaterClockSyncAfterLogin(
|
||||
'on-node',
|
||||
globalDefault: false,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
await storage.repeaterClockSyncAfterLogin(
|
||||
'off-node',
|
||||
globalDefault: true,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
await storage.repeaterClockSyncAfterLogin(
|
||||
'new-node',
|
||||
globalDefault: true,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
await storage.repeaterClockSyncAfterLogin(
|
||||
'new-node',
|
||||
globalDefault: false,
|
||||
),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('choosing default removes the per-repeater override', () async {
|
||||
final storage = StorageService();
|
||||
await storage.setRepeaterClockSyncOverride(
|
||||
'node',
|
||||
RepeaterClockSyncOverride.on,
|
||||
);
|
||||
expect(
|
||||
await storage.getRepeaterClockSyncOverride('node'),
|
||||
RepeaterClockSyncOverride.on,
|
||||
);
|
||||
|
||||
await storage.setRepeaterClockSyncOverride(
|
||||
'node',
|
||||
RepeaterClockSyncOverride.followDefault,
|
||||
);
|
||||
expect(
|
||||
await storage.getRepeaterClockSyncOverride('node'),
|
||||
RepeaterClockSyncOverride.followDefault,
|
||||
);
|
||||
expect(
|
||||
PrefsManager.instance.containsKey('repeater_auto_clock_sync_after_login'),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -205,7 +205,7 @@ void main() {
|
||||
final pick = svc.selectPathForAttempt(
|
||||
contact,
|
||||
attemptIndex: attempt,
|
||||
maxRetries: maxRetries,
|
||||
directRetries: maxRetries - 1,
|
||||
recentSelections: used,
|
||||
context: context,
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user