Merge remote-tracking branch 'origin/dev' into pr-593
# Conflicts: # lib/models/app_settings.dart # lib/screens/channel_chat_screen.dart # lib/screens/chat_screen.dart # untranslated.json
This commit is contained in:
commit
7e7e7a48db
87 files changed
+4822
-882
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
|
||||
void main() {
|
||||
bool mentions(String text, String? name) =>
|
||||
MeshCoreConnector.textMentionsName(text, name);
|
||||
|
||||
test('matches bracketed and plain mentions case-insensitively', () {
|
||||
expect(mentions('@[Bob] hello', 'Bob'), isTrue);
|
||||
expect(mentions('hey @[bob]', 'Bob'), isTrue);
|
||||
expect(mentions('hey @bob, look', 'Bob'), isTrue);
|
||||
expect(mentions('@BOB', 'Bob'), isTrue);
|
||||
expect(mentions('ping @Иван!', 'иван'), isTrue);
|
||||
});
|
||||
|
||||
test('requires a word boundary for plain mentions', () {
|
||||
expect(mentions('hey @bobby', 'Bob'), isFalse);
|
||||
expect(mentions('mail x@bob.com', 'Bob'), isFalse);
|
||||
expect(mentions('hey bob', 'Bob'), isFalse);
|
||||
});
|
||||
|
||||
test('names with spaces or regex characters must match in full', () {
|
||||
expect(mentions('hi @Bob Smith', 'Bob Smith'), isTrue);
|
||||
expect(mentions('hi @Bob', 'Bob Smith'), isFalse);
|
||||
expect(mentions('@[Node (1)] ok', 'Node (1)'), isTrue);
|
||||
expect(mentions('@[Node 1] ok', 'Node (1)'), isFalse);
|
||||
});
|
||||
|
||||
test('no self name never matches', () {
|
||||
expect(mentions('@[Bob] hi', null), isFalse);
|
||||
expect(mentions('@ hi', ''), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -65,7 +65,12 @@ void main() {
|
||||
waitForReply: true,
|
||||
);
|
||||
queue.takeErr(6);
|
||||
await expectLater(pending!.completer!.future, throwsException);
|
||||
await expectLater(
|
||||
pending!.completer!.future,
|
||||
throwsA(
|
||||
isA<FirmwareCommandException>().having((e) => e.errCode, 'errCode', 6),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
group('timed-out entries', () {
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/review_mode/review_radio.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/contact_store.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/// Review radio that records every frame the app sends.
|
||||
class _RecordingReviewRadio extends ReviewRadio {
|
||||
final List<Uint8List> sent = [];
|
||||
|
||||
_RecordingReviewRadio()
|
||||
: super(scheduledMessageInterval: const Duration(hours: 1));
|
||||
|
||||
@override
|
||||
void handle(Uint8List frame) {
|
||||
sent.add(frame);
|
||||
super.handle(frame);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
test('removed contact stays gone from the radio, list and store', () async {
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
final retryService = MessageRetryService();
|
||||
addTearDown(retryService.dispose);
|
||||
connector.initialize(
|
||||
retryService: retryService,
|
||||
pathHistoryService: PathHistoryService(StorageService()),
|
||||
);
|
||||
final radio = _RecordingReviewRadio();
|
||||
connector.reviewRadioFactoryForTest = () => radio;
|
||||
|
||||
await connector.connectReview();
|
||||
await _waitFor(
|
||||
() => connector.hasLoadedContacts && connector.contacts.length >= 6,
|
||||
);
|
||||
final contact = connector.contacts.firstWhere((c) => c.name == 'Maya');
|
||||
|
||||
await connector.removeContact(contact);
|
||||
|
||||
bool listed() =>
|
||||
connector.contacts.any((c) => c.publicKeyHex == contact.publicKeyHex);
|
||||
expect(listed(), isFalse);
|
||||
expect(
|
||||
connector.discoveredContacts
|
||||
.firstWhere((c) => c.publicKeyHex == contact.publicKeyHex)
|
||||
.isActive,
|
||||
isFalse,
|
||||
);
|
||||
|
||||
// A full resync from the radio must not bring it back.
|
||||
await connector.getContacts();
|
||||
await _waitFor(() => connector.hasLoadedContacts);
|
||||
expect(connector.contacts, isNotEmpty);
|
||||
expect(listed(), isFalse);
|
||||
|
||||
final store = ContactStore()..setPublicKeyHex = connector.selfPublicKeyHex;
|
||||
final saved = await store.loadContacts();
|
||||
expect(saved.any((c) => c.publicKeyHex == contact.publicKeyHex), isFalse);
|
||||
|
||||
// An open chat/repeater screen still syncs the path before each send, and
|
||||
// the favourite toggle writes flags. On firmware CMD_ADD_UPDATE_CONTACT
|
||||
// adds unknown keys, so neither may be sent for the removed contact.
|
||||
radio.sent.clear();
|
||||
await connector.setContactPath(contact, Uint8List.fromList([0x42]), 1);
|
||||
await connector.preparePathForContactSend(contact);
|
||||
await connector.setContactFlags(contact, isFavorite: true);
|
||||
expect(radio.sent.where((f) => f.first == cmdAddUpdateContact), isEmpty);
|
||||
|
||||
await connector.disconnect(manual: true);
|
||||
});
|
||||
|
||||
test('auto-add config reports which contact types come back', () {
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
connector.handleFrameForTest([respCodeAutoAddConfig, autoAddRepeaterFlag]);
|
||||
|
||||
expect(connector.autoAddsContactType(advTypeRepeater), isTrue);
|
||||
expect(connector.autoAddsContactType(advTypeChat), isFalse);
|
||||
expect(connector.autoAddsContactType(advTypeRoom), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/models/app_settings.dart';
|
||||
|
||||
void main() {
|
||||
test('channel notification modes round-trip by name', () {
|
||||
final settings = AppSettings(
|
||||
channelNotificationModes: {
|
||||
'a': ChannelNotificationMode.mentionsOnly,
|
||||
'b': ChannelNotificationMode.muted,
|
||||
},
|
||||
);
|
||||
final json = settings.toJson();
|
||||
expect(json['channel_notification_modes'], {
|
||||
'a': 'mentionsOnly',
|
||||
'b': 'muted',
|
||||
});
|
||||
expect(json['muted_channels'], ['b']);
|
||||
expect(
|
||||
AppSettings.fromJson(json).channelNotificationModes,
|
||||
settings.channelNotificationModes,
|
||||
);
|
||||
});
|
||||
|
||||
test('invalid channel notification mode entries are skipped', () {
|
||||
final settings = AppSettings.fromJson({
|
||||
'channel_notification_modes': {
|
||||
'ok': 'muted',
|
||||
'unknown': 'loud',
|
||||
'int': 2,
|
||||
'null': null,
|
||||
},
|
||||
});
|
||||
expect(settings.channelNotificationModes, {
|
||||
'ok': ChannelNotificationMode.muted,
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/models/contact.dart';
|
||||
|
||||
Contact _contact(List<int> key) => Contact(
|
||||
publicKey: Uint8List.fromList(key),
|
||||
name: 'Node',
|
||||
type: advTypeChat,
|
||||
pathLength: -1,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
);
|
||||
|
||||
void main() {
|
||||
final contact = _contact([0xA3, 0x0F, 0xB2, 0x44]);
|
||||
|
||||
test('formats the first pathHashByteWidth bytes as uppercase hex', () {
|
||||
expect(contact.publicKeyPrefixHex(1), 'A3');
|
||||
expect(contact.publicKeyPrefixHex(2), 'A30F');
|
||||
expect(contact.publicKeyPrefixHex(3), 'A30FB2');
|
||||
});
|
||||
|
||||
test('clamps width to the supported 1-3 range', () {
|
||||
expect(contact.publicKeyPrefixHex(0), 'A3');
|
||||
expect(contact.publicKeyPrefixHex(4), 'A30FB2');
|
||||
});
|
||||
|
||||
test('handles keys shorter than the width', () {
|
||||
expect(_contact([0x01]).publicKeyPrefixHex(3), '01');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:meshcore_open/models/map_path_trace_draft.dart';
|
||||
import 'package:meshcore_open/services/ui_view_state_service.dart';
|
||||
|
||||
void main() {
|
||||
test('draft survives on the shared view state service', () {
|
||||
final service = UiViewStateService();
|
||||
final draft = service.mapPathTrace
|
||||
..active = true
|
||||
..returnPath = false;
|
||||
draft.pathBytes.addAll([0xAB, 0xCD]);
|
||||
draft.points.add(const LatLng(1, 2));
|
||||
|
||||
expect(identical(service.mapPathTrace, draft), isTrue);
|
||||
expect(service.mapPathTrace.hasHops, isTrue);
|
||||
expect(service.mapPathTrace.returnPath, isFalse);
|
||||
});
|
||||
|
||||
test('clear drops hops and the last result but keeps the mode', () {
|
||||
final draft = MapPathTraceDraft()
|
||||
..returnPath = false
|
||||
..lastResultFrame = Uint8List.fromList([1, 2, 3]);
|
||||
draft.pathBytes.add(0xAB);
|
||||
draft.hopWidths.add(1);
|
||||
draft.points.add(const LatLng(1, 2));
|
||||
|
||||
draft.clear();
|
||||
|
||||
expect(draft.hasHops, isFalse);
|
||||
expect(draft.hopWidths, isEmpty);
|
||||
expect(draft.points, isEmpty);
|
||||
expect(draft.lastResultFrame, isNull);
|
||||
expect(draft.returnPath, isFalse);
|
||||
});
|
||||
|
||||
test('belongsTo matches only the radio it was built on', () {
|
||||
final draft = MapPathTraceDraft();
|
||||
expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue);
|
||||
draft.radioKey = Uint8List.fromList([1, 2]);
|
||||
expect(draft.belongsTo(Uint8List.fromList([1, 2])), isTrue);
|
||||
expect(draft.belongsTo(Uint8List.fromList([3, 4])), isFalse);
|
||||
});
|
||||
}
|
||||
@@ -24,7 +24,10 @@ void main() {
|
||||
test('channel mutes made in review mode are undone on exit', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.muteChannel('Hiking Group');
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
final connector = MeshCoreConnector();
|
||||
addTearDown(connector.dispose);
|
||||
final retryService = MessageRetryService();
|
||||
@@ -39,23 +42,41 @@ void main() {
|
||||
|
||||
await connector.connectReview();
|
||||
// Mutes are keyed by channel name, so these would leak into real radios.
|
||||
await settings.muteChannel('Public');
|
||||
await settings.unmuteChannel('Hiking Group');
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
// Other app preferences are the user's to change, even while reviewing.
|
||||
await PrefsManager.instance.setString('unrelated_key', 'changed');
|
||||
|
||||
await connector.disconnect(manual: true);
|
||||
|
||||
expect(settings.isChannelMuted('Public'), isFalse);
|
||||
expect(settings.isChannelMuted('Hiking Group'), isTrue);
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Hiking Group'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
expect(PrefsManager.instance.getString('unrelated_key'), 'changed');
|
||||
|
||||
// A fresh launch has nothing left to undo.
|
||||
final relaunched = AppSettingsService();
|
||||
await relaunched.loadSettings();
|
||||
await endReviewModeSession(relaunched);
|
||||
expect(relaunched.isChannelMuted('Public'), isFalse);
|
||||
expect(relaunched.isChannelMuted('Hiking Group'), isTrue);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Hiking Group'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
@@ -63,11 +84,20 @@ void main() {
|
||||
() async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.muteChannel('Hiking Group');
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
|
||||
await beginReviewModeSession(settings);
|
||||
await settings.muteChannel('Public');
|
||||
await settings.unmuteChannel('Hiking Group');
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
await PrefsManager.instance.setString(
|
||||
'contacts${ReviewRadio.storagePrefix}',
|
||||
'[]',
|
||||
@@ -76,11 +106,20 @@ void main() {
|
||||
|
||||
final relaunched = AppSettingsService();
|
||||
await relaunched.loadSettings();
|
||||
expect(relaunched.isChannelMuted('Public'), isTrue);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
await endReviewModeSession(relaunched);
|
||||
|
||||
expect(relaunched.isChannelMuted('Public'), isFalse);
|
||||
expect(relaunched.isChannelMuted('Hiking Group'), isTrue);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
expect(
|
||||
relaunched.getChannelNotificationMode('Hiking Group'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
expect(
|
||||
PrefsManager.instance.getKeys().where(
|
||||
(k) => k.contains(ReviewRadio.storagePrefix),
|
||||
@@ -90,6 +129,61 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test('every channel notification mode is restored on exit', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.mentionsOnly,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Noisy',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
|
||||
await beginReviewModeSession(settings);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Hiking Group',
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Noisy',
|
||||
ChannelNotificationMode.mentionsOnly,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.mentionsOnly,
|
||||
);
|
||||
await endReviewModeSession(settings);
|
||||
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Hiking Group'),
|
||||
ChannelNotificationMode.mentionsOnly,
|
||||
);
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Noisy'),
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
expect(
|
||||
settings.getChannelNotificationMode('Public'),
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
});
|
||||
|
||||
test('setting a channel back to all drops its stored mode', () async {
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.muted,
|
||||
);
|
||||
await settings.setChannelNotificationMode(
|
||||
'Public',
|
||||
ChannelNotificationMode.all,
|
||||
);
|
||||
expect(settings.settings.channelNotificationModes, isEmpty);
|
||||
});
|
||||
|
||||
test('the review scope never adopts legacy unscoped data', () async {
|
||||
await PrefsManager.instance.setString('contacts', '[]');
|
||||
await beginReviewModeSession(null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/screens/map_screen.dart';
|
||||
import 'package:meshcore_open/helpers/marker_message.dart';
|
||||
|
||||
void main() {
|
||||
test('parseMarkerText accepts in-range coordinates', () {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart';
|
||||
import 'package:meshcore_open/services/node_banner_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
const _record =
|
||||
'v=1;on=1;url=https%3A%2F%2Fshop.example.com%2Fnode%3Fref%3Da%26b%3Dc;'
|
||||
'title=Need%20a%20node%3F';
|
||||
|
||||
String _doh(String data, {int status = 0, int ttl = 300}) => jsonEncode({
|
||||
'Status': status,
|
||||
'Answer': [
|
||||
{'name': '_banner.meshcoreopen.org', 'type': 16, 'TTL': ttl, 'data': data},
|
||||
],
|
||||
});
|
||||
|
||||
void main() {
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
group('NodeBannerConfig.parse', () {
|
||||
test('reads the link and decodes text overrides', () {
|
||||
final config = NodeBannerConfig.parse(_record)!;
|
||||
expect(config.url.toString(), 'https://shop.example.com/node?ref=a&b=c');
|
||||
expect(config.title, 'Need a node?');
|
||||
expect(config.body, isNull);
|
||||
expect(config.action, isNull);
|
||||
});
|
||||
|
||||
test('accepts plain-text values', () {
|
||||
final config = NodeBannerConfig.parse(
|
||||
'v=1;on=1;url=https://shop.example.com/node?ref=a&b=c;'
|
||||
'title=Need a new node?;body=Waterproof, 50% off this week.;'
|
||||
'cta=Get one here',
|
||||
)!;
|
||||
expect(config.url.toString(), 'https://shop.example.com/node?ref=a&b=c');
|
||||
expect(config.title, 'Need a new node?');
|
||||
expect(config.body, 'Waterproof, 50% off this week.');
|
||||
expect(config.action, 'Get one here');
|
||||
});
|
||||
|
||||
test('is off for on=0, unknown versions, and non-https links', () {
|
||||
expect(
|
||||
NodeBannerConfig.parse(_record.replaceAll('on=1', 'on=0')),
|
||||
isNull,
|
||||
);
|
||||
expect(NodeBannerConfig.parse(_record.replaceAll('v=1', 'v=2')), isNull);
|
||||
expect(NodeBannerConfig.parse('v=1;on=1;url=http%3A%2F%2Fx.com'), isNull);
|
||||
expect(NodeBannerConfig.parse('v=1;on=1'), isNull);
|
||||
expect(NodeBannerConfig.parse('v=1;on=1;url=%E0%A4%A'), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
test('joins split TXT character-strings and unescapes them', () {
|
||||
final answer = NodeBannerService.txtFromDohJson(
|
||||
_doh(r'"v=1;on=1;url=https%3A%2F%2Fa.com" ";title=Say \"hi\""'),
|
||||
)!;
|
||||
expect(answer.text, 'v=1;on=1;url=https%3A%2F%2Fa.com;title=Say "hi"');
|
||||
expect(answer.ttl, 300);
|
||||
});
|
||||
|
||||
test('no record or NXDOMAIN gives no answer', () {
|
||||
expect(NodeBannerService.txtFromDohJson(jsonEncode({'Status': 3})), isNull);
|
||||
expect(NodeBannerService.txtFromDohJson(jsonEncode({'Status': 0})), isNull);
|
||||
});
|
||||
|
||||
test('load queries Cloudflare DoH and caches for the TTL', () async {
|
||||
var calls = 0;
|
||||
var now = DateTime(2026, 1, 1);
|
||||
final client = MockClient((request) async {
|
||||
calls++;
|
||||
expect(request.url.host, 'cloudflare-dns.com');
|
||||
expect(request.url.queryParameters['name'], '_banner.meshcoreopen.org');
|
||||
expect(request.url.queryParameters['type'], 'TXT');
|
||||
expect(request.headers['accept'], 'application/dns-json');
|
||||
return http.Response(_doh('"$_record"'), 200);
|
||||
});
|
||||
final service = NodeBannerService(client: client, now: () => now);
|
||||
|
||||
expect((await service.load())?.title, 'Need a node?');
|
||||
expect((await service.load())?.title, 'Need a node?');
|
||||
expect(calls, 1);
|
||||
|
||||
now = now.add(const Duration(minutes: 6));
|
||||
await service.load();
|
||||
expect(calls, 2);
|
||||
});
|
||||
|
||||
test('load returns null when the lookup fails', () async {
|
||||
final failing = NodeBannerService(
|
||||
client: MockClient((_) async => throw http.ClientException('offline')),
|
||||
);
|
||||
expect(await failing.load(), isNull);
|
||||
|
||||
final serverError = NodeBannerService(
|
||||
client: MockClient((_) async => http.Response('', 503)),
|
||||
);
|
||||
expect(await serverError.load(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/helpers/gif_helper.dart';
|
||||
import 'package:meshcore_open/helpers/reaction_helper.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/services/notification_service.dart';
|
||||
import 'package:meshcore_open/services/received_image_store.dart';
|
||||
import 'package:meshcore_open/widgets/marker_label_dialog.dart';
|
||||
|
||||
void main() {
|
||||
final l10n = lookupAppLocalizations(const Locale('en'));
|
||||
String format(String text) =>
|
||||
NotificationService.formatNotificationText(text, l10n);
|
||||
|
||||
test('shared locations show a summary instead of coordinates', () {
|
||||
expect(
|
||||
format(formatMarkerText(45.5, -122.6, 'Camp', 'poi')),
|
||||
'Shared a location: Camp',
|
||||
);
|
||||
expect(
|
||||
format(formatMarkerText(45.5, -122.6, '', 'poi')),
|
||||
'Shared a location',
|
||||
);
|
||||
});
|
||||
|
||||
test('reactions, GIFs and images are summarized', () {
|
||||
expect(
|
||||
format(ReactionHelper.encodeReaction('ab12', '00')),
|
||||
startsWith('Reacted '),
|
||||
);
|
||||
expect(format('👍\nabcd2345'), 'Reacted 👍');
|
||||
expect(format(GifHelper.encodeGif('xT9IgG50Fb7Mi0prBC')), 'Sent a GIF');
|
||||
expect(
|
||||
format('https://media.giphy.com/media/xT9IgG50Fb7Mi0prBC/giphy.gif'),
|
||||
'Sent a GIF',
|
||||
);
|
||||
expect(format(ReceivedImageRef.encode('0a1b2c3d4e5f60')), 'Sent an image');
|
||||
});
|
||||
|
||||
test('plain text is unchanged', () {
|
||||
expect(format('see you at m:ain street'), 'see you at m:ain street');
|
||||
expect(format('hello'), 'hello');
|
||||
});
|
||||
}
|
||||
@@ -61,30 +61,34 @@ int _readIntOption(Socket socket, int level, int option) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('connect enables TCP keepalive with short probe timings', () async {
|
||||
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final overrides = _CapturingConnectOverrides();
|
||||
final service = TcpTransportService();
|
||||
try {
|
||||
await IOOverrides.runZoned(
|
||||
() => service.connect(
|
||||
host: InternetAddress.loopbackIPv4.address,
|
||||
port: server.port,
|
||||
),
|
||||
socketConnect: overrides.socketConnect,
|
||||
);
|
||||
final socket = overrides.socket!;
|
||||
// Linux values: SO_KEEPALIVE 9, TCP_KEEPIDLE 4, TCP_KEEPINTVL 5,
|
||||
// TCP_KEEPCNT 6.
|
||||
expect(_readIntOption(socket, RawSocketOption.levelSocket, 9), 1);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 4), 30);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 5), 10);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 6), 3);
|
||||
} finally {
|
||||
await service.disconnect();
|
||||
await server.close();
|
||||
}
|
||||
}, skip: Platform.isLinux ? false : 'Option numbers checked are Linux ones');
|
||||
test(
|
||||
'connect enables TCP keepalive with short probe timings',
|
||||
() async {
|
||||
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final overrides = _CapturingConnectOverrides();
|
||||
final service = TcpTransportService();
|
||||
try {
|
||||
await IOOverrides.runZoned(
|
||||
() => service.connect(
|
||||
host: InternetAddress.loopbackIPv4.address,
|
||||
port: server.port,
|
||||
),
|
||||
socketConnect: overrides.socketConnect,
|
||||
);
|
||||
final socket = overrides.socket!;
|
||||
// Linux values: SO_KEEPALIVE 9, TCP_KEEPIDLE 4, TCP_KEEPINTVL 5,
|
||||
// TCP_KEEPCNT 6.
|
||||
expect(_readIntOption(socket, RawSocketOption.levelSocket, 9), 1);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 4), 30);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 5), 10);
|
||||
expect(_readIntOption(socket, RawSocketOption.levelTcp, 6), 3);
|
||||
} finally {
|
||||
await service.disconnect();
|
||||
await server.close();
|
||||
}
|
||||
},
|
||||
skip: Platform.isLinux ? false : 'Option numbers checked are Linux ones',
|
||||
);
|
||||
|
||||
test('connect/disconnect updates TCP transport state', () async {
|
||||
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/services/node_banner_service.dart';
|
||||
import 'package:meshcore_open/widgets/get_node_banner.dart';
|
||||
|
||||
final _config = NodeBannerConfig(url: Uri.parse('https://example.com/node'));
|
||||
|
||||
void main() {
|
||||
Future<void> pumpBanner(
|
||||
WidgetTester tester, {
|
||||
required Size size,
|
||||
required double textScale,
|
||||
NodeBannerConfig? config,
|
||||
bool hidden = false,
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
@@ -21,7 +26,11 @@ void main() {
|
||||
size: size,
|
||||
textScaler: TextScaler.linear(textScale),
|
||||
),
|
||||
child: const Scaffold(bottomNavigationBar: GetNodeBanner()),
|
||||
child: Scaffold(
|
||||
bottomNavigationBar: GetNodeBanner(
|
||||
loadConfig: () async => hidden ? null : config ?? _config,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -29,11 +38,11 @@ void main() {
|
||||
|
||||
testWidgets('shows the pitch and affiliate link', (tester) async {
|
||||
await pumpBanner(tester, size: const Size(390, 844), textScale: 1);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Need a new node?'), findsOneWidget);
|
||||
expect(find.text('Get one here'), findsOneWidget);
|
||||
expect(find.textContaining('Affiliate link'), findsOneWidget);
|
||||
expect(getNodeUrl, contains('sensecap_affiliate=JFWID0g'));
|
||||
// Leaves most of the screen for the device list.
|
||||
expect(
|
||||
tester.getSize(find.byType(GetNodeBanner)).height,
|
||||
@@ -43,6 +52,38 @@ void main() {
|
||||
|
||||
testWidgets('lays out on a narrow phone with large text', (tester) async {
|
||||
await pumpBanner(tester, size: const Size(320, 800), textScale: 1.5);
|
||||
await tester.pump();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('uses text overrides from the record', (tester) async {
|
||||
await pumpBanner(
|
||||
tester,
|
||||
size: const Size(390, 844),
|
||||
textScale: 1,
|
||||
config: NodeBannerConfig(
|
||||
url: Uri.parse('https://example.com'),
|
||||
title: 'Spring sale',
|
||||
action: 'Shop now',
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Spring sale'), findsOneWidget);
|
||||
expect(find.text('Shop now'), findsOneWidget);
|
||||
expect(find.textContaining('Affiliate link'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('shows nothing when there is no config', (tester) async {
|
||||
await pumpBanner(
|
||||
tester,
|
||||
size: const Size(390, 844),
|
||||
textScale: 1,
|
||||
hidden: true,
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(InkWell), findsNothing);
|
||||
expect(tester.getSize(find.byType(GetNodeBanner)).height, 0);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user