diff --git a/integration_test/e2e_test.dart b/integration_test/e2e_test.dart index 7d1c599..8b36491 100644 --- a/integration_test/e2e_test.dart +++ b/integration_test/e2e_test.dart @@ -153,8 +153,6 @@ void testE2E(String description) { /// Delete profile await tester.openSettings(); await tester.tapDescendantTextOf(S.current.equipmentProfiles); - await tester.tap(find.text(mockEquipmentProfiles[0].name).first); - await tester.pumpAndSettle(); await tester.tap(find.byIcon(Icons.edit).first); await tester.pumpAndSettle(); await tester.deleteEdits(); diff --git a/test/providers/equipment_profile_provider_test.dart b/test/providers/equipment_profile_provider_test.dart index a44c81b..908833f 100644 --- a/test/providers/equipment_profile_provider_test.dart +++ b/test/providers/equipment_profile_provider_test.dart @@ -22,6 +22,7 @@ void main() { () => storageService.updateProfile( id: any(named: 'id'), name: any(named: 'name'), + isUsed: any(named: 'isUsed'), ), ).thenAnswer((_) async {}); when(() => storageService.deleteProfile(any())).thenAnswer((_) async {}); @@ -55,6 +56,10 @@ void main() { expect(find.text(_EquipmentProfilesCount.text(count)), findsOneWidget); } + void expectEquipmentProfilesInUseCount(int count) { + expect(find.text(_EquipmentProfilesInUseCount.text(count)), findsOneWidget); + } + void expectSelectedEquipmentProfileName(String name) { expect(find.text(_SelectedEquipmentProfile.text(name)), findsOneWidget); } @@ -96,6 +101,26 @@ void main() { }, ); + testWidgets( + 'toggleProfile', + (tester) async { + when(() => storageService.selectedEquipmentProfileId).thenReturn(_customProfiles.first.id); + await pumpTestWidget(tester, IAPProductStatus.purchased); + expectEquipmentProfilesCount(_customProfiles.length + 1); + expectEquipmentProfilesInUseCount(_customProfiles.length + 1); + expectSelectedEquipmentProfileName(_customProfiles.first.name); + + await tester.equipmentProfilesProvider.toggleProfile(_customProfiles.first, false); + await tester.pump(); + expectEquipmentProfilesCount(_customProfiles.length + 1); + expectEquipmentProfilesInUseCount(_customProfiles.length + 1 - 1); + expectSelectedEquipmentProfileName(''); + + verify(() => storageService.updateProfile(id: _customProfiles.first.id, isUsed: false)).called(1); + verify(() => storageService.selectedEquipmentProfileId = '').called(1); + }, + ); + testWidgets( 'EquipmentProfilesProvider CRUD', (tester) async { @@ -167,6 +192,7 @@ class _Application extends StatelessWidget { child: Column( children: [ _EquipmentProfilesCount(), + _EquipmentProfilesInUseCount(), _SelectedEquipmentProfile(), ], ), @@ -187,6 +213,17 @@ class _EquipmentProfilesCount extends StatelessWidget { } } +class _EquipmentProfilesInUseCount extends StatelessWidget { + static String text(int count) => "Profiles in use count: $count"; + + const _EquipmentProfilesInUseCount(); + + @override + Widget build(BuildContext context) { + return Text(text(EquipmentProfiles.inUseOf(context).length)); + } +} + class _SelectedEquipmentProfile extends StatelessWidget { static String text(String name) => "Selected profile: $name}"; diff --git a/test/screens/metering/components/shared/readings_container/equipment_profile_picker_test.dart b/test/screens/metering/components/shared/readings_container/equipment_profile_picker_test.dart index 7ee1081..6576273 100644 --- a/test/screens/metering/components/shared/readings_container/equipment_profile_picker_test.dart +++ b/test/screens/metering/components/shared/readings_container/equipment_profile_picker_test.dart @@ -79,6 +79,18 @@ void main() { ); }, ); + + testWidgets( + 'Equipment profile picker shows only profiles in use', + (tester) async { + when(() => storageService.getProfiles()) + .thenAnswer((_) async => _mockEquipmentProfiles.skip(1).toList().toSelectableMap()); + await pumpApplication(tester); + await tester.openAnimatedPicker(); + expectRadioListTile(S.current.none, isSelected: true); + expectRadioListTile(_mockEquipmentProfiles[1].name); + }, + ); } final _mockEquipmentProfiles = [