feat: basic trainer support
This commit is contained in:
65
test/service/shifter_settings_test.dart
Normal file
65
test/service/shifter_settings_test.dart
Normal file
@ -0,0 +1,65 @@
|
||||
import 'dart:convert';
|
||||
import 'package:abawo_bt_app/model/shifter_types.dart';
|
||||
import 'package:abawo_bt_app/model/simulation.dart';
|
||||
import 'package:abawo_bt_app/service/shifter_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../support/settings_bluetooth.dart';
|
||||
|
||||
void main() {
|
||||
late SettingsBluetooth bluetooth;
|
||||
late ShifterService service;
|
||||
setUp(() {
|
||||
bluetooth = SettingsBluetooth();
|
||||
service = ShifterService(bluetooth: bluetooth, buttonDeviceId: 'test');
|
||||
});
|
||||
tearDown(() async {
|
||||
await service.dispose();
|
||||
await bluetooth.close();
|
||||
});
|
||||
|
||||
test('selection is confirmed before address and connection command',
|
||||
() async {
|
||||
final result = await service.connectButtonToTrainer(
|
||||
const TrainerAddress(flags: 0, bytes: [1, 2, 3, 4, 5, 6]),
|
||||
protocol: 'yesoul');
|
||||
expect(result.isOk(), isTrue);
|
||||
expect(bluetooth.steps, [
|
||||
'write:$trainerProtocolCharacteristicUuid',
|
||||
'read:$trainerProtocolCharacteristicUuid',
|
||||
'write:$universalShifterConnectToAddrCharacteristicUuid',
|
||||
'write:$universalShifterCommandCharacteristicUuid'
|
||||
]);
|
||||
});
|
||||
test('rejected protocol does not connect or write address', () async {
|
||||
bluetooth.rejectWrites = true;
|
||||
final result = await service.connectButtonToTrainer(
|
||||
const TrainerAddress(flags: 0, bytes: [1, 2, 3, 4, 5, 6]),
|
||||
protocol: 'yesoul');
|
||||
expect(result.isErr(), isTrue);
|
||||
expect(bluetooth.steps.length, 2);
|
||||
expect(utf8.decode(bluetooth.values[trainerProtocolCharacteristicUuid]!),
|
||||
'auto');
|
||||
});
|
||||
test('legacy connection does not require optional protocol characteristic',
|
||||
() async {
|
||||
bluetooth.values.remove(trainerProtocolCharacteristicUuid);
|
||||
final result = await service.connectButtonToTrainer(
|
||||
const TrainerAddress(flags: 0, bytes: [1, 2, 3, 4, 5, 6]));
|
||||
expect(result.isOk(), isTrue);
|
||||
expect(bluetooth.steps.length, 2);
|
||||
});
|
||||
test('simulation saves require matching read-back', () async {
|
||||
const config =
|
||||
SimulationConfig(policy: SimulationPolicy.force, riderWeight: 80.25);
|
||||
expect((await service.writeSimulationConfig(config)).isOk(), isTrue);
|
||||
expect((await service.readSimulationConfig()).unwrap().riderWeight, 80.25);
|
||||
bluetooth.rejectWrites = true;
|
||||
expect(
|
||||
(await service.writeSimulationConfig(const SimulationConfig())).isErr(),
|
||||
isTrue);
|
||||
});
|
||||
test('malformed configuration is a recoverable read error', () async {
|
||||
bluetooth.values[simulationConfigCharacteristicUuid] = [1];
|
||||
expect((await service.readSimulationConfig()).isErr(), isTrue);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user