From 41f1797dcf23177c0571adc2e5244d87ba2d6340 Mon Sep 17 00:00:00 2001 From: JulianAlcala Date: Sun, 26 Apr 2026 08:29:17 +0200 Subject: [PATCH] test(device-entity): add queueCommands and isDisconnected tests (11 cases) --- .../domain/entities/device_entity_test.dart | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 packages/sf_shared/test/domain/entities/device_entity_test.dart diff --git a/packages/sf_shared/test/domain/entities/device_entity_test.dart b/packages/sf_shared/test/domain/entities/device_entity_test.dart new file mode 100644 index 00000000..2c19146a --- /dev/null +++ b/packages/sf_shared/test/domain/entities/device_entity_test.dart @@ -0,0 +1,109 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:sf_shared/src/domain/entities/device_entity.dart'; + +void main() { + group('DeviceEntity.queueCommands', () { + test('defaults to false', () { + final device = DeviceEntity(id: '1', identificator: 'dev-1'); + expect(device.queueCommands, isFalse); + }); + + test('can be set to true', () { + final device = DeviceEntity( + id: '1', + identificator: 'dev-1', + queueCommands: true, + ); + expect(device.queueCommands, isTrue); + }); + + test('can be set to false explicitly', () { + final device = DeviceEntity( + id: '1', + identificator: 'dev-1', + queueCommands: false, + ); + expect(device.queueCommands, isFalse); + }); + }); + + group('DeviceEntityFlags.isDisconnected', () { + test('returns true when flags contain isDisconnect as true', () { + final device = DeviceEntity( + id: '1', + identificator: 'dev-1', + flags: {'isDisconnect': true}, + ); + expect(device.isDisconnected, isTrue); + }); + + test('returns false when flags contain isDisconnect as false', () { + final device = DeviceEntity( + id: '1', + identificator: 'dev-1', + flags: {'isDisconnect': false}, + ); + expect(device.isDisconnected, isFalse); + }); + + test('returns false when flags do not contain isDisconnect', () { + final device = DeviceEntity( + id: '1', + identificator: 'dev-1', + flags: {'someOtherFlag': true}, + ); + expect(device.isDisconnected, isFalse); + }); + + test('returns false when flags are empty', () { + final device = DeviceEntity(id: '1', identificator: 'dev-1'); + expect(device.isDisconnected, isFalse); + }); + }); + + group('guardDeviceCommand logic (unit-level)', () { + test('queueCommands true and disconnected allows command', () { + final device = DeviceEntity( + id: '1', + identificator: 'dev-1', + queueCommands: true, + flags: {'isDisconnect': true}, + ); + final shouldBlock = !device.queueCommands && device.isDisconnected; + expect(shouldBlock, isFalse); + }); + + test('queueCommands false and disconnected blocks command', () { + final device = DeviceEntity( + id: '1', + identificator: 'dev-1', + queueCommands: false, + flags: {'isDisconnect': true}, + ); + final shouldBlock = !device.queueCommands && device.isDisconnected; + expect(shouldBlock, isTrue); + }); + + test('queueCommands false and connected allows command', () { + final device = DeviceEntity( + id: '1', + identificator: 'dev-1', + queueCommands: false, + flags: {'isDisconnect': false}, + ); + final shouldBlock = !device.queueCommands && device.isDisconnected; + expect(shouldBlock, isFalse); + }); + + test('queueCommands true and connected allows command', () { + final device = DeviceEntity( + id: '1', + identificator: 'dev-1', + queueCommands: true, + flags: {'isDisconnect': false}, + ); + final shouldBlock = !device.queueCommands && device.isDisconnected; + expect(shouldBlock, isFalse); + }); + }); +}