#1279 merged with test-gate red: every test it added used the new guard class, so none compiled against the base code and none showed the old behavior failing. The guard now runs inside MeshCoreApp, through StaleKeyboardInsetRepair, and is gated on defaultTargetPlatform (not dart:io, which is never Android in a test). A new test loads the real MeshCoreApp, hands it a stale inset after a pause and resume, and expects a re-apply. It fails on the base, where main() started the guard and the root widget did not. Two more tests pin that iOS never calls the channel and that the guard stops once the app is gone; each was proven by breaking the condition it guards. No change on a phone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>pull/1293/head
parent
bb7a5df8cb
commit
5bc88420fc
@ -0,0 +1,158 @@
|
||||
// #1231 / #1283: the running app, not only the guard class, repairs a keyboard
|
||||
// inset Android has already dropped (flutter/flutter#191156). Built from the
|
||||
// app's root widget, so it fails on any code that never starts the guard.
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/main.dart';
|
||||
import 'package:meshcore_open/services/app_debug_log_service.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/ble_debug_log_service.dart';
|
||||
import 'package:meshcore_open/services/block_service.dart';
|
||||
import 'package:meshcore_open/services/chat_text_scale_service.dart';
|
||||
import 'package:meshcore_open/services/map_tile_cache_service.dart';
|
||||
import 'package:meshcore_open/services/mesh_topology_service.dart';
|
||||
import 'package:meshcore_open/services/message_retry_service.dart';
|
||||
import 'package:meshcore_open/services/path_history_service.dart';
|
||||
import 'package:meshcore_open/services/radio_preset_service.dart';
|
||||
import 'package:meshcore_open/services/storage_health_service.dart';
|
||||
import 'package:meshcore_open/services/storage_service.dart';
|
||||
import 'package:meshcore_open/services/timeout_prediction_service.dart';
|
||||
import 'package:meshcore_open/services/translation_service.dart';
|
||||
import 'package:meshcore_open/services/ui_view_state_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
const _channel = MethodChannel('meshcore_open/keyboard_insets');
|
||||
|
||||
/// Android's side of the channel: the keyboard is hidden.
|
||||
class _FakeAndroid {
|
||||
final calls = <String>[];
|
||||
|
||||
Future<Object?> handle(MethodCall call) async {
|
||||
calls.add(call.method);
|
||||
return switch (call.method) {
|
||||
'getImeState' => <String, Object?>{
|
||||
'supported': true,
|
||||
'available': true,
|
||||
'sdkInt': 37,
|
||||
'imeVisible': false,
|
||||
'imeBottomPx': 0,
|
||||
'navBottomPx': 126,
|
||||
},
|
||||
'reapplyInsets' => 'reapplied',
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pumpApp(WidgetTester tester) async {
|
||||
final storage = StorageService();
|
||||
final settings = AppSettingsService();
|
||||
await tester.pumpWidget(
|
||||
MeshCoreApp(
|
||||
storageHealth: StorageHealthService(),
|
||||
connector: MeshCoreConnector(),
|
||||
retryService: MessageRetryService(),
|
||||
pathHistoryService: PathHistoryService(storage),
|
||||
meshTopologyService: MeshTopologyService(),
|
||||
storage: storage,
|
||||
appSettingsService: settings,
|
||||
bleDebugLogService: BleDebugLogService(),
|
||||
appDebugLogService: AppDebugLogService(),
|
||||
mapTileCacheService: MapTileCacheService(),
|
||||
chatTextScaleService: ChatTextScaleService(),
|
||||
translationService: TranslationService(settings),
|
||||
uiViewStateService: UiViewStateService(),
|
||||
timeoutPredictionService: TimeoutPredictionService(storage),
|
||||
blockService: BlockService(),
|
||||
radioPresetService: RadioPresetService(),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PackageInfo.setMockInitialValues(
|
||||
appName: 'Offband MeshCore',
|
||||
packageName: 'app.offband.meshcore',
|
||||
version: '1.9.0',
|
||||
buildNumber: '1',
|
||||
buildSignature: '',
|
||||
);
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'the app re-applies a keyboard inset Android has dropped',
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.android),
|
||||
(tester) async {
|
||||
final android = _fakeAndroid(tester);
|
||||
await _pumpApp(tester);
|
||||
|
||||
await _staleInsetAfterResume(tester);
|
||||
|
||||
expect(android.calls, contains('reapplyInsets'));
|
||||
await _unmount(tester);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'off Android the app never asks the native side',
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
|
||||
(tester) async {
|
||||
final android = _fakeAndroid(tester);
|
||||
await _pumpApp(tester);
|
||||
|
||||
await _staleInsetAfterResume(tester);
|
||||
|
||||
expect(android.calls, isEmpty);
|
||||
await _unmount(tester);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'once the app is gone the guard stops',
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.android),
|
||||
(tester) async {
|
||||
final android = _fakeAndroid(tester);
|
||||
await _pumpApp(tester);
|
||||
await _unmount(tester);
|
||||
|
||||
await _staleInsetAfterResume(tester);
|
||||
|
||||
expect(android.calls, isEmpty);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
_FakeAndroid _fakeAndroid(WidgetTester tester) {
|
||||
final android = _FakeAndroid();
|
||||
final messenger = tester.binding.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(_channel, android.handle);
|
||||
addTearDown(() {
|
||||
messenger.setMockMethodCallHandler(_channel, null);
|
||||
tester.view.reset();
|
||||
});
|
||||
return android;
|
||||
}
|
||||
|
||||
/// Backgrounded mid-animation: Flutter is handed the keyboard-open inset
|
||||
/// again on the way back, with no keyboard on screen.
|
||||
Future<void> _staleInsetAfterResume(WidgetTester tester) async {
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
tester.view.viewInsets = const FakeViewPadding(bottom: 846);
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
await tester.pump(const Duration(milliseconds: 600));
|
||||
}
|
||||
|
||||
Future<void> _unmount(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
}
|
||||
Loading…
Reference in new issue