diff --git a/test/widget_tests/after_auth_screens/profile/edit_profile_page_test.dart b/test/widget_tests/after_auth_screens/profile/edit_profile_page_test.dart index 6c0312a4c..79826304e 100644 --- a/test/widget_tests/after_auth_screens/profile/edit_profile_page_test.dart +++ b/test/widget_tests/after_auth_screens/profile/edit_profile_page_test.dart @@ -448,22 +448,39 @@ Future main() async { }); // Testing onPressed for firstName - testWidgets("Testing if firstName text field gets focus", (tester) async { + testWidgets("Testing if firstName text field gets focus on onPressed", + (tester) async { userConfig.updateUser( User(firstName: 'Test', lastName: 'Test', email: 'test@test.com'), ); + + // Render the widget await tester.pumpWidget(createEditProfilePage(themeMode: ThemeMode.dark)); await tester.pumpAndSettle(); - await tester.tap(find.byKey(const Key('FirstNameTextField'))); + + // Find the 'First Name' text field and its suffix icon + final firstNameTextField = find.byKey(const Key('FirstNameTextField')); + final editIconButton = find.descendant( + of: firstNameTextField, + matching: find.byIcon(Icons.edit), + ); + + // Ensure the text field and icon exist + expect(firstNameTextField, findsOneWidget); + expect(editIconButton, findsOneWidget); + + // Tap on the edit icon button to trigger focus + await tester.tap(editIconButton); await tester.pumpAndSettle(); - // Verify the focus + // Verify that the lastNameFocus is focused + final focusedElement = + FocusScope.of(tester.element(firstNameTextField)).focusedChild; + expect(focusedElement, isNotNull); // Ensure there is a focused child expect( - FocusScope.of(tester.element(find.byType(EditProfilePage))) - .focusedChild! - .hasPrimaryFocus, - true, - ); + focusedElement!.hasPrimaryFocus, + isTrue, + ); // Ensure it h }); testWidgets("Testing if lastName text field gets focus on onPressed",