mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-11-29 09:11:17 +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>
66 lines
2.3 KiB
Dart
66 lines
2.3 KiB
Dart
import 'package:bike_control/bluetooth/messages/notification.dart';
|
|
import 'package:bike_control/gen/l10n.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, LucideIcons;
|
|
|
|
void main() {
|
|
setUpAll(() async {
|
|
await AppLocalizations.load(const Locale('en'));
|
|
});
|
|
|
|
group('AlertNotification.connection', () {
|
|
test('names the trainer app and tags the WiFi transport on connect', () {
|
|
final notification = AlertNotification.connection(
|
|
connected: true,
|
|
type: ConnectionMethodType.network,
|
|
appName: 'Zwift',
|
|
);
|
|
|
|
expect(notification.alertMessage, 'Connected to Zwift');
|
|
expect(notification.connectionType, ConnectionMethodType.network);
|
|
expect(notification.level, LogLevel.LOGLEVEL_INFO);
|
|
});
|
|
|
|
test('names the trainer app and tags the Bluetooth transport on disconnect', () {
|
|
final notification = AlertNotification.connection(
|
|
connected: false,
|
|
type: ConnectionMethodType.bluetooth,
|
|
appName: 'Rouvy',
|
|
);
|
|
|
|
expect(notification.alertMessage, 'Disconnected from Rouvy');
|
|
expect(notification.connectionType, ConnectionMethodType.bluetooth);
|
|
});
|
|
|
|
test('falls back to plain copy when the trainer app is unknown', () {
|
|
final connected = AlertNotification.connection(
|
|
connected: true,
|
|
type: ConnectionMethodType.network,
|
|
appName: null,
|
|
);
|
|
final disconnected = AlertNotification.connection(
|
|
connected: false,
|
|
type: ConnectionMethodType.network,
|
|
appName: null,
|
|
);
|
|
|
|
expect(connected.alertMessage, 'Connected');
|
|
expect(disconnected.alertMessage, 'Disconnected');
|
|
// Still tagged with the transport so the activity icon is correct.
|
|
expect(connected.connectionType, ConnectionMethodType.network);
|
|
});
|
|
});
|
|
|
|
group('ConnectionMethodType.activityIcon', () {
|
|
test('network maps to the WiFi icon', () {
|
|
expect(ConnectionMethodType.network.activityIcon, LucideIcons.wifi);
|
|
});
|
|
|
|
test('bluetooth maps to the Bluetooth icon', () {
|
|
expect(ConnectionMethodType.bluetooth.activityIcon, LucideIcons.bluetooth);
|
|
});
|
|
});
|
|
}
|