mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
fix: Align contact sorting labels #0
This commit is contained in:
35
test/models/channel_test.dart
Normal file
35
test/models/channel_test.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_sar_app/models/channel.dart';
|
||||
|
||||
void main() {
|
||||
test('hash channels expose deterministic psk_base64', () {
|
||||
final channel = Channel.create(index: 3, name: '#ops');
|
||||
|
||||
expect(channel.isHashChannel, isTrue);
|
||||
expect(channel.pskBase64, 'O2RN43fDLHh5NgWiWqkVvw==');
|
||||
expect(
|
||||
Channel.pskBase64ForHashChannelName('#ops'),
|
||||
'O2RN43fDLHh5NgWiWqkVvw==',
|
||||
);
|
||||
});
|
||||
|
||||
test('normal channels reject derived hashtag psk export helper', () {
|
||||
expect(
|
||||
() => Channel.pskBase64ForHashChannelName('ops'),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
|
||||
test('normal channels still expose their stored psk_base64', () {
|
||||
final channel = Channel.create(
|
||||
index: 4,
|
||||
name: 'ops',
|
||||
explicitSecret: Uint8List.fromList(List<int>.generate(16, (i) => i)),
|
||||
);
|
||||
|
||||
expect(channel.isHashChannel, isFalse);
|
||||
expect(channel.pskBase64, 'AAECAwQFBgcICQoLDA0ODw==');
|
||||
});
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_sar_app/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_sar_app/models/channel.dart';
|
||||
import 'package:meshcore_sar_app/models/contact.dart';
|
||||
import 'package:meshcore_sar_app/models/contact_group.dart';
|
||||
import 'package:meshcore_sar_app/providers/connection_provider.dart';
|
||||
@@ -15,8 +17,28 @@ import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
String? clipboardText;
|
||||
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
clipboardText = null;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
||||
switch (call.method) {
|
||||
case 'Clipboard.setData':
|
||||
clipboardText =
|
||||
(call.arguments as Map<dynamic, dynamic>)['text'] as String?;
|
||||
return null;
|
||||
case 'Clipboard.getData':
|
||||
return <String, dynamic>{'text': clipboardText};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(SystemChannels.platform, null);
|
||||
});
|
||||
|
||||
Contact buildChannel({required String name, required int channelIndex}) {
|
||||
@@ -123,6 +145,7 @@ void main() {
|
||||
await tester.tap(find.text('Ops'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Export psk_base64'), findsNothing);
|
||||
expect(find.text('Delete Channel'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Delete Channel'));
|
||||
@@ -137,6 +160,26 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('hash channel activity card exports psk_base64', (tester) async {
|
||||
await pumpContactsTab(
|
||||
tester,
|
||||
contacts: [buildChannel(name: '#ops', channelIndex: 3)],
|
||||
);
|
||||
|
||||
expect(find.text('#ops'), findsOneWidget);
|
||||
await tester.tap(find.text('#ops'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Export psk_base64'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Export psk_base64'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
|
||||
expect(clipboardText, Channel.pskBase64ForHashChannelName('#ops'));
|
||||
expect(find.text('psk_base64 copied to clipboard'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('repeaters show Others group when multiple groups exist', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -218,7 +261,7 @@ void main() {
|
||||
contacts: [buildSensor(seed: 60, name: 'WX Station')],
|
||||
);
|
||||
|
||||
expect(find.text('Sensors'), findsOneWidget);
|
||||
expect(find.text('Sensors'), findsWidgets);
|
||||
expect(find.text('WX Station'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ void main() {
|
||||
required String name,
|
||||
required ContactType type,
|
||||
int secondByte = 0,
|
||||
int flags = 0,
|
||||
int lastAdvert = 0,
|
||||
}) {
|
||||
final publicKey = Uint8List(32);
|
||||
publicKey[1] = secondByte;
|
||||
@@ -18,11 +20,11 @@ void main() {
|
||||
return Contact(
|
||||
publicKey: publicKey,
|
||||
type: type,
|
||||
flags: 0,
|
||||
flags: flags,
|
||||
outPathLen: 0,
|
||||
outPath: Uint8List(0),
|
||||
advName: name,
|
||||
lastAdvert: 0,
|
||||
lastAdvert: lastAdvert,
|
||||
advLat: 0,
|
||||
advLon: 0,
|
||||
lastMod: 0,
|
||||
@@ -98,4 +100,54 @@ void main() {
|
||||
expect(find.text('Show all'), findsNothing);
|
||||
expect(find.text('John Smith'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('sorts contacts with favourites first, then last seen', (
|
||||
tester,
|
||||
) async {
|
||||
final recentNonFavourite = buildContact(
|
||||
name: 'Alpha',
|
||||
type: ContactType.chat,
|
||||
secondByte: 1,
|
||||
lastAdvert: 300,
|
||||
);
|
||||
final olderFavourite = buildContact(
|
||||
name: 'Bravo',
|
||||
type: ContactType.chat,
|
||||
secondByte: 2,
|
||||
flags: 0x01,
|
||||
lastAdvert: 100,
|
||||
);
|
||||
final newerFavourite = buildContact(
|
||||
name: 'Charlie',
|
||||
type: ContactType.chat,
|
||||
secondByte: 3,
|
||||
flags: 0x01,
|
||||
lastAdvert: 200,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: RecipientSelectorSheet(
|
||||
contacts: [recentNonFavourite, olderFavourite, newerFavourite],
|
||||
rooms: const [],
|
||||
channels: const [],
|
||||
unreadCount: 0,
|
||||
unreadCountsByPublicKey: const {},
|
||||
showAllOption: false,
|
||||
onSelect: (selectedRecipient, draftMessage) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final charlieY = tester.getTopLeft(find.text('Charlie')).dy;
|
||||
final bravoY = tester.getTopLeft(find.text('Bravo')).dy;
|
||||
final alphaY = tester.getTopLeft(find.text('Alpha')).dy;
|
||||
|
||||
expect(charlieY, lessThan(bravoY));
|
||||
expect(bravoY, lessThan(alphaY));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user