Files
swiftcontrol/test/screenshot_test.dart
Jonas Bark a8c18633e0 fix(store): show a finished setup on the home board, and stop the corner eating the status bar
Four things the first pass got wrong.

The home screen is the first board on the listing, and it was advertising
an unconfigured app: an amber "3 steps left — Controller & Trainer app
still need setting up" banner, nine controller cards (the set the card
goldens further down need, not a rider's bars), a steering gauge reading
"Calibrating…" where the Click V2's contour belongs, and an "Unlock it
with Zwift" card. The scene now runs with one controller — the Click V2,
which `screenshotMode` already shows as "Controller" — its unlock-mode
choice made and its unlock persisted, the trainer bridged and the
MyWhoosh Link connected. Every one of those buys off a step the home
chain was counting, so the banner is green and the controller card draws
its contour.

The device's corner radius was a fraction of the viewport WIDTH, which is
fine on a portrait phone and wrong on a landscape tablet: 78 logical
units on the 917-wide iPad viewport, where golden_screenshot's status bar
image puts the battery 23 units in from the right. It ate the battery.
Radius and bezel now scale off the viewport's SHORT side — a bezel is a
physical property of the device, not of the orientation it is held in —
and phones and tablets get their own radius fractions, because a real
phone is dramatically rounder than a real tablet. store_board_test.dart
holds every slot's corner arc clear of that status bar corner, with the
insets measured off the package's own topbar assets.

Version to 6.4.2+146, which the boards print in the overview header — the
fixture was still claiming 6.1.0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-15 14:09:42 +02:00

