From 631f031daab7d4c1d2efc91f2cde5bace4b7992c Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Tue, 23 Dec 2025 09:10:05 +0100 Subject: [PATCH] unit test adjustments --- lib/utils/actions/base_actions.dart | 4 ++-- test/shimano_di2_test.dart | 37 +++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/lib/utils/actions/base_actions.dart b/lib/utils/actions/base_actions.dart index cefbb29..bf6ccce 100644 --- a/lib/utils/actions/base_actions.dart +++ b/lib/utils/actions/base_actions.dart @@ -176,11 +176,11 @@ abstract class BaseActions { class StubActions extends BaseActions { StubActions({super.supportedModes = const []}); - final List performedActions = []; + final List<(ControllerButton button, bool isDown, bool isUp)> performedActions = []; @override Future performAction(ControllerButton button, {bool isKeyDown = true, bool isKeyUp = false}) async { - performedActions.add(button); + performedActions.add((button, isKeyDown, isKeyUp)); return Future.value(Ignored('${button.name.splitByUpperCase()} clicked')); } } diff --git a/test/shimano_di2_test.dart b/test/shimano_di2_test.dart index 678ff76..1ff1a87 100644 --- a/test/shimano_di2_test.dart +++ b/test/shimano_di2_test.dart @@ -1,11 +1,12 @@ import 'dart:typed_data'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:shared_preferences/shared_preferences.dart'; import 'package:bike_control/bluetooth/devices/shimano/shimano_di2.dart'; import 'package:bike_control/utils/actions/base_actions.dart'; import 'package:bike_control/utils/core.dart'; import 'package:bike_control/utils/keymap/apps/openbikecontrol.dart'; +import 'package:bike_control/utils/keymap/buttons.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'package:universal_ble/universal_ble.dart'; Future main() async { @@ -38,5 +39,37 @@ Future main() async { ); expect(stubActions.performedActions.isEmpty, false); }); + + test('should transmit all events', () async { + final instance = ShimanoDi2(BleDevice(name: 'Di2', deviceId: '')); + await instance.processCharacteristic( + ShimanoDi2Constants.D_FLY_CHANNEL_UUID, + Uint8List.fromList([0x21, 0x13, 0xF0, 0xF0]), + ); + + expect(stubActions.performedActions.isEmpty, true); + + await instance.processCharacteristic( + ShimanoDi2Constants.D_FLY_CHANNEL_UUID, + Uint8List.fromList([0x21, 0x13, 0xF0, 0xF0]), + ); + expect(stubActions.performedActions.isEmpty, true); + + await instance.processCharacteristic( + ShimanoDi2Constants.D_FLY_CHANNEL_UUID, + Uint8List.fromList([0x21, 0x14, 0xF0, 0xF0]), + ); + final button = ControllerButton('D-Fly Channel 1'); + expect(stubActions.performedActions, equals([(button, true, false), (button, false, true)])); + + await instance.processCharacteristic( + ShimanoDi2Constants.D_FLY_CHANNEL_UUID, + Uint8List.fromList([0x21, 0x15, 0xF0, 0xF0]), + ); + expect( + stubActions.performedActions, + equals([(button, true, false), (button, false, true), (button, true, false), (button, false, true)]), + ); + }); }); }