fix: Improve message signal chip behavior

This commit is contained in:
Janez T
2026-03-18 14:29:33 +01:00
parent 67d8e1c906
commit 140088fe2f
12 changed files with 1162 additions and 634 deletions

View File

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

View File

@@ -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 {