fixed tests

This commit is contained in:
Vadim 2024-11-11 14:06:16 +01:00
parent efd3dc2586
commit 4e6f9dff17
3 changed files with 49 additions and 2 deletions

View file

@ -153,8 +153,6 @@ void testE2E(String description) {
/// Delete profile
await tester.openSettings();
await tester.tapDescendantTextOf<SettingsScreen>(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();

View file

@ -22,6 +22,7 @@ void main() {
() => storageService.updateProfile(
id: any<String>(named: 'id'),
name: any<String>(named: 'name'),
isUsed: any<bool>(named: 'isUsed'),
),
).thenAnswer((_) async {});
when(() => storageService.deleteProfile(any<String>())).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}";

View file

@ -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<EquipmentProfilePicker>();
expectRadioListTile<EquipmentProfile>(S.current.none, isSelected: true);
expectRadioListTile<EquipmentProfile>(_mockEquipmentProfiles[1].name);
},
);
}
final _mockEquipmentProfiles = [