test(device-entity): add queueCommands and isDisconnected tests (11 cases)
This commit is contained in:
109
packages/sf_shared/test/domain/entities/device_entity_test.dart
Normal file
109
packages/sf_shared/test/domain/entities/device_entity_test.dart
Normal 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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user