update to zjs81/dev commit d5f54df

This commit is contained in:
ericz committed 2026-09-21 15:59:53 +02:00
commit 213f3e3971
36 files changed
+1447 -919

No files matched your search

@@ -1,23 +1,38 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
import 'package:meshcore_open/helpers/message_url_image_helper.dart';
void main() {
group('MessageUrlImageHelper', () {
tearDown(() => MessageUrlImageHelper.httpClient = null);
void mockPyxPage(String id) {
MessageUrlImageHelper.httpClient = MockClient((request) async {
expect(request.url.toString(), 'https://pyx.li/?i=$id');
return http.Response(
'<html><body><img src="/i/$id.jpg"></body></html>',
200,
headers: {'content-type': 'text/html; charset=utf-8'},
);
});
}
test('parses short pyx ids', () async {
mockPyxPage('RzmdkTsE');
final attachment = await MessageUrlImageHelper.parse(
'my picture: https://pyx.li/?i=RzmdkTsE text',
);
expect(attachment, isNotNull);
expect(attachment, 'https://pyx.li/i/RzmdkTsE.jpg');
});
test('parses direct pyx image urls', () async {
mockPyxPage('Cd1KFiwu');
final attachment = await MessageUrlImageHelper.parse(
'https://pyx.li/?i=Cd1KFiwu',
);
expect(attachment, isNotNull);
expect(attachment, 'https://pyx.li/i/Cd1KFiwu.jpg');
});
+157
View File
@@ -1,3 +1,4 @@
import 'package:characters/characters.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/helpers/reaction_helper.dart';
import 'package:meshcore_open/widgets/emoji_picker.dart';
@@ -340,6 +341,162 @@ void main() {
});
});
group('MeshCoreOne Reactions', () {
test('emoji validation sanity checks', () {
// This is more a test of expectations than of app code, but it was
// a good place to get this sorted out cleanly, and I leave it for
// anyone interested in understanding the emoji validation and tests.
expect('🥳'.length, equals(2));
expect('\u{1f44c}\u{1f3ff}'.length, equals(4));
final oneChar = RegExp(r'^(.)$');
final twoChar = RegExp(r'^(..)$');
expect(oneChar.firstMatch('🥳'), isNull);
expect(oneChar.firstMatch('\u{1F642}'), isNull);
expect(oneChar.firstMatch('\u{1f44c}\u{1f3ff}'), isNull);
expect(twoChar.firstMatch('\u{1f44c}\u{1f3ff}'), isNull);
final regex = RegExp(r'^(.{1,4})$');
expect(regex.firstMatch('🥳'), isNotNull);
expect(regex.firstMatch('😀'), isNotNull);
expect(regex.firstMatch('\u{1F642}'), isNotNull);
expect(regex.firstMatch('\u{1f44c}\u{1f3ff}'), isNotNull);
expect(Characters('🥳').length, equals(1));
expect(Characters('\u{1F642}').length, equals(1));
expect(Characters('\u{1F642}').length, equals(1));
expect(Characters('\u{1f44c}\u{1f3ff}').length, equals(1));
expect(Characters('🧑‍🧑‍🧒‍🧒').length, equals(1));
});
test('parse MeshCoreOne reaction', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReactionMC1(
'@[$senderName]$emoji\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
List<String> messages = [
'🥳\n01234567',
'@[entropy]🥳\n01234567',
'\u{1f44c}\u{1f3ff}\n01234567',
'@[entropy]\u{1f44c}\u{1f3ff}\n01234567',
'@[entropy]🧑‍🧑‍🧒\n01234567', // long composite emoji - 21 bytes
'🧑‍🧑‍🧒‍🧒\n01234567', // long composite emoji - 25 bytes
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1(txt);
expect(info, isNotNull, reason: "$txt did not parse");
}
});
test('parse MeshCoreOne reaction - avoid false positives', () {
List<String> messages = [
'test\nabcdefgh',
'🥳\nhashistoolong',
'🥳\nshort',
'🥳🥳\n01234567', // two emojis not composed into one grapheme
'X\n01234567',
'🥳\nabcuuxyz', // u is not valid as we don't support checksums
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1(txt);
expect(info, isNull, reason: "$txt should not have parsed");
}
});
test('parse MeshCoreOne reaction - Legacy format', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReactionMC1Legacy(
'$emoji@[$senderName]\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
List<String> messages = [
'🥳\n01234567',
'🥳@[entropy]\n01234567',
'\u{1f44c}\u{1f3ff}\n01234567',
'\u{1f44c}\u{1f3ff}@[entropy]\n01234567',
'🧑‍🧑‍🧒@[entropy]\n01234567', // long composite emoji - 21 bytes
'🧑‍🧑‍🧒‍🧒\n01234567', // long composite emoji - 25 bytes
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1Legacy(txt);
expect(info, isNotNull, reason: "$txt did not parse");
}
});
test(
'parse MeshCoreOne reaction - Legacy format - avoid false positives',
() {
List<String> messages = [
'test\nabcdefgh',
'🥳\nhashistoolong',
'🥳\nshort',
'🥳🥳\n01234567', // two emojis not composed into one grapheme
'X\n01234567',
'🥳\nabcuuxyz', // u is not valid as we don't support checksums
];
for (String txt in messages) {
final info = ReactionHelper.parseReactionMC1Legacy(txt);
expect(info, isNull, reason: "$txt should not have parsed");
}
},
);
test('parse MeshCoreOne reaction - main entry', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReaction(
'@[$senderName]$emoji\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
});
test('parse MeshCoreOne reaction Legacy format - main entry', () {
final emoji = '🥳';
final senderName = 'entropy 📓';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReaction(
'$emoji@[$senderName]\n$hash',
);
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:$senderName'));
expect(info.emoji, equals(emoji));
});
test('parse MeshCoreOne reaction for DM chats', () {
final emoji = '🥳';
final hash = 'b3je6qf7';
final info = ReactionHelper.parseReaction('$emoji\n$hash');
expect(info, isNotNull);
expect(info!.targetHash, equals('$hash:'));
expect(info.emoji, equals(emoji));
});
test('computeq MeshCoreOne reaction hash', () {
const timestamp = 1234567890;
const senderName = 'Alice';
const messageText = 'Hello world!';
final hash = ReactionHelper.computeReactionHashMC1(
timestamp,
senderName,
messageText,
);
expect(hash, equals('tyvbkb33'));
});
});
group('full reaction flow', () {
test('should encode and decode reaction correctly', () {
// Simulate sending a reaction
@@ -0,0 +1,46 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/services/repeater_command_service.dart';
void main() {
group('normalizeRepeaterClockSyncCommand', () {
test('translates "clock sync" to explicit time command', () {
final result = normalizeRepeaterClockSyncCommand(
'clock sync',
nowSeconds: 1787900000,
);
expect(result, 'time 1787900000');
});
test('is case-insensitive and tolerates surrounding whitespace', () {
expect(
normalizeRepeaterClockSyncCommand(' Clock Sync ', nowSeconds: 1),
'time 1',
);
});
test('passes other commands through unchanged', () {
expect(
normalizeRepeaterClockSyncCommand('clock', nowSeconds: 1),
'clock',
);
expect(
normalizeRepeaterClockSyncCommand('get radio', nowSeconds: 1),
'get radio',
);
expect(
normalizeRepeaterClockSyncCommand('time 123', nowSeconds: 1),
'time 123',
);
});
test('uses current time when nowSeconds is omitted', () {
final before = DateTime.now().millisecondsSinceEpoch ~/ 1000;
final result = normalizeRepeaterClockSyncCommand('clock sync');
final after = DateTime.now().millisecondsSinceEpoch ~/ 1000;
expect(result, startsWith('time '));
final epoch = int.parse(result.substring('time '.length));
expect(epoch, inInclusiveRange(before, after));
});
});
}