From 81fd00bd979a9d4d5f109b70cef64e8b1f4fdf34 Mon Sep 17 00:00:00 2001 From: Andrea Bizzotto Date: Thu, 26 May 2022 11:48:45 +0100 Subject: [PATCH] Completed auth flow test --- .../authentication/auth_flow_test.dart | 9 ++++++++ .../features/authentication/auth_robot.dart | 23 ++++++++++++++++++- ecommerce_app/test/src/robot.dart | 18 ++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/ecommerce_app/test/src/features/authentication/auth_flow_test.dart b/ecommerce_app/test/src/features/authentication/auth_flow_test.dart index ad256748..2f59fcd0 100644 --- a/ecommerce_app/test/src/features/authentication/auth_flow_test.dart +++ b/ecommerce_app/test/src/features/authentication/auth_flow_test.dart @@ -7,5 +7,14 @@ void main() { final r = Robot(tester); await r.pumpMyApp(); r.expectFindAllProductCards(); + await r.openPopupMenu(); + await r.auth.openEmailPasswordSignInScreen(); + await r.auth.signInWithEmailAndPassword(); + r.expectFindAllProductCards(); + await r.openPopupMenu(); + await r.auth.openAccountScreen(); + await r.auth.tapLogoutButton(); + await r.auth.tapDialogLogoutButton(); + r.expectFindAllProductCards(); }); } diff --git a/ecommerce_app/test/src/features/authentication/auth_robot.dart b/ecommerce_app/test/src/features/authentication/auth_robot.dart index 70af72e9..91ed772a 100644 --- a/ecommerce_app/test/src/features/authentication/auth_robot.dart +++ b/ecommerce_app/test/src/features/authentication/auth_robot.dart @@ -4,6 +4,7 @@ import 'package:ecommerce_app/src/features/authentication/data/fake_auth_reposit import 'package:ecommerce_app/src/features/authentication/presentation/account/account_screen.dart'; import 'package:ecommerce_app/src/features/authentication/presentation/sign_in/email_password_sign_in_screen.dart'; import 'package:ecommerce_app/src/features/authentication/presentation/sign_in/email_password_sign_in_state.dart'; +import 'package:ecommerce_app/src/features/products/presentation/home_app_bar/more_menu_button.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -12,6 +13,13 @@ class AuthRobot { AuthRobot(this.tester); final WidgetTester tester; + Future openEmailPasswordSignInScreen() async { + final finder = find.byKey(MoreMenuButton.signInKey); + expect(finder, findsOneWidget); + await tester.tap(finder); + await tester.pumpAndSettle(); + } + Future pumpEmailPasswordSignInContents({ required FakeAuthRepository authRepository, required EmailPasswordSignInFormType formType, @@ -38,7 +46,7 @@ class AuthRobot { final primaryButton = find.byType(PrimaryButton); expect(primaryButton, findsOneWidget); await tester.tap(primaryButton); - await tester.pump(); + await tester.pumpAndSettle(); } Future enterEmail(String email) async { @@ -53,6 +61,19 @@ class AuthRobot { await tester.enterText(passwordField, password); } + Future signInWithEmailAndPassword() async { + await enterEmail('test@test.com'); + await enterPassword('test1234'); + await tapEmailAndPasswordSubmitButton(); + } + + Future openAccountScreen() async { + final finder = find.byKey(MoreMenuButton.accountKey); + expect(finder, findsOneWidget); + await tester.tap(finder); + await tester.pumpAndSettle(); + } + Future pumpAccountScreen({FakeAuthRepository? authRepository}) async { await tester.pumpWidget( ProviderScope( diff --git a/ecommerce_app/test/src/robot.dart b/ecommerce_app/test/src/robot.dart index 9ad9e600..0cf93729 100644 --- a/ecommerce_app/test/src/robot.dart +++ b/ecommerce_app/test/src/robot.dart @@ -2,13 +2,17 @@ import 'package:ecommerce_app/src/app.dart'; import 'package:ecommerce_app/src/constants/test_products.dart'; import 'package:ecommerce_app/src/features/authentication/data/fake_auth_repository.dart'; import 'package:ecommerce_app/src/features/products/data/fake_products_repository.dart'; +import 'package:ecommerce_app/src/features/products/presentation/home_app_bar/more_menu_button.dart'; import 'package:ecommerce_app/src/features/products/presentation/products_list/product_card.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'features/authentication/auth_robot.dart'; + class Robot { - Robot(this.tester); + Robot(this.tester) : auth = AuthRobot(tester); final WidgetTester tester; + final AuthRobot auth; Future pumpMyApp() async { // Override repositories @@ -30,4 +34,16 @@ class Robot { final finder = find.byType(ProductCard); expect(finder, findsNWidgets(kTestProducts.length)); } + + Future openPopupMenu() async { + final finder = find.byType(MoreMenuButton); + final matches = finder.evaluate(); + // if an item is found, it means that we're running + // on a small window and can tap to reveal the menu + if (matches.isNotEmpty) { + await tester.tap(finder); + await tester.pumpAndSettle(); + } + // else no-op, as the items are already visible + } }