mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-12-04 20:52:23 +01:00
The "connected"/"disconnected" activity alerts fired when a trainer app
attaches to one of our emulators now name the app ("Connected to Zwift",
"Disconnected from Zwift") and tag the alert with the transport, so the
activity log shows a WiFi or Bluetooth icon depending on how the app is
connected instead of always Bluetooth.
- AlertNotification gains a connectionType field + a connection() factory
that builds the localized, app-named message and tags the transport.
- All 6 emulator call sites (Zwift BLE, FTMS/Rouvy mDNS) route through it,
passing their own type and core.settings.getTrainerApp()?.name.
- ConnectionMethodType.activityIcon maps network -> wifi, else -> bluetooth;
overview threads connectionType through and uses it for the leading icon.
- Reuse existing connectedTo string; add disconnectedFrom (en/de/es/fr/it/pl).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
64 lines
2.3 KiB
Dart
64 lines
2.3 KiB
Dart
import 'package:bike_control/bluetooth/devices/zwift/rouvy_mdns_emulator.dart';
|
|
import 'package:bike_control/bluetooth/messages/notification.dart';
|
|
import 'package:bike_control/gen/l10n.dart';
|
|
import 'package:bike_control/utils/core.dart';
|
|
import 'package:bike_control/widgets/ui/connection_method.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:prop/prop.dart';
|
|
import 'package:shadcn_flutter/shadcn_flutter.dart' show Locale;
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
void main() {
|
|
setUpAll(() async {
|
|
await AppLocalizations.load(const Locale('en'));
|
|
});
|
|
|
|
setUp(() async {
|
|
SharedPreferences.setMockInitialValues({'trainer_app': 'Zwift'});
|
|
core.settings.prefs = await SharedPreferences.getInstance();
|
|
});
|
|
|
|
group('RouvyMdnsEmulator connection alerts', () {
|
|
test('signals "Connected to <app>" tagged with the WiFi transport on connect', () async {
|
|
final click = ClickEmulator();
|
|
final emulator = RouvyMdnsEmulator(clickEmulator: click);
|
|
addTearDown(emulator.stop);
|
|
|
|
final alerts = <AlertNotification>[];
|
|
final sub = core.connection.actionStream
|
|
.where((n) => n is AlertNotification)
|
|
.cast<AlertNotification>()
|
|
.listen(alerts.add);
|
|
addTearDown(sub.cancel);
|
|
|
|
click.isConnected.value = true;
|
|
await pumpEventQueue();
|
|
|
|
expect(alerts, isNotEmpty);
|
|
expect(alerts.last.alertMessage, 'Connected to Zwift');
|
|
expect(alerts.last.connectionType, ConnectionMethodType.network);
|
|
});
|
|
|
|
test('signals "Disconnected from <app>" tagged with the WiFi transport on disconnect', () async {
|
|
final click = ClickEmulator();
|
|
final emulator = RouvyMdnsEmulator(clickEmulator: click);
|
|
addTearDown(emulator.stop);
|
|
|
|
final alerts = <AlertNotification>[];
|
|
final sub = core.connection.actionStream
|
|
.where((n) => n is AlertNotification)
|
|
.cast<AlertNotification>()
|
|
.listen(alerts.add);
|
|
addTearDown(sub.cancel);
|
|
|
|
click.isConnected.value = true;
|
|
await pumpEventQueue();
|
|
click.isConnected.value = false;
|
|
await pumpEventQueue();
|
|
|
|
expect(alerts.last.alertMessage, 'Disconnected from Zwift');
|
|
expect(alerts.last.connectionType, ConnectionMethodType.network);
|
|
});
|
|
});
|
|
}
|