unit test adjustments

This commit is contained in:
Jonas Bark
2025-12-23 09:10:05 +01:00
parent a487539e6a
commit 631f031daa
2 changed files with 37 additions and 4 deletions

View File

@@ -176,11 +176,11 @@ abstract class BaseActions {
class StubActions extends BaseActions {
StubActions({super.supportedModes = const []});
final List<ControllerButton> performedActions = [];
final List<(ControllerButton button, bool isDown, bool isUp)> performedActions = [];
@override
Future<ActionResult> 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'));
}
}

View File

@@ -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<void> main() async {
@@ -38,5 +39,37 @@ Future<void> 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)]),
);
});
});
}