mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-12-01 02:02:33 +01:00
Choosing where to ride replaces the action handler, and that choice read dart:io's Platform, so a staged Android build got the desktop handler back the moment a target was picked. It now reads HostPlatform like the other gates: the Android build gets AndroidActions (local control through the accessibility service). Unchanged outside tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
112 lines
4.6 KiB
Dart
112 lines
4.6 KiB
Dart
// The host-platform seam: feature gates that depend on the operating system
|
|
// read it instead of dart:io's Platform, so a test can stage the Android (or
|
|
// iOS) build on a desktop test host. Off by default: without an override the
|
|
// gates see the real host.
|
|
import 'dart:io';
|
|
|
|
import 'package:bike_control/gen/l10n.dart';
|
|
import 'package:bike_control/main.dart' show OtherLocalizationsDelegate;
|
|
import 'package:bike_control/pages/home/home_extras.dart';
|
|
import 'package:bike_control/utils/actions/android.dart';
|
|
import 'package:bike_control/utils/actions/base_actions.dart';
|
|
import 'package:bike_control/utils/core.dart';
|
|
import 'package:bike_control/utils/host_platform.dart';
|
|
import 'package:bike_control/utils/keymap/apps/my_whoosh.dart';
|
|
import 'package:bike_control/utils/requirements/android.dart';
|
|
import 'package:bike_control/utils/requirements/multi.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
|
|
|
import 'widget_snapshot.dart';
|
|
|
|
Future<void> main() async {
|
|
await ensureSnapshotHarness();
|
|
|
|
tearDown(() {
|
|
debugHostPlatformOverride = null;
|
|
core.actionHandler = StubActions();
|
|
});
|
|
|
|
test('without an override it is the real host', () {
|
|
expect(HostPlatform.isAndroid, Platform.isAndroid);
|
|
expect(HostPlatform.isIOS, Platform.isIOS);
|
|
expect(HostPlatform.isMacOS, Platform.isMacOS);
|
|
expect(HostPlatform.isWindows, Platform.isWindows);
|
|
});
|
|
|
|
test('an override stands in for the host', () {
|
|
debugHostPlatformOverride = TargetPlatform.android;
|
|
expect(HostPlatform.isAndroid, isTrue);
|
|
expect(HostPlatform.isIOS, isFalse);
|
|
expect(HostPlatform.isMacOS, isFalse);
|
|
expect(HostPlatform.isWindows, isFalse);
|
|
});
|
|
|
|
test('an Android build with the accessibility service can run it', () {
|
|
core.actionHandler = AndroidActions();
|
|
debugHostPlatformOverride = TargetPlatform.android;
|
|
expect(core.logic.canRunAndroidService, isTrue);
|
|
debugHostPlatformOverride = TargetPlatform.iOS;
|
|
expect(core.logic.canRunAndroidService, isFalse);
|
|
});
|
|
|
|
test('local control on an Android build asks for the accessibility service', () {
|
|
core.settings.setTrainerApp(MyWhoosh());
|
|
core.settings.setLastTarget(Target.thisDevice);
|
|
debugHostPlatformOverride = TargetPlatform.android;
|
|
expect(core.logic.showLocalControl, isTrue);
|
|
expect(core.permissions.getLocalControlRequirements().single, isA<AccessibilityRequirement>());
|
|
debugHostPlatformOverride = TargetPlatform.iOS;
|
|
expect(core.logic.showLocalControl, isFalse);
|
|
});
|
|
|
|
test('choosing this device on an Android build drives it through the accessibility service', () async {
|
|
// The accessibility plugin AndroidActions talks to on init.
|
|
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
|
const plugin = 'dev.flutter.pigeon.accessibility.';
|
|
messenger.setMockMessageHandler(
|
|
'${plugin}Accessibility.setHandledKeys',
|
|
(_) async => const StandardMessageCodec().encodeMessage(<Object?>[null]),
|
|
);
|
|
for (final stream in ['streamEvents', 'hidKeyPressed']) {
|
|
messenger.setMockMessageHandler(
|
|
'${plugin}EventChannelMethods.$stream',
|
|
(_) async => const StandardMethodCodec().encodeSuccessEnvelope(null),
|
|
);
|
|
}
|
|
debugHostPlatformOverride = TargetPlatform.android;
|
|
core.settings.setTrainerApp(MyWhoosh());
|
|
await core.settings.setLastTarget(Target.thisDevice);
|
|
expect(core.actionHandler, isA<AndroidActions>());
|
|
});
|
|
|
|
testWidgets('phone steering is offered on an Android build, not on a desktop one', (tester) async {
|
|
Future<void> pump() async {
|
|
await tester.pumpWidget(
|
|
ShadcnApp(
|
|
localizationsDelegates: const [
|
|
...ShadcnLocalizations.localizationsDelegates,
|
|
OtherLocalizationsDelegate(),
|
|
AppLocalizations.delegate,
|
|
],
|
|
supportedLocales: AppLocalizations.delegate.supportedLocales,
|
|
theme: snapshotTheme(Brightness.light),
|
|
home: SingleChildScrollView(child: HomeExtras(isMobile: true, onUpdate: () {})),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
|
|
debugHostPlatformOverride = TargetPlatform.android;
|
|
await pump();
|
|
expect(find.text(AppLocalizations.current.enableSteeringWithPhone), findsOneWidget);
|
|
expect(find.text(AppLocalizations.current.enableMediaKeyDetection), findsNothing);
|
|
|
|
debugHostPlatformOverride = TargetPlatform.macOS;
|
|
await tester.pumpWidget(const SizedBox());
|
|
await pump();
|
|
expect(find.text(AppLocalizations.current.enableSteeringWithPhone), findsNothing);
|
|
});
|
|
}
|