forked from andrew/SIAB-Scale
59 lines
1.8 KiB
Dart
59 lines
1.8 KiB
Dart
// This is a basic Flutter widget test.
|
|
//
|
|
// To perform an interaction with a widget in your test, use the WidgetTester
|
|
// utility in the flutter_test package. For example, you can send tap and scroll
|
|
// gestures. You can also use WidgetTester to find child widgets in the widget
|
|
// tree, read text, and verify that the values of widget properties are correct.
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:siab_bluetooth_app/models/registered_device.dart';
|
|
import 'package:siab_bluetooth_app/services/ble_service.dart';
|
|
|
|
void main() {
|
|
group('RegisteredDevice Model Tests', () {
|
|
test('toMap and fromMap serialization', () {
|
|
final device = RegisteredDevice(
|
|
id: 1,
|
|
uuid: '00:11:22:33:44:55',
|
|
label: 'Scale Alpha',
|
|
);
|
|
|
|
final map = device.toMap();
|
|
expect(map['id'], 1);
|
|
expect(map['uuid'], '00:11:22:33:44:55');
|
|
expect(map['label'], 'Scale Alpha');
|
|
|
|
final from = RegisteredDevice.fromMap(map);
|
|
expect(from.id, 1);
|
|
expect(from.uuid, '00:11:22:33:44:55');
|
|
expect(from.label, 'Scale Alpha');
|
|
});
|
|
|
|
test('copyWith works correctly', () {
|
|
final device = RegisteredDevice(
|
|
id: 1,
|
|
uuid: '00:11:22:33:44:55',
|
|
label: 'Scale Alpha',
|
|
);
|
|
|
|
final updated = device.copyWith(label: 'Scale Beta');
|
|
expect(updated.id, 1);
|
|
expect(updated.uuid, '00:11:22:33:44:55');
|
|
expect(updated.label, 'Scale Beta');
|
|
});
|
|
});
|
|
|
|
group('DataPacket Tests', () {
|
|
test('parses weight correctly from byte 3 (index 2)', () {
|
|
final packet = DataPacket(
|
|
data: [0xAA, 0xBB, 125, 0xDD],
|
|
timestamp: DateTime.now(),
|
|
packetNumber: 1,
|
|
);
|
|
|
|
expect(packet.weightKg, 12.5);
|
|
expect(packet.hexString, 'aabb7ddd');
|
|
});
|
|
});
|
|
}
|