import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:cashumit/services/bluetooth_service.dart'; import 'package:shared_preferences/shared_preferences.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); group('BluetoothService Tests', () { late BluetoothService bluetoothService; setUp(() { SharedPreferences.setMockInitialValues({}); TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( const MethodChannel('bluetooth_print/methods'), (MethodCall methodCall) async { switch (methodCall.method) { case 'state': return 12; // STATE_ON case 'startScan': return null; case 'stopScan': return null; case 'isConnected': return false; default: return null; } }, ); bluetoothService = BluetoothService(); }); tearDown(() { TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( const MethodChannel('bluetooth_print/methods'), null, ); }); test('initial values and getters work properly', () { expect(bluetoothService.isConnected, false); expect(bluetoothService.isPrinting, false); expect(bluetoothService.connectedDevice, isNull); expect(bluetoothService.isScanningNow, false); }); test('stopScan executes gracefully', () async { await bluetoothService.stopScan(); expect(bluetoothService.isScanningNow, false); }); test('reconnectIfNeeded returns false when no saved device', () async { final result = await bluetoothService.reconnectIfNeeded(); expect(result, false); }); }); }