Files
swiftcontrol/test/widgets/unlock_toggle_setup_again_test.dart
Jonas Bark 67e405e6ad fix: name the Click V2 unlock mode, and say where unlocking happens
The card showed only "Entsperrmodus" and "Erneut einrichten", so it looked
identical whichever mode was set and coming back from the explainer read as
if the choice had done nothing. Name the mode that is actually set, modelled
as the three states the setup can rest in — unlock-with-Zwift, right-side-
only, and the legacy restart loop — resolved in one place so both pucks name
the same mode the same way.

The missing unlock option was real, too. unlockWarnings — which carries
"Jetzt freischalten" — is rendered only by the left puck and the legacy
unified controller, and returns nothing without a connection; the right puck
never carried it, correctly, since the left one is what Zwift locks. So in
Zwift mode with the left puck off, asleep or not yet rediscovered, the action
existed nowhere and the card sat silent. Point at the left controller in that
case instead. When it is connected nothing changes: the left card shows the
real unlock UI and the right card stays quiet.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-13 08:37:18 +02:00

118 lines
4.7 KiB
Dart

import 'package:bike_control/gen/l10n.dart';
import 'package:bike_control/pages/click_v2_onboarding.dart';
import 'package:bike_control/utils/actions/base_actions.dart';
import 'package:bike_control/utils/core.dart';
import 'package:bike_control/widgets/unlock_toggle.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() async {
SharedPreferences.setMockInitialValues({});
core.actionHandler = StubActions();
core.settings.prefs = await SharedPreferences.getInstance();
await AppLocalizations.load(const Locale('en'));
});
testWidgets('offers a way back into the onboarding explainer', (tester) async {
// "Set up again" below navigates into ClickV2OnboardingPage, whose hero
// badges loop for as long as it's visible (see ClickContours) — this
// test exercises the navigation, not that loop, so animations are
// disabled to keep pumpAndSettle deterministic instead of waiting out a
// Ticker that never stops on its own.
tester.platformDispatcher.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures(disableAnimations: true);
await tester.pumpWidget(
ShadcnApp(
localizationsDelegates: const [AppLocalizations.delegate],
supportedLocales: const [Locale('en')],
home: Scaffold(child: const UnlockToggle(children: [])),
),
);
await tester.pumpAndSettle();
expect(find.text('Set up again'), findsOneWidget);
await tester.tap(find.text('Set up again'));
await tester.pumpAndSettle();
expect(find.byType(ClickV2OnboardingPage), findsOneWidget);
});
// The explainer is the only place the unlock mode is chosen — a dropdown
// beside it could set the setting without doing the work each mode needs.
testWidgets('offers no unlock-mode picker of its own', (tester) async {
tester.platformDispatcher.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures(disableAnimations: true);
await tester.pumpWidget(
ShadcnApp(
localizationsDelegates: const [AppLocalizations.delegate],
supportedLocales: const [Locale('en')],
home: Scaffold(child: const UnlockToggle(children: [])),
),
);
await tester.pumpAndSettle();
expect(find.byType(Select<bool>), findsNothing);
});
// Without this the card looked identical whichever mode was set, so coming
// back from the explainer read as if the choice had done nothing.
group('names the mode that is actually set', () {
Future<void> pump(WidgetTester tester) async {
tester.platformDispatcher.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures(
disableAnimations: true,
);
await tester.pumpWidget(
ShadcnApp(
localizationsDelegates: const [AppLocalizations.delegate],
supportedLocales: const [Locale('en')],
home: Scaffold(child: const UnlockToggle(children: [])),
),
);
await tester.pumpAndSettle();
}
testWidgets('unlock with Zwift', (tester) async {
await core.settings.setUnlockWithZwift(true);
await pump(tester);
expect(find.text(AppLocalizations.current.unlock_modeZwift), findsOneWidget);
});
testWidgets('right side only', (tester) async {
await core.settings.setClickV2RightSideOnly(true);
await pump(tester);
expect(find.text(AppLocalizations.current.clickV2Onboarding_rightOnlyTitle), findsOneWidget);
});
testWidgets('the legacy restart loop is the fallback', (tester) async {
await pump(tester);
expect(find.text(AppLocalizations.current.unlock_modeRestart), findsOneWidget);
});
});
// The "unlock now" action lives on the left puck and needs it connected, so
// in Zwift mode without one there is nothing to show — say where unlocking
// happens rather than leaving the card looking like the mode did nothing.
testWidgets('points at the left puck when Zwift mode has none connected', (tester) async {
await core.settings.setUnlockWithZwift(true);
tester.platformDispatcher.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures(
disableAnimations: true,
);
await tester.pumpWidget(
ShadcnApp(
localizationsDelegates: const [AppLocalizations.delegate],
supportedLocales: const [Locale('en')],
home: Scaffold(
child: UnlockToggle(children: [Text('unlock action')]),
),
),
);
await tester.pumpAndSettle();
expect(find.text(AppLocalizations.current.unlock_zwiftNeedsLeftSide), findsOneWidget);
expect(find.text('unlock action'), findsNothing);
});
}