mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
fix: Improve message signal chip behavior
This commit is contained in:
@@ -10,40 +10,28 @@ void main() {
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
ProfileStorageScope.setScope(
|
||||
profilesEnabled: false,
|
||||
profilesEnabled: true,
|
||||
activeProfileId: ConfigProfile.defaultProfileId,
|
||||
);
|
||||
});
|
||||
|
||||
group('ProfileManager', () {
|
||||
test(
|
||||
'hides the built-in default profile until profiles are enabled',
|
||||
() async {
|
||||
final manager = ProfileManager();
|
||||
test('shows the built-in default profile on a fresh install', () async {
|
||||
final manager = ProfileManager();
|
||||
|
||||
await manager.initialize();
|
||||
await manager.initialize();
|
||||
|
||||
expect(manager.activeProfileId, ConfigProfile.defaultProfileId);
|
||||
expect(manager.visibleProfiles, isEmpty);
|
||||
expect(
|
||||
manager.getProfile(ConfigProfile.defaultProfileId)?.isDefault,
|
||||
isTrue,
|
||||
);
|
||||
expect(ProfileStorageScope.profilesEnabled, isFalse);
|
||||
expect(ProfileStorageScope.effectiveNamespace, isNull);
|
||||
|
||||
await manager.setProfilesEnabled(true);
|
||||
|
||||
expect(manager.visibleProfiles, hasLength(1));
|
||||
expect(
|
||||
manager.visibleProfiles.single.id,
|
||||
ConfigProfile.defaultProfileId,
|
||||
);
|
||||
expect(manager.visibleProfiles.single.name, 'Default');
|
||||
expect(ProfileStorageScope.profilesEnabled, isTrue);
|
||||
expect(ProfileStorageScope.effectiveNamespace, isNull);
|
||||
},
|
||||
);
|
||||
expect(manager.activeProfileId, ConfigProfile.defaultProfileId);
|
||||
expect(manager.visibleProfiles, hasLength(1));
|
||||
expect(
|
||||
manager.getProfile(ConfigProfile.defaultProfileId)?.isDefault,
|
||||
isTrue,
|
||||
);
|
||||
expect(ProfileStorageScope.profilesEnabled, isTrue);
|
||||
expect(ProfileStorageScope.effectiveNamespace, isNull);
|
||||
expect(manager.visibleProfiles.single.name, 'Default');
|
||||
expect(ProfileStorageScope.effectiveNamespace, isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'persists custom profiles and restores scoped active profile state',
|
||||
@@ -118,6 +106,8 @@ void main() {
|
||||
reloaded.profileIdForDevice('pk:device-c'),
|
||||
ConfigProfile.defaultProfileId,
|
||||
);
|
||||
expect(reloaded.hasProfileForDevice('pk:device-a'), isTrue);
|
||||
expect(reloaded.hasProfileForDevice('pk:device-c'), isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -217,6 +217,40 @@ void main() {
|
||||
expect(manager.activeProfileId, alpha.id);
|
||||
expect(connectionProvider.disconnectCallCount, 0);
|
||||
});
|
||||
|
||||
test(
|
||||
'syncActiveProfileForCurrentDevice creates a profile for a new device',
|
||||
() async {
|
||||
final manager = ProfileManager();
|
||||
await manager.initialize();
|
||||
await manager.setProfilesEnabled(true);
|
||||
|
||||
final connectionProvider = _FakeConnectionProvider(
|
||||
deviceInfo: DeviceInfo(
|
||||
deviceId: 'ble-77',
|
||||
deviceName: 'MeshCore-Field Unit',
|
||||
selfName: 'Field Unit',
|
||||
publicKey: Uint8List.fromList([7, 7, 7, 7]),
|
||||
),
|
||||
);
|
||||
final coordinator = _buildCoordinator(
|
||||
profileManager: manager,
|
||||
connectionProvider: connectionProvider,
|
||||
);
|
||||
|
||||
await coordinator.syncActiveProfileForCurrentDevice();
|
||||
|
||||
expect(manager.activeProfileId, isNot(ConfigProfile.defaultProfileId));
|
||||
final profile = manager.getProfile(manager.activeProfileId);
|
||||
expect(profile, isNotNull);
|
||||
expect(profile!.name, 'Device Field Unit');
|
||||
expect(manager.hasProfileForDevice('pk:07070707'), isTrue);
|
||||
expect(
|
||||
manager.profileIdForDevice('pk:07070707'),
|
||||
manager.activeProfileId,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -300,7 +334,6 @@ class _FakeDeviceConfigApplicator extends DeviceConfigApplicator {
|
||||
class _FakeConnectionProvider implements ConnectionProvider {
|
||||
_FakeConnectionProvider({
|
||||
DeviceInfo? deviceInfo,
|
||||
this.connectionMode = ConnectionMode.ble,
|
||||
}) : deviceInfo = deviceInfo ?? DeviceInfo();
|
||||
|
||||
int disconnectCallCount = 0;
|
||||
@@ -309,7 +342,7 @@ class _FakeConnectionProvider implements ConnectionProvider {
|
||||
final DeviceInfo deviceInfo;
|
||||
|
||||
@override
|
||||
final ConnectionMode connectionMode;
|
||||
ConnectionMode get connectionMode => ConnectionMode.ble;
|
||||
|
||||
@override
|
||||
Future<void> disconnect() async {
|
||||
|
||||
Reference in New Issue
Block a user