test(device-entity): add queueCommands and isDisconnected tests (11 cases)

This commit is contained in:
2026-04-26 08:29:17 +02:00
parent cf6a9dd6df
commit 41f1797dcf

View File

@@ -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);
});
});
}