mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 08:20:36 +00:00
fix: Restore telemetry refresh behavior
ref:
This commit is contained in:
@@ -907,6 +907,56 @@ void main() {
|
||||
expect(restored.savedGroupsForSection('teamMembers'), hasLength(1));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'retains cached telemetry when sync re-adds a contact without telemetry',
|
||||
() async {
|
||||
final key = createPublicKey(141);
|
||||
final contact = createContact(
|
||||
key: key,
|
||||
type: ContactType.sensor,
|
||||
name: 'Sparse Sync Sensor',
|
||||
).copyWith(
|
||||
telemetry: ContactTelemetry(
|
||||
temperature: 18.5,
|
||||
humidity: 64.0,
|
||||
timestamp: DateTime(2026, 3, 22, 8, 30),
|
||||
),
|
||||
);
|
||||
|
||||
provider.addOrUpdateContact(contact);
|
||||
await provider.prepareForDeviceContactSync();
|
||||
|
||||
provider.addOrUpdateContact(
|
||||
createContact(
|
||||
key: key,
|
||||
type: ContactType.sensor,
|
||||
name: 'Sparse Sync Sensor',
|
||||
),
|
||||
);
|
||||
|
||||
final restored = provider.findContactByKey(key);
|
||||
expect(restored, isNotNull);
|
||||
expect(restored!.telemetry, isNotNull);
|
||||
expect(restored.telemetry!.temperature, closeTo(18.5, 0.01));
|
||||
expect(restored.telemetry!.humidity, closeTo(64.0, 0.01));
|
||||
},
|
||||
);
|
||||
|
||||
test('keeps self telemetry cached across reconnect for the same device', () async {
|
||||
final selfKey = createPublicKey(200);
|
||||
|
||||
await provider.initialize(devicePublicKey: selfKey);
|
||||
provider.updateTelemetry(
|
||||
selfKey.sublist(0, 6),
|
||||
CayenneLppParser.createTemperatureData(23.5, channel: 1),
|
||||
);
|
||||
|
||||
await provider.prepareForDeviceContactSync(devicePublicKey: selfKey);
|
||||
|
||||
expect(provider.selfTelemetry, isNotNull);
|
||||
expect(provider.selfTelemetry!.temperature, closeTo(23.5, 0.1));
|
||||
});
|
||||
});
|
||||
|
||||
group('ContactsProvider self telemetry', () {
|
||||
@@ -935,6 +985,24 @@ void main() {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('stores raw telemetry hex in metadata for verification', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final provider = ContactsProvider();
|
||||
final telemetryKey = createPublicKey(150);
|
||||
final contact = createContact(
|
||||
key: telemetryKey,
|
||||
type: ContactType.chat,
|
||||
name: 'Telemetry Node',
|
||||
);
|
||||
provider.addOrUpdateContact(contact);
|
||||
|
||||
final payload = Uint8List.fromList(<int>[0x01, 0x67, 0x00, 0xEB]);
|
||||
provider.updateTelemetry(telemetryKey.sublist(0, 6), payload);
|
||||
|
||||
final updated = provider.findContactByKey(telemetryKey)!;
|
||||
expect(updated.telemetry?.extraSensorData?['__raw_lpp_hex'], '01 67 00 eb');
|
||||
});
|
||||
}
|
||||
|
||||
String publicKeyHex(Uint8List publicKey) {
|
||||
|
||||
@@ -356,6 +356,43 @@ void main() {
|
||||
expect(connectionProvider.pingCalls, 2);
|
||||
});
|
||||
|
||||
test('refreshDueSensors refreshes self every minute', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final selfKey = Uint8List(32)..[0] = 0x66;
|
||||
final contactsProvider = ContactsProvider();
|
||||
await contactsProvider.initialize(devicePublicKey: selfKey);
|
||||
final connectionProvider = _FakeConnectionProvider(
|
||||
isConnected: true,
|
||||
publicKey: selfKey,
|
||||
selfName: 'My Device',
|
||||
);
|
||||
final start = DateTime(2026, 3, 22, 9, 0);
|
||||
|
||||
final provider = SensorsProvider();
|
||||
await waitUntilLoaded(provider);
|
||||
|
||||
await provider.refreshDueSensors(
|
||||
now: start,
|
||||
contactsProvider: contactsProvider,
|
||||
connectionProvider: connectionProvider,
|
||||
);
|
||||
expect(connectionProvider.pingCalls, 1);
|
||||
|
||||
await provider.refreshDueSensors(
|
||||
now: start.add(const Duration(seconds: 30)),
|
||||
contactsProvider: contactsProvider,
|
||||
connectionProvider: connectionProvider,
|
||||
);
|
||||
expect(connectionProvider.pingCalls, 1);
|
||||
|
||||
await provider.refreshDueSensors(
|
||||
now: start.add(const Duration(minutes: 1)),
|
||||
contactsProvider: contactsProvider,
|
||||
connectionProvider: connectionProvider,
|
||||
);
|
||||
expect(connectionProvider.pingCalls, 2);
|
||||
});
|
||||
|
||||
test(
|
||||
'addSensor includes available extra telemetry fields by default',
|
||||
() async {
|
||||
@@ -411,4 +448,32 @@ void main() {
|
||||
expect(selfContact!.telemetry, isNotNull);
|
||||
expect(selfContact.telemetry!.temperature, closeTo(19.5, 0.1));
|
||||
});
|
||||
|
||||
test(
|
||||
'displaySelfKey still returns self when watched sensors exist',
|
||||
() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final selfKey = Uint8List(32)..[0] = 0x66;
|
||||
final sensor = buildSensorContact(firstByte: 0x44, name: 'Weather');
|
||||
final contactsProvider = ContactsProvider();
|
||||
await contactsProvider.initialize(devicePublicKey: selfKey);
|
||||
|
||||
final connectionProvider = _FakeConnectionProvider(
|
||||
isConnected: true,
|
||||
publicKey: selfKey,
|
||||
selfName: 'My Device',
|
||||
);
|
||||
final provider = SensorsProvider();
|
||||
await waitUntilLoaded(provider);
|
||||
await provider.addSensor(sensor);
|
||||
|
||||
expect(
|
||||
provider.displaySelfKey(
|
||||
contactsProvider: contactsProvider,
|
||||
connectionProvider: connectionProvider,
|
||||
),
|
||||
selfKey.map((b) => b.toRadixString(16).padLeft(2, '0')).join(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
190
test/screens/discovery_screen_test.dart
Normal file
190
test/screens/discovery_screen_test.dart
Normal file
@@ -0,0 +1,190 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_sar_app/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_sar_app/models/device_info.dart' as device_info;
|
||||
import 'package:meshcore_sar_app/providers/connection_provider.dart';
|
||||
import 'package:meshcore_sar_app/providers/contacts_provider.dart';
|
||||
import 'package:meshcore_sar_app/screens/discovery_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class _FakeConnectionProvider extends ConnectionProvider {
|
||||
_FakeConnectionProvider({required bool isConnected})
|
||||
: _isConnected = isConnected;
|
||||
|
||||
final bool _isConnected;
|
||||
final List<int> discoveredAdvertTypes = <int>[];
|
||||
|
||||
@override
|
||||
device_info.DeviceInfo get deviceInfo => device_info.DeviceInfo(
|
||||
connectionState: _isConnected
|
||||
? device_info.ConnectionState.connected
|
||||
: device_info.ConnectionState.disconnected,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> discoverNodeType({
|
||||
required int advertType,
|
||||
bool prefixOnly = false,
|
||||
int since = 0,
|
||||
}) async {
|
||||
discoveredAdvertTypes.add(advertType);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pumpDiscoveryScreen(
|
||||
WidgetTester tester, {
|
||||
ContactsProvider? contactsProvider,
|
||||
ConnectionProvider? connectionProvider,
|
||||
}) async {
|
||||
final resolvedContactsProvider = contactsProvider ?? ContactsProvider();
|
||||
final resolvedConnectionProvider =
|
||||
connectionProvider ?? _FakeConnectionProvider(isConnected: true);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<ContactsProvider>.value(
|
||||
value: resolvedContactsProvider,
|
||||
),
|
||||
ChangeNotifierProvider<ConnectionProvider>.value(
|
||||
value: resolvedConnectionProvider,
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const DiscoveryScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Uint8List _publicKey(int seed) {
|
||||
final bytes = Uint8List(32);
|
||||
bytes[0] = seed;
|
||||
bytes[1] = seed + 1;
|
||||
bytes[2] = seed + 2;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'discovery actions are shown in the summary card instead of overflow menu',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(375, 812);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final connectionProvider = _FakeConnectionProvider(isConnected: true);
|
||||
|
||||
await _pumpDiscoveryScreen(
|
||||
tester,
|
||||
connectionProvider: connectionProvider,
|
||||
);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Discover repeaters'), findsOneWidget);
|
||||
expect(find.text('Discover sensors'), findsOneWidget);
|
||||
expect(find.text('Resolve all'), findsOneWidget);
|
||||
expect(find.text('Clear all'), findsOneWidget);
|
||||
expect(find.text('Search discovered nodes'), findsNothing);
|
||||
expect(find.byIcon(Icons.more_vert), findsNothing);
|
||||
expect(
|
||||
find.text(
|
||||
'Use the discovery actions above to find repeaters and sensors on the mesh.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Discover repeaters'));
|
||||
await tester.pump();
|
||||
|
||||
expect(connectionProvider.discoveredAdvertTypes, [2]);
|
||||
expect(find.text('Repeater discovery sent'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('search and inline type filters narrow discovered nodes', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 1400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final contactsProvider = ContactsProvider()
|
||||
..addOrUpdatePendingAdvertMetadata(
|
||||
publicKey: _publicKey(0x10),
|
||||
typeValue: 2,
|
||||
advName: 'Relay Alpha',
|
||||
)
|
||||
..addOrUpdatePendingAdvertMetadata(
|
||||
publicKey: _publicKey(0x20),
|
||||
typeValue: 4,
|
||||
advName: 'WX Station',
|
||||
)
|
||||
..addOrUpdatePendingAdvertMetadata(
|
||||
publicKey: _publicKey(0x30),
|
||||
typeValue: 3,
|
||||
advName: 'Ops Room',
|
||||
);
|
||||
|
||||
await _pumpDiscoveryScreen(
|
||||
tester,
|
||||
contactsProvider: contactsProvider,
|
||||
connectionProvider: _FakeConnectionProvider(isConnected: true),
|
||||
);
|
||||
|
||||
expect(find.text('Search discovered nodes'), findsOneWidget);
|
||||
expect(find.text('All'), findsOneWidget);
|
||||
expect(find.text('Repeaters'), findsOneWidget);
|
||||
expect(find.text('Sensors'), findsOneWidget);
|
||||
expect(find.text('Others'), findsOneWidget);
|
||||
|
||||
expect(find.text('Relay Alpha'), findsOneWidget);
|
||||
expect(find.text('WX Station'), findsOneWidget);
|
||||
expect(find.text('Ops Room'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Sensors'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Relay Alpha'), findsNothing);
|
||||
expect(find.text('WX Station'), findsOneWidget);
|
||||
expect(find.text('Ops Room'), findsNothing);
|
||||
expect(find.text('Discovered nodes (1/3)'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Others'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Relay Alpha'), findsNothing);
|
||||
expect(find.text('WX Station'), findsNothing);
|
||||
expect(find.text('Ops Room'), findsOneWidget);
|
||||
|
||||
await tester.enterText(find.byType(TextField), 'relay');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('No matches'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('All'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Relay Alpha'), findsOneWidget);
|
||||
expect(find.text('Ops Room'), findsNothing);
|
||||
|
||||
await tester.enterText(find.byType(TextField), 'ops');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Relay Alpha'), findsNothing);
|
||||
expect(find.text('WX Station'), findsNothing);
|
||||
expect(find.text('Ops Room'), findsOneWidget);
|
||||
expect(find.text('Discovered nodes (1/3)'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -38,7 +38,12 @@ void main() {
|
||||
telemetry: ContactTelemetry(
|
||||
temperature: 20.1,
|
||||
humidity: 52,
|
||||
extraSensorData: const {'speed_2': 3.1, 'gust_2': 4.8, 'rain_2': 12.3},
|
||||
extraSensorData: const {
|
||||
'generic_sensor_1': 1,
|
||||
'speed_2': 3.1,
|
||||
'gust_2': 4.8,
|
||||
'rain_2': 12.3,
|
||||
},
|
||||
timestamp: DateTime(2026, 3, 21, 12),
|
||||
),
|
||||
);
|
||||
@@ -52,4 +57,28 @@ void main() {
|
||||
]);
|
||||
expect(supportsBTHomeMetHistory(contact), isTrue);
|
||||
});
|
||||
|
||||
test('does not enable BTHome MET history without channel 1 capability', () {
|
||||
final contact = Contact(
|
||||
publicKey: Uint8List(32),
|
||||
type: ContactType.sensor,
|
||||
flags: 0,
|
||||
outPathLen: 0,
|
||||
outPath: Uint8List(64),
|
||||
advName: 'WX',
|
||||
lastAdvert: 0,
|
||||
advLat: 0,
|
||||
advLon: 0,
|
||||
lastMod: 0,
|
||||
telemetry: ContactTelemetry(
|
||||
temperature: 20.1,
|
||||
humidity: 52,
|
||||
extraSensorData: const {'speed_2': 3.1, 'gust_2': 4.8, 'rain_2': 12.3},
|
||||
timestamp: DateTime(2026, 3, 21, 12),
|
||||
),
|
||||
);
|
||||
|
||||
expect(bTHomeMetMeasurementsForContact(contact), isEmpty);
|
||||
expect(supportsBTHomeMetHistory(contact), isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -488,6 +488,39 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test('weather station payload keeps generic percentage and does not invent battery from ch1 voltage', () {
|
||||
final payload = Uint8List.fromList([
|
||||
0x01, 0x74, 0x00, 0x00,
|
||||
0x02, 0x78, 0x64,
|
||||
0x02, 0x73, 0x24, 0x32,
|
||||
0x02, 0x65, 0x5A, 0x50,
|
||||
0x02, 0x8A, 0xFF, 0xE4,
|
||||
0x02, 0x74, 0x01, 0xE0,
|
||||
0x02, 0x9D, 0x00,
|
||||
0x02, 0x68, 0x76,
|
||||
0x02, 0x81, 0x01, 0x4A,
|
||||
0x02, 0x89, 0x01, 0xB8,
|
||||
0x02, 0x67, 0x00, 0x2D,
|
||||
0x02, 0xAD, 0x0A,
|
||||
0x02, 0x84, 0x00, 0x56,
|
||||
0x02, 0x8B, 0x00, 0xB3,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
]);
|
||||
|
||||
final decoded = CayenneLppParser.parse(payload);
|
||||
|
||||
expect(decoded.batteryPercentage, isNull);
|
||||
expect(decoded.batteryMilliVolts, isNull);
|
||||
expect(decoded.temperature, closeTo(4.5, 0.1));
|
||||
expect(decoded.humidity, closeTo(59.0, 0.1));
|
||||
expect(decoded.pressure, closeTo(926.6, 0.1));
|
||||
expect(decoded.extraSensorData!['voltage_1'], closeTo(0.0, 0.001));
|
||||
expect(decoded.extraSensorData!['percentage_2'], equals(100.0));
|
||||
expect(decoded.extraSensorData!['uv_2'], equals(1.0));
|
||||
expect(decoded.extraSensorData!['rain_2'], closeTo(17.9, 0.1));
|
||||
expect(decoded.extraSensorData!.containsKey('__source_channel:battery'), isFalse);
|
||||
});
|
||||
|
||||
test('unknown sensor type is skipped gracefully', () {
|
||||
final buffer = ByteData(5);
|
||||
buffer.setUint8(0, 0);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
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/contact.dart';
|
||||
import 'package:meshcore_sar_app/providers/sensors_provider.dart';
|
||||
import 'package:meshcore_sar_app/services/cayenne_lpp_parser.dart';
|
||||
import 'package:meshcore_sar_app/widgets/sensors/sensor_telemetry_card.dart';
|
||||
|
||||
void main() {
|
||||
@@ -190,6 +192,139 @@ void main() {
|
||||
expect(find.text('12.3 mm'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders generic percentage separately from UV for weather payload', (tester) async {
|
||||
tester.view.physicalSize = const Size(1600, 2600);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(() {
|
||||
tester.view.resetPhysicalSize();
|
||||
tester.view.resetDevicePixelRatio();
|
||||
});
|
||||
|
||||
final publicKey = Uint8List(32);
|
||||
publicKey[0] = 0x49;
|
||||
final payload = Uint8List.fromList([
|
||||
0x01, 0x74, 0x00, 0x00,
|
||||
0x02, 0x78, 0x64,
|
||||
0x02, 0x73, 0x24, 0x31,
|
||||
0x02, 0x65, 0x67, 0xDE,
|
||||
0x02, 0x8A, 0xFF, 0xE6,
|
||||
0x02, 0x74, 0x01, 0xE0,
|
||||
0x02, 0x9D, 0x00,
|
||||
0x02, 0x68, 0x76,
|
||||
0x02, 0x81, 0x00, 0xDC,
|
||||
0x02, 0x89, 0x01, 0x36,
|
||||
0x02, 0x67, 0x00, 0x2F,
|
||||
0x02, 0xAD, 0x0A,
|
||||
0x02, 0x84, 0x00, 0x50,
|
||||
0x02, 0x8B, 0x00, 0xB3,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
]);
|
||||
|
||||
final contact = Contact(
|
||||
publicKey: publicKey,
|
||||
type: ContactType.sensor,
|
||||
flags: 0,
|
||||
outPathLen: 0,
|
||||
outPath: Uint8List(64),
|
||||
advName: 'WX Station',
|
||||
lastAdvert: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
advLat: 0,
|
||||
advLon: 0,
|
||||
lastMod: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
telemetry: CayenneLppParser.parse(payload),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: SensorTelemetryCard(
|
||||
contact: contact,
|
||||
state: SensorRefreshState.idle,
|
||||
visibleFields: const {
|
||||
'temperature',
|
||||
'humidity',
|
||||
'pressure',
|
||||
'extra:percentage_2',
|
||||
'extra:dew_2',
|
||||
'extra:speed_2',
|
||||
'extra:gust_2',
|
||||
'extra:uv_2',
|
||||
'extra:direction_2',
|
||||
'extra:rain_2',
|
||||
},
|
||||
fieldSpans: sensorFullWidthFieldSpans(const {
|
||||
'temperature',
|
||||
'humidity',
|
||||
'pressure',
|
||||
'extra:percentage_2',
|
||||
'extra:dew_2',
|
||||
'extra:speed_2',
|
||||
'extra:gust_2',
|
||||
'extra:uv_2',
|
||||
'extra:direction_2',
|
||||
'extra:rain_2',
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byKey(const ValueKey('sensor_metric_extra:percentage_2')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('sensor_metric_extra:uv_2')), findsOneWidget);
|
||||
expect(find.text('100%'), findsOneWidget);
|
||||
expect(find.text('1%'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
expect(find.text('80°'), findsOneWidget);
|
||||
expect(find.text('8°'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('renders direction metric with compact compass layout', (
|
||||
tester,
|
||||
) async {
|
||||
final publicKey = Uint8List(32);
|
||||
publicKey[0] = 0x47;
|
||||
final contact = Contact(
|
||||
publicKey: publicKey,
|
||||
type: ContactType.sensor,
|
||||
flags: 0,
|
||||
outPathLen: 0,
|
||||
outPath: Uint8List(64),
|
||||
advName: 'WX Station',
|
||||
lastAdvert: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
advLat: 0,
|
||||
advLon: 0,
|
||||
lastMod: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
telemetry: ContactTelemetry(
|
||||
timestamp: DateTime.now().subtract(const Duration(minutes: 1)),
|
||||
extraSensorData: const {'direction_2': 111.0},
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SensorTelemetryCard(
|
||||
contact: contact,
|
||||
state: SensorRefreshState.idle,
|
||||
visibleFields: const {'extra:direction_2'},
|
||||
fieldSpans: sensorFullWidthFieldSpans(const {'extra:direction_2'}),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Direction'), findsOneWidget);
|
||||
expect(find.text('111°'), findsOneWidget);
|
||||
expect(find.text('E'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.navigation_rounded), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('long pressing a telemetry bubble triggers refresh', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -221,4 +356,92 @@ void main() {
|
||||
|
||||
expect(refreshCount, 1);
|
||||
});
|
||||
|
||||
testWidgets('overflow menu exposes move actions', (tester) async {
|
||||
final contact = buildContact();
|
||||
var moveUpCount = 0;
|
||||
var moveDownCount = 0;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SensorTelemetryCard(
|
||||
contact: contact,
|
||||
state: SensorRefreshState.idle,
|
||||
visibleFields: const {'temperature'},
|
||||
fieldSpans: sensorFullWidthFieldSpans(const {'temperature'}),
|
||||
onMoveUp: () async {
|
||||
moveUpCount += 1;
|
||||
},
|
||||
onMoveDown: () async {
|
||||
moveDownCount += 1;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.more_vert));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Move up'), findsOneWidget);
|
||||
expect(find.text('Move down'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Move down'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(moveUpCount, 0);
|
||||
expect(moveDownCount, 1);
|
||||
});
|
||||
|
||||
testWidgets('overflow menu copies raw response', (tester) async {
|
||||
final publicKey = Uint8List(32);
|
||||
publicKey[0] = 0x48;
|
||||
final contact = Contact(
|
||||
publicKey: publicKey,
|
||||
type: ContactType.sensor,
|
||||
flags: 0,
|
||||
outPathLen: 0,
|
||||
outPath: Uint8List(64),
|
||||
advName: 'WX Station',
|
||||
lastAdvert: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
advLat: 0,
|
||||
advLon: 0,
|
||||
lastMod: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
telemetry: ContactTelemetry(
|
||||
temperature: 21.5,
|
||||
timestamp: DateTime.now().subtract(const Duration(minutes: 1)),
|
||||
extraSensorData: const {'__raw_lpp_hex': '01 67 00 d7'},
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: SensorTelemetryCard(
|
||||
contact: contact,
|
||||
state: SensorRefreshState.idle,
|
||||
visibleFields: const {'temperature'},
|
||||
fieldSpans: sensorFullWidthFieldSpans(const {'temperature'}),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.more_vert));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Copy raw response'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Copy raw response'));
|
||||
await tester.pump();
|
||||
|
||||
final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
expect(clipboardData?.text, '01 67 00 d7');
|
||||
expect(find.text('Raw response copied'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user