1224 lines
50 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@Tags(['screenshots'])
library;
import 'package:bike_control/bluetooth/devices/base_device.dart';
import 'package:bike_control/bluetooth/devices/bluetooth_device.dart';
import 'package:bike_control/bluetooth/devices/cycplus/cycplus_bc2.dart';
import 'package:bike_control/bluetooth/devices/elite/elite_sterzo.dart';
import 'package:bike_control/bluetooth/devices/gyroscope/gyroscope_steering.dart';
import 'package:bike_control/bluetooth/devices/proxy/proxy_device.dart';
import 'package:bike_control/bluetooth/devices/thinkrider/thinkrider_vs200.dart';
import 'package:bike_control/bluetooth/devices/zwift/constants.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_click.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_clickv2.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_play.dart';
import 'package:bike_control/bluetooth/devices/zwift/zwift_ride.dart';
import 'package:bike_control/bluetooth/messages/notification.dart';
import 'package:bike_control/utils/actions/base_actions.dart';
import 'package:bike_control/gen/l10n.dart';
import 'package:bike_control/main.dart';
import 'package:bike_control/pages/button_simulator.dart';
import 'package:bike_control/pages/configuration.dart';
import 'package:bike_control/pages/controller_settings.dart';
import 'package:bike_control/pages/navigation.dart';
import 'package:bike_control/pages/overview.dart';
import 'package:bike_control/pages/proxy_device_details.dart';
import 'package:bike_control/pages/proxy_device_details/front_shift_card.dart';
import 'package:bike_control/pages/proxy_device_details/gear_ratios_editor_page.dart';
import 'package:bike_control/pages/proxy_device_details/overlay_settings_section.dart';
import 'package:bike_control/pages/proxy_device_details/shifting_config_picker.dart';
import 'package:bike_control/pages/proxy_device_details/trainer_settings_section.dart';
import 'package:bike_control/models/shifting_config.dart';
import 'package:bike_control/services/overlay/trainer_overlay_service.dart';
import 'package:bike_control/pages/trainer_connection_settings.dart';
import 'package:bike_control/utils/core.dart' show core;
import 'package:bike_control/utils/iap/iap_manager.dart';
import 'package:bike_control/utils/keymap/apps/bike_control.dart';
import 'package:bike_control/utils/keymap/apps/my_whoosh.dart';
import 'package:bike_control/utils/keymap/apps/rouvy.dart';
import 'package:bike_control/utils/keymap/apps/supported_app.dart';
import 'package:bike_control/utils/keymap/apps/training_peaks.dart';
import 'package:bike_control/utils/keymap/apps/zwift.dart';
import 'package:bike_control/utils/keymap/buttons.dart';
import 'package:bike_control/utils/keymap/keymap.dart';
import 'package:bike_control/services/overlay/overlay_state.dart';
import 'package:bike_control/services/overview_screenshot.dart';
import 'package:bike_control/utils/requirements/multi.dart';
import 'package:bike_control/widgets/apps/di2_ble_tile.dart';
import 'package:bike_control/widgets/apps/local_tile.dart';
import 'package:bike_control/widgets/apps/mywhoosh_link_tile.dart';
import 'package:bike_control/widgets/apps/openbikecontrol_ble_tile.dart';
import 'package:bike_control/widgets/apps/openbikecontrol_mdns_tile.dart';
import 'package:bike_control/widgets/apps/zwift_mdns_tile.dart';
import 'package:bike_control/widgets/apps/zwift_tile.dart';
import 'package:bike_control/widgets/controller/controller_canvas.dart';
import 'package:bike_control/widgets/overlay/trainer_overlay_view.dart';
import 'package:bike_control/widgets/ui/animated_button_widget.dart';
import 'package:flutter/material.dart' as ma;
import 'package:flutter/services.dart' show MethodChannel;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_screenshot/golden_screenshot.dart' hide testGoldens;
import 'package:integration_test/integration_test.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:prop/emulators/definitions/fitness_bike_definition.dart';
import 'package:prop/emulators/dircon_emulator.dart';
import 'package:prop/emulators/transporter/network_transporter.dart';
import 'package:prop/utils/prefs.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:universal_ble/universal_ble.dart';
import 'custom_frame.dart';
import 'store_copy.dart';
/// Drop-in for golden_screenshot's [testGoldens] that leaves
/// [debugDisableShadows] = false at teardown.
///
/// These screenshot tests run under the live
/// [IntegrationTestWidgetsFlutterBinding] (needed for the real-async Supabase /
/// settings bootstrap in [main]), whose painting-vars invariant requires
/// debugDisableShadows == false. golden_screenshot's own testGoldens resets it
/// to true — correct only for the automated binding — which trips that
/// invariant. Shadows stay enabled during capture, so the goldens are identical.
void testGoldens(
String description,
WidgetTesterCallback callback, {
// Mirrors golden_screenshot's internal kAllowedDiffPercent default.
double allowedDiffPercent = 0.1,
}) {
testWidgets(description, (tester) async {
debugDisableShadows = false;
tester.useFuzzyComparator(allowedDiffPercent: allowedDiffPercent);
try {
await callback(tester);
} finally {
debugDisableShadows = false;
}
});
}
Future<void> main() async {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
// The overview header prints this, so every board carries it — keep it on
// the version being shipped rather than whichever one the fixture was
// written against.
PackageInfo.setMockInitialValues(
appName: 'BikeControl',
packageName: 'de.jonasbark.swiftcontrol',
version: '6.4.2',
buildNumber: '146',
buildSignature: '',
);
FlutterSecureStorage.setMockInitialValues({});
SharedPreferences.setMockInitialValues({});
IAPManager.instance.isPurchased.value = true;
screenshotMode = true;
// Some setup (e.g. core.whooshLink) reads AppLocalizations.current before any
// app widget has loaded the delegate, so load it up front. Without this, a
// single test run in isolation throws "No instance of AppLocalizations".
await AppLocalizations.load(const Locale('en'));
await core.settings.init();
await core.settings.reset();
final keymap = MyWhoosh();
final device =
ZwiftClickV2(
BleDevice(
name: 'Controller',
deviceId: '00:11:22:33:44:55',
),
)
..firmwareVersion = '1.2.0'
..isConnected = true
..rssi = -51
..batteryLevel = 81;
final proxy =
ProxyDevice(
BleDevice(
name: 'Smart Trainer',
deviceId: '00:11:22:33:44:55',
services: [
FitnessBikeDefinition.FITNESS_MACHINE_SERVICE_UUID,
],
),
)
..services = [
BleService(FitnessBikeDefinition.FITNESS_MACHINE_SERVICE_UUID, []),
]
..firmwareVersion = '1.2.0'
..isConnected = true
..rssi = -51;
final fbd = FitnessBikeDefinition(
connectedDevice: proxy.scanResult,
connectedDeviceServices: proxy.services!,
data: ValueNotifier(''),
)..setDebugValues();
proxy.emulator.debugSetTransporter(NetworkTransporter(definition: fbd));
core.connection.addDevices([device, proxy]);
// Connected instances of every controller we shoot a full connection-card
// golden for. Each is given a real advertised name (so the card header shows
// the actual product name) and the connected meta (battery/rssi/firmware) the
// overview list would display. `device` above is the Zwift Click v2 instance.
BleDevice scan(String name) => BleDevice(name: name, deviceId: '00:11:22:33:44:55');
// BLE controllers carry battery / rssi / firmware meta (defined on
// BluetoothDevice); set it so the card header shows the connected status line.
T connectedBle<T extends BluetoothDevice>(T d) {
d
..firmwareVersion = '1.2.0'
..isConnected = true
..rssi = -51
..batteryLevel = 81;
return d;
}
final zwiftClick = connectedBle(ZwiftClick(scan('Zwift Click')));
final zwiftRide = connectedBle(ZwiftRide(scan('Zwift Ride')));
final zwiftPlay = connectedBle(
ZwiftPlay(scan('Zwift Play'), deviceType: ZwiftDeviceType.playLeft),
);
final cycplusBc2 = connectedBle(CycplusBc2(scan('CYCPLUS BC2')));
final thinkriderVs200 = connectedBle(ThinkRiderVs200(scan('THINK VS200')));
final eliteSterzo = connectedBle(EliteSterzo(scan('STERZO')));
// GyroscopeSteering extends BaseDevice directly (no BLE), so it has no
// battery/rssi/firmware — just mark it connected.
final gyroSteering = GyroscopeSteering()..isConnected = true;
// All controllers must live in core.connection.devices so the MyWhoosh
// action handler (initialized below) seeds each button's default in-game
// action into the keymap — that's what renders the action badges.
core.connection.addDevices([
zwiftClick,
zwiftRide,
zwiftPlay,
cycplusBc2,
thinkriderVs200,
eliteSterzo,
gyroSteering,
]);
// core.actionHandler is `late` (assigned in the app's main(), which the test
// harness never runs). Provide a StubActions and init it with MyWhoosh so
// core.actionHandler.supportedApp?.keymap is the populated MyWhoosh keymap the
// connected-Controllers footer passes to AnimatedButtonWidget.
core.actionHandler = StubActions();
core.actionHandler.init(MyWhoosh());
final firstButton = ZwiftButtons.b.copyWith(sourceDeviceId: device.uniqueId);
final keyEntry = keymap.keymap.getOrCreateKeyPair(firstButton, trigger: ButtonTrigger.longPress);
keyEntry.inGameAction = InGameAction.steerRight;
core.settings.setRetrofitMode(proxy.trainerKey, RetrofitMode.wifi);
core.settings.setTrainerApp(keymap);
core.settings.setKeyMap(keymap);
core.settings.setLastTarget(Target.thisDevice);
// The slot table lives in custom_frame.dart, next to the board that lays them
// out, so store_board_test.dart can assert against the real slots.
const sizes = kStoreSlots;
debugDisableShadows = true;
// Locales to render — see kScreenshotLocales.
const screenshotLocales = kScreenshotLocales;
// Marketing copy, the brand gradient and the per-scene hue ramp all live in
// store_copy.dart, so the board tests can read them without booting the app.
// Renders [scene] for every locale × device size and writes
// ../screenshots/<locale>/<scene>-<device>-<WxH>.png.
Future<void> shoot(
WidgetTester tester,
String scene,
Widget Function() homeBuilder, {
Future<void> Function(WidgetTester tester)? afterPump,
}) async {
// The gradient rotated to this scene's place in the listing, so the six
// boards read as a series rather than as one image repeated.
final sceneStyle = kStoreBrandStyle.forScene(scene);
// core.settings.reset() (in main) clears this, so re-assert the Base version
// is active — otherwise the overview shows the "N day trial available" banner.
IAPManager.instance.isPurchased.value = true;
for (final loc in screenshotLocales) {
await AppLocalizations.load(Locale(loc));
screenshotLocale = Locale(loc);
for (final size in sizes) {
await tester.pumpWidget(
ScreenshotApp(
locale: Locale(loc),
device: ScreenshotDevice(
platform: size.platform,
resolution: size.size,
pixelRatio: 3,
goldenSubFolder: 'iphoneScreenshots/',
frameBuilder:
({
required ScreenshotDevice device,
required ScreenshotFrameColors? frameColors,
required Widget child,
}) => CustomFrame(
platform: size.type,
title: sceneHeadline(scene, loc),
accent: sceneAccent(scene, loc),
style: sceneStyle,
device: device,
frameColors: frameColors,
child: child,
),
),
home: homeBuilder(),
),
);
await tester.pump();
if (afterPump != null) await afterPump(tester);
// golden_screenshot v9+ only loads fonts found in the rendered widget
// tree, so load after the first pump (then re-render with them).
await tester.loadAssets();
await tester.pump();
await expectLater(
find.byType(ma.Scaffold),
matchesGoldenFile(
'../screenshots/$loc/$scene-${size.type.name}-${size.size.width.toInt()}x${size.size.height.toInt()}.png',
),
);
}
}
}
// Blog screenshot: a single clean frameless (noFrame) English shot written to
// ../screenshots/en/<scene>-noFrame-1100x2390.png — used for the website blog,
// not the localized App Store matrix that [shoot] produces.
Future<void> shootOne(
WidgetTester tester,
String scene,
Widget Function() home, {
Finder Function()? capture,
Future<void> Function(WidgetTester tester)? afterPump,
TargetPlatform platform = TargetPlatform.android,
// Override the (frameless) render resolution. Defaults to the noFrame size
// (~367 logical px wide); pass a wider Size for widgets that need more room
// (e.g. a Row whose Select would collapse at phone-narrow widths).
Size? size,
}) async {
final nf = sizes.firstWhere((s) => s.type == DeviceType.noFrame);
final res = size ?? nf.size;
await AppLocalizations.load(const Locale('en'));
screenshotLocale = const Locale('en');
await tester.pumpWidget(
ScreenshotApp(
locale: const Locale('en'),
device: ScreenshotDevice(
// Default Android, never the entry's Windows platform: shadcn's theme
// queries the Windows accent colour via advapi32.dll, which can't load
// on a macOS test host.
platform: platform,
resolution: res,
pixelRatio: 3,
goldenSubFolder: 'iphoneScreenshots/',
frameBuilder:
({
required ScreenshotDevice device,
required ScreenshotFrameColors? frameColors,
required Widget child,
}) => CustomFrame(platform: DeviceType.noFrame, title: '', device: device, child: child),
),
home: home(),
),
);
await tester.pump();
if (afterPump != null) await afterPump(tester);
await tester.loadAssets();
await tester.pump();
await expectLater(
capture?.call() ?? find.byType(ma.Scaffold),
matchesGoldenFile('../screenshots/en/$scene.png'),
);
}
// Localized widget snapshot: like [shootOne], but renders the (frameless,
// noFrame) widget once per locale and writes ../screenshots/<loc>/<scene>.png.
// Used for the website setup guides, which show the matching-language widget
// screenshots. The website uses the en/de/es/fr/it intersection of the app's
// and the site's supported locales; Czech falls back to en on the website.
Future<void> shootLocalized(
WidgetTester tester,
String scene,
Widget Function() home, {
Finder Function()? capture,
Future<void> Function(WidgetTester tester)? afterPump,
TargetPlatform platform = TargetPlatform.android,
}) async {
const widgetLocales = ['en', 'de', 'es', 'fr', 'it'];
final nf = sizes.firstWhere((s) => s.type == DeviceType.noFrame);
for (final loc in widgetLocales) {
await AppLocalizations.load(Locale(loc));
screenshotLocale = Locale(loc);
await tester.pumpWidget(
ScreenshotApp(
locale: Locale(loc),
device: ScreenshotDevice(
// Default Android, never the entry's Windows platform: shadcn's theme
// queries the Windows accent colour via advapi32.dll, which can't load
// on a macOS test host.
platform: platform,
resolution: nf.size,
pixelRatio: 3,
goldenSubFolder: 'iphoneScreenshots/',
frameBuilder:
({
required ScreenshotDevice device,
required ScreenshotFrameColors? frameColors,
required Widget child,
}) => CustomFrame(platform: DeviceType.noFrame, title: '', device: device, child: child),
),
home: home(),
),
);
await tester.pump();
if (afterPump != null) await afterPump(tester);
await tester.loadAssets();
await tester.pump();
await expectLater(
capture?.call() ?? find.byType(ma.Scaffold),
matchesGoldenFile('../screenshots/$loc/$scene.png'),
);
}
}
// The home screen — the first board on the listing, so it has to show a
// FINISHED setup. The home chain derives its top banner from the cards below
// it, and anything outstanding turns that banner amber ("3 steps left —
// Controller & Trainer app still need setting up"), which is not a claim a
// store listing should make. Every line below buys off one outstanding step:
//
// * one controller, not the nine the card goldens further down need. The
// marketing shot is a phone with a Zwift Click V2 on the bars, and the
// smart trainer it bridges — a stack of every controller BikeControl
// supports reads as a lab bench.
// * the Click V2's unlock-mode choice made and its unlock persisted, so the
// controller card is green instead of carrying "Unlock it with Zwift".
// * the MyWhoosh Link enabled AND connected, which is what satisfies the
// app link's "connection method" and "connected" steps.
// * the trainer bridged, so its card reads "connected" rather than offering
// a "Connect" button on the flagship image. (`isBridged` is what the
// chain calls connected for a trainer — the bridge running, not merely a
// Bluetooth link — so driving the wrapper is enough.)
testGoldens('Device', (WidgetTester tester) async {
final savedDevices = core.connection.devices.toList();
core.connection.devices
..clear()
..addAll([device, proxy]);
core.connection.hasDevices.value = true;
await core.settings.setClickV2OnboardingDone(true);
propPrefs.setZwiftClickV2LastUnlock(device.scanResult.deviceId, DateTime.now());
core.settings.setMyWhooshLinkEnabled(true);
core.whooshLink.isConnected.value = true;
proxy.debugSetTrainerAppConnected(true);
try {
await shoot(tester, 'device', () => BikeControlApp());
} finally {
// Restored so the scenes stay independent of the order they run in.
proxy.debugSetTrainerAppConnected(false);
core.connection.devices
..clear()
..addAll(savedDevices);
core.connection.hasDevices.value = core.connection.devices.isNotEmpty;
}
});
testGoldens('Trainer', (WidgetTester tester) async {
core.settings.setTrainerApp(BikeControl());
core.settings.setKeyMap(BikeControl());
await shoot(
tester,
'trainer',
() => BikeControlApp(customChild: TrainerConnectionSettingsPage()),
);
});
testGoldens('Customization', (WidgetTester tester) async {
core.settings.setTrainerApp(keymap);
core.settings.setKeyMap(keymap);
await shoot(
tester,
'customization',
() => BikeControlApp(customChild: ControllerSettingsPage(device: device)),
);
});
testGoldens('Trainer Controls', (WidgetTester tester) async {
core.settings.setTrainerApp(keymap);
core.settings.setKeyMap(keymap);
core.settings.setMyWhooshLinkEnabled(true);
core.whooshLink.isConnected.value = true;
await shoot(
tester,
'companion',
() => BikeControlApp(customChild: ButtonSimulator()),
);
});
testGoldens('Virtual Shifting', (WidgetTester tester) async {
core.settings.setTrainerApp(keymap);
core.settings.setKeyMap(keymap);
core.settings.setMyWhooshLinkEnabled(true);
core.whooshLink.isConnected.value = true;
// Put the proxy into virtual-shifting mode so the page shows the gear UI
// instead of the "trainer doesn't advertise FTMS" warning.
proxy.debugAttachFitnessBike(fbd);
await shoot(
tester,
'virtualshifting',
() => BikeControlApp(customChild: ProxyDeviceDetailsPage(device: proxy)),
);
});
testGoldens('Virtual Shifting Settings', (WidgetTester tester) async {
core.settings.setTrainerApp(Zwift());
core.settings.setKeyMap(Zwift());
core.settings.setMyWhooshLinkEnabled(true);
core.whooshLink.isConnected.value = true;
await shoot(
tester,
'virtualshifting-settings',
() => BikeControlApp(
customChild: GearRatiosEditorPage(
device: proxy,
definition: fbd,
),
),
);
});
// --- 6.2 Virtual front derailleur (blog widget snapshots) ---
// Each widget is rendered standalone inside a keyed RepaintBoundary so the
// golden captures ONLY that widget (no page chrome).
// The second-window / desktop gear overlay (TrainerOverlayView), as shown on
// Windows & macOS. Large ring → the primary readout uses the 2×N position
// notation (here 2×14). Mirrors desktop_overlay_window: bare overlay on white.
testGoldens('Front Derailleur Gear', (WidgetTester tester) async {
const k = ValueKey('shot');
final state = ValueNotifier<TrainerOverlayState>(
const TrainerOverlayState(
gear: 14,
maxGear: 24,
gearRatio: 3.53,
mode: TrainerMode.simMode,
powerW: 250,
cadenceRpm: 90,
ergTargetW: null,
fields: {OverlayField.power, OverlayField.cadence},
frontShiftEnabled: true,
frontRingLarge: true,
),
);
await shootOne(
tester,
'frontderailleur-gear',
() => BikeControlApp(
customChild: Center(
child: RepaintBoundary(
key: k,
child: ColoredBox(
color: const Color(0xFFFFFFFF),
child: SizedBox(
width: 240,
child: TrainerOverlayView(state: state, onModeToggle: null),
),
),
),
),
),
capture: () => find.byKey(k),
platform: TargetPlatform.macOS,
);
});
// The front-derailleur setting card, enabled so the chainring steppers show.
testGoldens('Front Derailleur Setting', (WidgetTester tester) async {
await core.shiftingConfigs.upsert(
core.shiftingConfigs.activeFor(proxy.trainerKey).copyWith(
frontShiftEnabled: true,
smallChainringTeeth: 34,
largeChainringTeeth: 50,
),
);
const k = ValueKey('shot');
await shootOne(
tester,
'frontderailleur-setting',
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(24),
child: RepaintBoundary(key: k, child: FrontShiftCard(device: proxy, definition: fbd)),
),
),
),
capture: () => find.byKey(k),
);
});
// --- MyWhoosh setup-guide widget snapshots (website setup guide) ---
// Tight single-widget captures of the two BikeControl controls the MyWhoosh
// setup guide walks through: the trainer-app picker (showing MyWhoosh) and the
// "Connect directly over Network" connection method. Rendered standalone inside
// a keyed RepaintBoundary so the golden captures ONLY the widget.
// The trainer-app picker with MyWhoosh selected. screenshotMode stays on (it
// suppresses the real BLE bootstrap) and TrainerAppSelect.showRealName forces
// the closed Select to show the real "MyWhoosh" name + logo instead of the
// generic "Trainer app" placeholder the marketing screenshots use.
testGoldens('mywhoosh-trainer-select', (WidgetTester tester) async {
core.settings.setTrainerApp(MyWhoosh());
core.settings.setKeyMap(MyWhoosh());
const k = ValueKey('shot');
await shootLocalized(
tester,
'mywhoosh-trainer-select',
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(24),
child: RepaintBoundary(
key: k,
child: TrainerAppSelect(onUpdate: () {}, showRealName: true),
),
),
),
),
capture: () => find.byKey(k),
);
});
// The Network connection method (OpenBikeControl over mDNS), as shown for
// MyWhoosh, in its disabled/off state. The tile passes no requirements, so no
// real BLE is touched even though screenshotMode hides the "Recommended" badge.
testGoldens('mywhoosh-network-connection', (WidgetTester tester) async {
core.settings.setTrainerApp(MyWhoosh());
core.settings.setKeyMap(MyWhoosh());
core.settings.setObpMdnsEnabled(false);
// Force the off / not-yet-connected state so the captured card is identical
// regardless of any emulator state a prior scene left behind (the shown
// description and height depend on isStarted/connectedApp).
core.obpMdnsEmulator.isStarted.value = false;
core.obpMdnsEmulator.connectedApp.value = null;
const k = ValueKey('shot');
await shootLocalized(
tester,
'mywhoosh-network-connection',
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(24),
child: RepaintBoundary(
key: k,
child: OpenBikeControlMdnsTile(small: false),
),
),
),
),
capture: () => find.byKey(k),
);
});
// --- Full connection card (connected-controller list entry) ---
// The complete card the overview's Controllers list renders for a connected
// controller: `device.showInformation` draws the header Row (StatusIcon +
// name + Beta pill + status meta) and, below it, the footer — the
// `ControllerCanvas` contour with its buttons. Two deviations from the live
// app, both deliberate so the image is chrome-free:
// * `showSettingsIcon: false` hides the small header gear (settings live on
// a separate page, not in this card).
// * `showAdditionalInfo: false` drops the device's own state chrome (e.g.
// the Zwift Click unlock warning) so the card is state-agnostic.
// The footer's buttons DO carry the MyWhoosh keymap (via
// `core.actionHandler.supportedApp?.keymap`), so each button that maps to an
// in-game action renders its supported-action badge — exactly like the
// connected-Controllers list. Buttons with no action (e.g. pure steering on
// the Sterzo / phone) render as bare buttons.
//
// `ZwiftClickV2.toString()` anonymizes its name to "Controller" while the
// marketing `screenshotMode` is on; we flip it off *synchronously* around just
// the `showInformation` build so the header shows the real product name — and
// restore it immediately, before any async (the app's connection-init scan
// reads `screenshotMode` on a later microtask, by which point it is true
// again, so no BLE scan fires). Only ClickV2 needs this, but doing it
// uniformly is harmless for the other devices.
//
// Rendered inside `BikeControlApp` so the card has the real theme and an
// `i18n` context, standalone in a keyed RepaintBoundary (captured tight) at a
// fixed list-card width.
Future<void> shootCard(WidgetTester tester, String scene, BaseDevice cardDevice) async {
const k = ValueKey('shot');
final savedScreenshotMode = screenshotMode;
try {
await shootOne(
tester,
scene,
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Center(
child: SizedBox(
width: 340,
child: Padding(
padding: const EdgeInsets.all(16),
child: Builder(
builder: (context) {
// Footer mirrors overview.dart's footerBuilder: the
// active app's keymap drives the per-button action badges.
final keymap = core.actionHandler.supportedApp?.keymap;
final size = 56 / Theme.of(context).scaling;
Widget btnFor(ControllerButton btn) => AnimatedButtonWidget(
key: ValueKey(btn.name),
button: btn,
pressGeneration: 0,
keymap: keymap,
device: cardDevice,
size: size,
onUpdate: () {},
);
final footer = ControllerCanvas(
layout: cardDevice.controllerLayout!,
availableButtons: cardDevice.availableButtons,
buttonBuilder: btnFor,
buttonSize: size,
);
// Flip screenshotMode off only for this synchronous build
// so the header shows the real product name, then restore
// it before control returns to the framework.
final saved = screenshotMode;
screenshotMode = false;
final card = cardDevice.showInformation(
context,
showFull: false,
showSettingsIcon: false,
showAdditionalInfo: false,
footer: footer,
);
screenshotMode = saved;
return RepaintBoundary(key: k, child: card);
},
),
),
),
),
),
),
capture: () => find.byKey(k),
);
} finally {
screenshotMode = savedScreenshotMode;
}
}
testGoldens('controller-zwift-click', (WidgetTester tester) async {
await shootCard(tester, 'controller-zwift-click', zwiftClick);
});
testGoldens('controller-zwift-click-v2', (WidgetTester tester) async {
await shootCard(tester, 'controller-zwift-click-v2', device);
});
testGoldens('controller-zwift-ride', (WidgetTester tester) async {
await shootCard(tester, 'controller-zwift-ride', zwiftRide);
});
testGoldens('controller-zwift-play', (WidgetTester tester) async {
await shootCard(tester, 'controller-zwift-play', zwiftPlay);
});
testGoldens('controller-cycplus-bc2', (WidgetTester tester) async {
await shootCard(tester, 'controller-cycplus-bc2', cycplusBc2);
});
testGoldens('controller-thinkrider-vs200', (WidgetTester tester) async {
await shootCard(tester, 'controller-thinkrider-vs200', thinkriderVs200);
});
testGoldens('controller-elite-sterzo', (WidgetTester tester) async {
await shootCard(tester, 'controller-elite-sterzo', eliteSterzo);
});
testGoldens('controller-phone-steering', (WidgetTester tester) async {
await shootCard(tester, 'controller-phone-steering', gyroSteering);
});
// --- Rouvy & TrainingPeaks setup-guide widget snapshots (website setup guide) ---
// Tight single-widget captures mirroring the MyWhoosh setup-guide scenes above:
// the trainer-app picker (showing the active app's real name + logo) and the
// connection methods the guide walks through. The connection-methods scene
// reproduces `trainer.dart`'s `recommendedTiles` conditional expression VERBATIM
// (see [recommendedConnectionTiles]) so the snapshot shows exactly the tiles the
// live app renders for whichever app is active — driven by `core.logic.show*`.
// These flags are derived from the selected app's declared `connections`:
// * Rouvy supports (rouvyMdns, zwiftBle) → ZwiftMdnsTile + ZwiftTile.
// * TrainingPeaks supports (obpBle, obpDirCon) → OpenBikeControlMdnsTile +
// OpenBikeControlBluetoothTile.
// The BLE-backed flags (showZwiftBleEmulator / showObpBluetoothEmulator) ALSO
// require `getLastTarget() != Target.thisDevice`, so [setActiveApp] persists
// `Target.otherDevice` (the "run the app on another device" setup-guide path).
// Helper: set the active app exactly as selecting it in the app would, so the
// `core.logic.show*` flags become what the live app uses, then force every
// emulator into its off / not-yet-connected state so the captured cards are
// identical regardless of any emulator state a prior scene left behind (the
// shown description and height depend on isStarted/isConnected/connectedApp).
void setActiveApp(SupportedApp app) {
core.settings.setTrainerApp(app);
core.settings.setKeyMap(app);
// Selecting "another device" as the target is what enables the Bluetooth
// connection methods (showZwiftBleEmulator / showObpBluetoothEmulator both
// gate on getLastTarget() != Target.thisDevice). Without a non-null,
// non-thisDevice target the BLE tiles — and the whole tile block — are hidden.
core.settings.setLastTarget(Target.otherDevice);
// OBC (TrainingPeaks) tiles.
core.settings.setObpMdnsEnabled(false);
core.settings.setObpBleEnabled(false);
core.obpMdnsEmulator.isStarted.value = false;
core.obpMdnsEmulator.connectedApp.value = null;
core.obpMdnsEmulator.isConnected.value = false;
core.obpBluetoothEmulator.isStarted.value = false;
core.obpBluetoothEmulator.connectedApp.value = null;
core.obpBluetoothEmulator.isConnected.value = false;
// Zwift-protocol (Rouvy) tiles.
core.settings.setZwiftMdnsEmulatorEnabled(false);
core.settings.setZwiftBleEmulatorEnabled(false);
core.rouvyMdnsEmulator.isStarted.value = false;
core.rouvyMdnsEmulator.isConnected.value = false;
core.zwiftMdnsEmulator.isStarted.value = false;
core.zwiftMdnsEmulator.isConnected.value = false;
core.zwiftEmulator.isStarted.value = false;
core.zwiftEmulator.isConnected.value = false;
}
// The connection-method tiles the live app renders for the active app. This is
// `trainer.dart`'s `recommendedTiles` expression reproduced VERBATIM (same
// `if (core.logic.showX) XTile(small: false)` set, same order) so the snapshot
// matches the live app for whatever app `setActiveApp` selected. The onUpdate
// callbacks mirror trainer.dart's (signal a log notification); they never fire
// in the static snapshot.
List<Widget> recommendedConnectionTiles() {
// Verbatim from trainer.dart: the leading `false &&` is intentional (the
// "show Local as an Other method" path is currently disabled there).
// ignore: dead_code
final showLocalAsOther = false && core.logic.showLocalControl && !core.settings.getLocalEnabled();
final showWhooshLinkAsOther =
(core.logic.showObpBluetoothEmulator || core.logic.showObpMdnsEmulator) && core.logic.showMyWhooshLink;
return [
if (core.logic.showObpMdnsEmulator) OpenBikeControlMdnsTile(small: false),
if (core.logic.showObpBluetoothEmulator) OpenBikeControlBluetoothTile(small: false),
if (core.logic.showZwiftMsdnEmulator)
ZwiftMdnsTile(
small: false,
onUpdate: () {
core.connection.signalNotification(
LogNotification('Zwift Emulator status changed to ${core.zwiftEmulator.isConnected.value}'),
);
},
),
if (core.logic.showZwiftBleEmulator)
ZwiftTile(
small: false,
onUpdate: () {
core.connection.signalNotification(
LogNotification('Zwift Emulator status changed to ${core.zwiftEmulator.isConnected.value}'),
);
},
),
if (core.logic.showDi2Ble) Di2BleTile(small: false),
if (core.logic.showLocalControl && !showLocalAsOther) LocalTile(small: false),
if (core.logic.showMyWhooshLink && !showWhooshLinkAsOther) MyWhooshLinkTile(small: false),
];
}
// Render the recommended connection-method tiles for the active app the same
// way the trainer page lays them out (each tile in an IntrinsicHeight, stacked
// in a Column with 12px gaps), inside a keyed RepaintBoundary so the golden
// captures only the tile stack at a fixed setup-guide width.
Future<void> shootConnectionMethods(WidgetTester tester, String scene) async {
const k = ValueKey('shot');
await shootLocalized(
tester,
scene,
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Center(
child: SizedBox(
width: 340,
child: Padding(
padding: const EdgeInsets.all(24),
child: RepaintBoundary(
key: k,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (final tile in recommendedConnectionTiles())
Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: IntrinsicHeight(child: tile),
),
],
),
),
),
),
),
),
),
capture: () => find.byKey(k),
);
}
// The trainer-app picker with Rouvy selected (showRealName forces the real
// "Rouvy" name + logo instead of the generic "Trainer app" placeholder).
testGoldens('rouvy-trainer-select', (WidgetTester tester) async {
setActiveApp(Rouvy());
const k = ValueKey('shot');
await shootLocalized(
tester,
'rouvy-trainer-select',
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(24),
child: RepaintBoundary(
key: k,
child: TrainerAppSelect(onUpdate: () {}, showRealName: true),
),
),
),
),
capture: () => find.byKey(k),
);
});
// The connection methods the live app renders for Rouvy. Rouvy supports
// (rouvyMdns, zwiftBle), so this captures ZwiftMdnsTile (Network, over the
// Rouvy mDNS emulator) + ZwiftTile (Bluetooth) — NOT the OBC tiles — both in
// their off / not-yet-connected state.
testGoldens('rouvy-connection-methods', (WidgetTester tester) async {
setActiveApp(Rouvy());
await shootConnectionMethods(tester, 'rouvy-connection-methods');
});
// The trainer-app picker with TrainingPeaks selected. Note: TrainingPeaks's
// app name is "TrainingPeaks Virtual", so the closed Select (and the
// connection-method descriptions below) show "TrainingPeaks Virtual".
testGoldens('trainingpeaks-trainer-select', (WidgetTester tester) async {
setActiveApp(TrainingPeaks());
const k = ValueKey('shot');
await shootLocalized(
tester,
'trainingpeaks-trainer-select',
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(24),
child: RepaintBoundary(
key: k,
child: TrainerAppSelect(onUpdate: () {}, showRealName: true),
),
),
),
),
capture: () => find.byKey(k),
);
});
// The connection methods the live app renders for TrainingPeaks. TrainingPeaks
// supports (obpBle, obpDirCon), so this captures OpenBikeControlMdnsTile
// (Network) + OpenBikeControlBluetoothTile (Bluetooth), both off. Descriptions
// read "Lets TrainingPeaks Virtual connect…".
testGoldens('trainingpeaks-connection-methods', (WidgetTester tester) async {
setActiveApp(TrainingPeaks());
await shootConnectionMethods(tester, 'trainingpeaks-connection-methods');
});
// --- Overview / main screen (website setup-guide step 1) ---------------------
// A clean capture of the app's OVERVIEW page (Controllers card + Trainer
// Connection) showing ONLY a single connected controller with its REAL product
// name (not the anonymized "Controller" the App-Store `Device` shot uses). No
// device frame, no marketing title banner — just the app's own UI inside the
// frameless `noFrame` ScreenshotApp, localized one shot per locale.
//
// Two tricks make this work:
// * We render the full `Navigation()` (the overview Scaffold + its AppBar)
// while `screenshotMode == true`, so `Navigation.initState` →
// `core.logic.startEnabledConnectionMethod()` early-returns (no BLE/mDNS
// emulators start) and the page is laid out without any real connection.
// * To get the REAL device name we flip `screenshotMode` off *synchronously*
// for just the final `pump()` that produces the captured frame, then
// restore it. e.g. `ZwiftClickV2.toString()` is read during that build and
// returns "Zwift Click V2"; every async callback that re-reads the flag
// (timers, the connection-init scan) runs on a later microtask, by which
// point it is `true` again, so nothing scans. Harmless for the controllers
// whose names are never anonymized.
//
// `core.connection.devices` is reduced to exactly the given controller + the
// smart-trainer proxy (so the Trainer Connection card shows a connected
// trainer). The active trainer app is MyWhoosh (the harness default).
//
// The frameless `noFrame` size entry's logical width (~367 px) is just narrow
// enough that the AppBar wraps the "BikeControl" title to two lines. The
// overview here is rendered slightly wider — `overviewNoFrameSize`, ~500
// logical px — so the title fits on one line while staying well under the
// overview's 800-logical-px two-column breakpoint (so it remains a phone-style
// single-column portrait main screen).
//
// Captured via the Navigation Scaffold's existing `overviewScreenshotKey`
// RepaintBoundary → tight, no surrounding chrome.
final overviewNf = sizes.firstWhere((s) => s.type == DeviceType.noFrame);
// Widen just the overview shots so "BikeControl" no longer wraps. 1500 device
// px / pixelRatio 3 = 500 logical px — comfortably below the 800-logical-px
// two-column breakpoint, so it stays single-column portrait.
final overviewNoFrameSize = Size(1500, overviewNf.size.height);
Future<void> shootOverview(
WidgetTester tester,
String scene,
BaseDevice overviewDevice,
) async {
const overviewLocales = ['en', 'de', 'es', 'fr', 'it'];
// Only the given controller + the smart-trainer proxy.
final savedDevices = core.connection.devices.toList();
core.connection.devices
..clear()
..addAll([overviewDevice, proxy]);
core.connection.hasDevices.value = true;
// core.settings.reset() (in main) clears this, so re-assert the Base version
// is active — otherwise the overview shows the "trial available" IAP banner.
IAPManager.instance.isPurchased.value = true;
final savedScreenshotMode = screenshotMode;
try {
for (final loc in overviewLocales) {
await AppLocalizations.load(Locale(loc));
screenshotLocale = Locale(loc);
await tester.pumpWidget(
ScreenshotApp(
locale: Locale(loc),
device: ScreenshotDevice(
// Android, never the entry's Windows platform (advapi32.dll can't
// load on a macOS test host).
platform: TargetPlatform.android,
resolution: overviewNoFrameSize,
pixelRatio: 3,
goldenSubFolder: 'iphoneScreenshots/',
frameBuilder:
({
required ScreenshotDevice device,
required ScreenshotFrameColors? frameColors,
required Widget child,
}) => CustomFrame(platform: DeviceType.noFrame, title: '', device: device, child: child),
),
// Full overview Scaffold (header + Controllers card + Trainer
// Connection). screenshotMode is still true here, so initState does
// not start any connection method.
home: BikeControlApp(customChild: Navigation()),
),
);
await tester.pump();
await tester.loadAssets();
// Flip screenshotMode off only for the synchronous build/pump that
// produces the captured frame, so the Controllers card header shows the
// real product name, then restore it before any async work continues.
// initState already ran (with the flag true → no connection method
// started); mark the mounted OverviewPage element dirty so only its
// build() re-runs with the flag off, picking up the real device name.
screenshotMode = false;
tester.element(find.byType(OverviewPage)).markNeedsBuild();
await tester.pump();
try {
await expectLater(
find.byKey(overviewScreenshotKey),
matchesGoldenFile('../screenshots/$loc/$scene.png'),
);
} finally {
screenshotMode = savedScreenshotMode;
await tester.pump();
}
}
} finally {
screenshotMode = savedScreenshotMode;
core.connection.devices
..clear()
..addAll(savedDevices);
core.connection.hasDevices.value = core.connection.devices.isNotEmpty;
}
}
testGoldens('overview-zwift-click', (WidgetTester tester) async {
await shootOverview(tester, 'overview-zwift-click', zwiftClick);
});
testGoldens('overview-zwift-click-v2', (WidgetTester tester) async {
await shootOverview(tester, 'overview-zwift-click-v2', device);
});
testGoldens('overview-zwift-ride', (WidgetTester tester) async {
await shootOverview(tester, 'overview-zwift-ride', zwiftRide);
});
testGoldens('overview-zwift-play', (WidgetTester tester) async {
await shootOverview(tester, 'overview-zwift-play', zwiftPlay);
});
testGoldens('overview-cycplus-bc2', (WidgetTester tester) async {
await shootOverview(tester, 'overview-cycplus-bc2', cycplusBc2);
});
testGoldens('overview-thinkrider-vs200', (WidgetTester tester) async {
await shootOverview(tester, 'overview-thinkrider-vs200', thinkriderVs200);
});
// --- Virtual-shifting settings widget snapshots (settings video) -------------
// Tight single-widget captures of the virtual-shifting settings controls, each
// rendered standalone inside a keyed RepaintBoundary (English, light) so the
// golden captures ONLY that widget (no page chrome).
// Seed a few NAMED shifting configs for the proxy trainer, with "Climb day"
// active, so the picker and the settings sections show genuine content.
Future<void> seedShiftingConfigs() async {
final key = proxy.trainerKey;
await core.shiftingConfigs.upsert(
ShiftingConfig.defaults(trainerKey: key, name: 'Default', isActive: false),
);
await core.shiftingConfigs.upsert(
ShiftingConfig.defaults(trainerKey: key, name: 'Sprint', isActive: false)
.copyWith(riderWeightKg: 72, bikeWeightKg: 7.5),
);
await core.shiftingConfigs.upsert(
ShiftingConfig.defaults(trainerKey: key, name: 'Climb day', isActive: true)
.copyWith(riderWeightKg: 78, bikeWeightKg: 8.5),
);
}
// 1) The named-config picker (active "Climb day" + New / Manage buttons).
testGoldens('shifting-config-picker', (WidgetTester tester) async {
await seedShiftingConfigs();
const k = ValueKey('shot');
await shootOne(
tester,
'shifting-config-picker',
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20),
child: RepaintBoundary(
key: k,
child: ShiftingConfigPicker(trainerKey: proxy.trainerKey),
),
),
),
),
capture: () => find.byKey(k),
size: const Size(1980, 2390),
);
});
// 2) Ride-feel / trainer settings: the config picker + gear settings card +
// bike-weight + rider-weight steppers.
testGoldens('ride-feel', (WidgetTester tester) async {
await seedShiftingConfigs();
proxy.debugAttachFitnessBike(fbd);
const k = ValueKey('shot');
await shootOne(
tester,
'ride-feel',
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20),
child: RepaintBoundary(
key: k,
child: TrainerSettingsSection(definition: fbd, device: proxy),
),
),
),
),
capture: () => find.byKey(k),
// Wide enough that the embedded config picker's Select shows the active
// config name on one line (it sizes to its Expanded slot, which collapses
// at phone-narrow widths).
size: const Size(1980, 2390),
);
});
// 3) Overlay settings: the enable tile + the display-field toggles (Power /
// Cadence / ERG / Gear / Controls). The field list only renders while the
// overlay is "showing", so flip the platform controller (the same singleton
// the section reads in initState) on up front.
testGoldens('overlay-settings', (WidgetTester tester) async {
proxy.debugAttachFitnessBike(fbd);
// The desktop overlay controller opens a native window via this method
// channel; stub it so show() (used below to expand the field list) doesn't
// throw MissingPluginException in the host test VM.
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('com.coditas.multi_window_native/pluginChannel'),
(call) async => null,
);
await core.settings.setOverlayFields({
OverlayField.power,
OverlayField.cadence,
OverlayField.gearRatio,
});
await TrainerOverlayService.forCurrentPlatform()
.show(fbd, core.settings.getOverlayFields());
const k = ValueKey('shot');
await shootOne(
tester,
'overlay-settings',
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20),
child: RepaintBoundary(
key: k,
child: OverlaySettingsSection(definition: fbd, device: proxy),
),
),
),
),
capture: () => find.byKey(k),
);
});
// 4) The Virtual Shifting mode selector (Target Power / Track Resistance /
// Basic radio group), extracted from GearRatiosEditorPage as a public widget.
testGoldens('vs-mode', (WidgetTester tester) async {
await seedShiftingConfigs();
proxy.debugAttachFitnessBike(fbd);
fbd.setVirtualShiftingMode(VirtualShiftingMode.targetPower);
const k = ValueKey('shot');
await shootOne(
tester,
'vs-mode',
() => BikeControlApp(
customChild: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20),
child: RepaintBoundary(
key: k,
child: VirtualShiftingModeCard(definition: fbd, device: proxy),
),
),
),
),
capture: () => find.byKey(k),
);
});
}