feat: Save profile defaults per device

This commit is contained in:
Janez T
2026-03-18 13:34:50 +01:00
parent 87cb890877
commit 29b75a3155
7 changed files with 257 additions and 26 deletions

View File

@@ -82,5 +82,42 @@ void main() {
expect(reloaded.activeProfileId, profile.id);
},
);
test('stores per-device default profiles independently', () async {
final manager = ProfileManager();
await manager.initialize();
await manager.setProfilesEnabled(true);
final profile = ConfigProfile(
id: 'profile-alpha',
name: 'Alpha',
createdAt: DateTime.parse('2026-03-16T12:00:00Z'),
updatedAt: DateTime.parse('2026-03-16T12:00:00Z'),
sections: const ConfigProfileSections(),
);
await manager.upsertProfile(profile);
await manager.setActiveProfileIdForDevice(
profile.id,
deviceKey: 'pk:device-a',
);
await manager.setActiveProfileIdForDevice(
ConfigProfile.defaultProfileId,
deviceKey: 'pk:device-b',
);
final reloaded = ProfileManager();
await reloaded.initialize();
expect(reloaded.profileIdForDevice('pk:device-a'), profile.id);
expect(
reloaded.profileIdForDevice('pk:device-b'),
ConfigProfile.defaultProfileId,
);
expect(
reloaded.profileIdForDevice('pk:device-c'),
ConfigProfile.defaultProfileId,
);
});
});
}

View File

@@ -184,6 +184,39 @@ void main() {
expect(manager.activeProfileId, target.id);
},
);
test('syncActiveProfileForCurrentDevice uses per-device default', () async {
final manager = ProfileManager();
await manager.initialize();
await manager.setProfilesEnabled(true);
final alpha = ConfigProfile(
id: 'profile-alpha',
name: 'Alpha',
createdAt: DateTime.parse('2026-03-16T12:00:00Z'),
updatedAt: DateTime.parse('2026-03-16T12:00:00Z'),
sections: const ConfigProfileSections(),
);
await manager.upsertProfile(alpha);
await manager.setActiveProfileIdForDevice(
alpha.id,
deviceKey: 'pk:01020304',
);
await manager.setActiveProfileId(ConfigProfile.defaultProfileId);
final connectionProvider = _FakeConnectionProvider(
deviceInfo: DeviceInfo(publicKey: Uint8List.fromList([1, 2, 3, 4])),
);
final coordinator = _buildCoordinator(
profileManager: manager,
connectionProvider: connectionProvider,
);
await coordinator.syncActiveProfileForCurrentDevice();
expect(manager.activeProfileId, alpha.id);
expect(connectionProvider.disconnectCallCount, 0);
});
});
}
@@ -265,10 +298,18 @@ class _FakeDeviceConfigApplicator extends DeviceConfigApplicator {
}
class _FakeConnectionProvider implements ConnectionProvider {
_FakeConnectionProvider({
DeviceInfo? deviceInfo,
this.connectionMode = ConnectionMode.ble,
}) : deviceInfo = deviceInfo ?? DeviceInfo();
int disconnectCallCount = 0;
@override
DeviceInfo get deviceInfo => DeviceInfo();
final DeviceInfo deviceInfo;
@override
final ConnectionMode connectionMode;
@override
Future<void> disconnect() async {