fix: Keep composer and sensor sheets closable #123

This commit is contained in:
Janez T
2026-03-22 18:27:57 +01:00
parent 6f0a66dc68
commit 7ea6334f02
3 changed files with 353 additions and 380 deletions

View File

@@ -7,6 +7,7 @@ import 'package:meshcore_sar_app/models/contact.dart';
import 'package:meshcore_sar_app/providers/contacts_provider.dart';
import 'package:meshcore_sar_app/providers/sensors_provider.dart';
import 'package:meshcore_sar_app/screens/sensors_tab.dart';
import 'package:meshcore_sar_app/widgets/sensors/sensor_telemetry_card.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -22,9 +23,12 @@ void main() {
expect(provider.isLoaded, isTrue);
}
Contact buildSensorContact() {
Contact buildSensorContact({
int firstByte = 0x44,
String name = 'WX Station',
}) {
final publicKey = Uint8List(32);
publicKey[0] = 0x44;
publicKey[0] = firstByte;
return Contact(
publicKey: publicKey,
@@ -32,7 +36,7 @@ void main() {
flags: 0,
outPathLen: 0,
outPath: Uint8List(64),
advName: 'WX Station',
advName: name,
lastAdvert: DateTime.now().millisecondsSinceEpoch ~/ 1000,
advLat: 0,
advLon: 0,
@@ -70,19 +74,22 @@ void main() {
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const SensorsTab(),
home: SensorCustomizeView(
publicKeyHex: contact.publicKeyHex,
initialContact: contact,
onRenameMetric:
({
required BuildContext context,
required String publicKeyHex,
required SensorMetricOption option,
required SensorsProvider sensorsProvider,
}) async {},
),
),
),
);
await tester.pump();
await tester.tap(find.byIcon(Icons.more_vert));
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
await tester.tap(find.text('Customize fields'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
expect(find.text('Customize WX Station'), findsOneWidget);
expect(find.text('Live preview'), findsOneWidget);
expect(find.text('Refresh schedule'), findsOneWidget);
@@ -94,4 +101,49 @@ void main() {
);
expect(find.text('Channel 2'), findsOneWidget);
});
testWidgets('add sensor sheet keeps close action available when scrolled', (
tester,
) async {
tester.view.physicalSize = const Size(320, 480);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
var didClose = false;
final candidates = List<Contact>.generate(
20,
(index) =>
buildSensorContact(firstByte: index + 1, name: 'Sensor ${index + 1}'),
);
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: AddSensorSheet(
candidates: candidates,
onSelect: (_) async {},
onClose: () {
didClose = true;
},
),
),
),
);
await tester.pump();
final closeButton = find.byTooltip('Close');
expect(closeButton, findsOneWidget);
await tester.drag(find.byType(ListView).last, const Offset(0, -600));
await tester.pump();
expect(closeButton, findsOneWidget);
await tester.tap(closeButton);
await tester.pump();
expect(didClose, isTrue);
});
}