From d8621f456b3b8c108f309635f6adffa200469680 Mon Sep 17 00:00:00 2001 From: TheTexanCodeur <92913266+TheTexanCodeur@users.noreply.github.com> Date: Wed, 29 May 2024 11:27:07 +0200 Subject: [PATCH] test(map-errors-fix): add regression tests --- test/views/pages/map/dynamic_map_test.dart | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/test/views/pages/map/dynamic_map_test.dart b/test/views/pages/map/dynamic_map_test.dart index 3d03a9d0..a245da53 100644 --- a/test/views/pages/map/dynamic_map_test.dart +++ b/test/views/pages/map/dynamic_map_test.dart @@ -479,4 +479,89 @@ void main() { verifyResult: null, ); }); + + group("location errors", () { + testWidgets("one error pop up occurs", (tester) async { + //make the location services fail + + when(geoLocationService.checkLocationServices()).thenAnswer( + (_) => Future.value(Exception("Location services not enabled")), + ); + + await beginTest(tester); + + //find an dialog with the error message + final errorPopUp = find.byType(Dialog); + + expect(errorPopUp, findsExactly(1)); + + //find the error message + final errorText = find.text("Exception: Location services not enabled"); + expect(errorText, findsOneWidget); + }); + + testWidgets("no error with user posts", (tester) async { + await beginTest(tester); + + //disable the location services + when(geoLocationService.checkLocationServices()).thenAnswer( + (_) => Future.value(Exception("Location services not enabled")), + ); + + //click on user posts tab + final chip = find.byKey( + MapSelectionOptionChips.optionChipKeys[MapSelectionOptions.myPosts]!, + ); + expect(chip, findsOneWidget); + await tester.tap(chip); + await tester.pumpAndSettle(); + + //no error dialog should appear + final errorPopUp = find.byType(Dialog); + expect(errorPopUp, findsNothing); + }); + + testWidgets("no errors when location services are re-enabled", + (tester) async { + //disable the location services + when(geoLocationService.checkLocationServices()).thenAnswer( + (_) => Future.value(Exception("Location services not enabled")), + ); + + await beginTest(tester); + + //expect an error dialog + final errorPopUp = find.byType(Dialog); + expect(errorPopUp, findsExactly(1)); + + //make the Dialog disappear by tapping next to it + await tester.tapAt(const Offset(0, 0)); // Top-left corner of the screen + await tester.pumpAndSettle(); + + //click on the user posts tab + final chip = find.byKey( + MapSelectionOptionChips.optionChipKeys[MapSelectionOptions.myPosts]!, + ); + expect(chip, findsOneWidget); + await tester.tap(chip); + await tester.pumpAndSettle(); + + //re-enable the location services + when(geoLocationService.checkLocationServices()).thenAnswer( + (_) => Future.value(null), + ); + + //click on the nearby posts tab + final nearbyChip = find.byKey( + MapSelectionOptionChips.optionChipKeys[MapSelectionOptions.nearby]!, + ); + expect(nearbyChip, findsOneWidget); + await tester.tap(nearbyChip); + await tester.pumpAndSettle(); + + //expect no error dialog + final errorPopUpAfter = find.byType(Dialog); + expect(errorPopUpAfter, findsNothing); + }); + }); }