mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-12-04 12:42:18 +01:00
Feature 1 — In-app language switcher: - Settings gains a persisted `locale_override` pref plus a `localeListenable` ValueNotifier, initialised in init() and updated by setLocaleOverride(). - The root ShadcnApp is wrapped in a ValueListenableBuilder on that notifier so switching languages rebuilds the whole app immediately; normal (non-demo, non-screenshot) path now honours the user override, defaulting to the OS language when unset. - A prominent Language row (shadcn Select over "System default" + each locale by its native endonym) is added to the top of the connection-settings page. - New l10n keys `language` and `languageSystemDefault` across en/de/es/it/fr/pl. Feature 2 — Suppress redundant connection toasts: - Extract the toast-show decision into a pure, testable shouldShowConnectionAlertToast() and suppress connection-type alerts when the connection card is already on screen; the activity-log entry is still always inserted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
1.9 KiB
Dart
52 lines
1.9 KiB
Dart
// Widget test for the in-app language switcher (LanguageSelect). Opens the
|
|
// Select and picks a non-system locale, asserting the override is persisted.
|
|
import 'package:bike_control/gen/l10n.dart';
|
|
import 'package:bike_control/main.dart' show OtherLocalizationsDelegate;
|
|
import 'package:bike_control/pages/trainer_connection_settings.dart';
|
|
import 'package:bike_control/utils/core.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.settings.prefs = await SharedPreferences.getInstance();
|
|
});
|
|
|
|
Widget harness() => ShadcnApp(
|
|
debugShowCheckedModeBanner: false,
|
|
localizationsDelegates: [
|
|
...ShadcnLocalizations.localizationsDelegates,
|
|
const OtherLocalizationsDelegate(),
|
|
AppLocalizations.delegate,
|
|
],
|
|
supportedLocales: AppLocalizations.delegate.supportedLocales,
|
|
theme: ThemeData(colorScheme: ColorSchemes.lightSlate, radius: 0.7),
|
|
home: Scaffold(
|
|
child: LanguageSelect(onChanged: () {}),
|
|
),
|
|
);
|
|
|
|
testWidgets('choosing a language persists the override', (tester) async {
|
|
await tester.pumpWidget(harness());
|
|
await tester.pumpAndSettle();
|
|
|
|
// Starts on system default (no override).
|
|
expect(core.settings.getLocaleOverride(), isNull);
|
|
|
|
// Open the language Select popup.
|
|
await tester.tap(find.byType(Select<String>));
|
|
await tester.pumpAndSettle();
|
|
|
|
// Pick German by its native name (endonym).
|
|
await tester.tap(find.text('Deutsch').last);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(core.settings.getLocaleOverride(), 'de');
|
|
expect(core.settings.localeListenable.value, const Locale('de'));
|
|
});
|
|
}
|