Files
swiftcontrol/test/host_platform_test.dart
Jonas Acker bbba10bee6 feat(ui): Devices, Activity and Settings tabs
Devices is the setup chain as grouped rows instead of cards:

- Controllers: one row per connected or remembered controller (tile,
  name, firmware and signal, status dot, battery), which opens its page,
  and "Connect Controllers" (scanning hint) for the setup sheet. With
  nothing paired the invitation row carries the checklist. Absent devices
  still swipe away with Undo.
- Smart trainer: bridged / connecting / waiting status, "to <app>", and
  live power, cadence and gear under the row; opens the trainer or the
  connect sheet. With none, an invitation plus "Share sensors instead".
  In sensors-only mode the sensors row takes the slot as before.
- Trainer app: name, connection method and status; opens Connection
  settings.
- Each row keeps its outstanding steps and their fix buttons ("Set up",
  "Enable overlay" / "Not now", Troubleshoot...) under it, and Ride's
  "Show" still scrolls to and flashes the outstanding rows (no motion
  with reduced motion).
- Share sensors (PRO without Pro, live chips while on), Other inputs
  (phone steering, Bluetooth media remotes, ignored devices with count)
  and Accessories as grouped rows.

Activity is a grouped list: "Last minute" and "Earlier" (rows move over
as they age), a glyph per kind of entry, the button and controller under
the message, the age at the end, errors in red with their fix as a link,
a footer on how much is kept, and an empty state. Clear sits in the page
header. Ride's activity column and preview use the same row.

Settings: a plan card (Go Pro or Manage, and today's virtual shifting
trial meter while Pro is off on this device); Riding with (trainer app,
connection method, gear count while a trainer shifts); During the ride
(overlay, vibration, shift sound, Apple Health where supported, moved
here from Devices); Help & support; App with Quit on phones.

Connection settings: the trainer app as a card with Change, method cards
without outlines (icon tile, switch, status, description, Instructions /
Supported actions links), section headers and a Network troubleshooting
row. Method logic is unchanged.

Also fixes the Spanish, French and Polish "Clear" translations.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-29 10:46:54 +02:00

112 lines
4.5 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/devices/devices_page.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: OtherInputsSection(onUpdate: () {})),
),
);
await tester.pump();
}
debugHostPlatformOverride = TargetPlatform.android;
await pump();
expect(find.text(AppLocalizations.current.devicesPhoneSteering), findsOneWidget);
expect(find.text(AppLocalizations.current.devicesMediaRemotes), findsNothing);
debugHostPlatformOverride = TargetPlatform.macOS;
await tester.pumpWidget(const SizedBox());
await pump();
expect(find.text(AppLocalizations.current.devicesPhoneSteering), findsNothing);
});
}