-
-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc3fd62
commit e99e8d5
Showing
1 changed file
with
27 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -560,43 +560,40 @@ Future<void> main() async { | |
}); | ||
}); | ||
|
||
testWidgets("Focus shifts to lastNameTextField when edit icon is pressed", | ||
testWidgets("Testing if lastName text field gets focus on onPressed", | ||
(tester) async { | ||
// Arrange: Set up the EditProfilePageViewModel mock with a focus node | ||
final model = EditProfilePageViewModel(); | ||
final lastNameFocusNode = FocusNode(); | ||
model.lastNameFocus = lastNameFocusNode; | ||
// Mock or set up user data | ||
userConfig.updateUser( | ||
User(firstName: 'Test', lastName: 'Test', email: '[email protected]'), | ||
); | ||
|
||
// Render the widget | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: Scaffold( | ||
body: TextFormField( | ||
key: const Key('LastNameTextField'), | ||
focusNode: model.lastNameFocus, | ||
decoration: InputDecoration( | ||
suffixIcon: IconButton( | ||
key: const Key('LastNameEditIcon'), | ||
onPressed: () { | ||
FocusScope.of( | ||
tester | ||
.element(find.byKey(const Key('LastNameTextField'))), | ||
).requestFocus(model.lastNameFocus); | ||
}, | ||
icon: const Icon(Icons.edit), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
await tester.pumpWidget(createEditProfilePage(themeMode: ThemeMode.dark)); | ||
await tester.pumpAndSettle(); | ||
|
||
// Find the 'Last Name' text field and its suffix icon | ||
final lastNameTextField = find.byKey(const Key('LastNameTextField')); | ||
final editIconButton = find.descendant( | ||
of: lastNameTextField, | ||
matching: find.byIcon(Icons.edit), | ||
); | ||
|
||
// Act: Tap the edit icon to trigger the focus request | ||
await tester.tap(find.byKey(const Key('LastNameEditIcon'))); | ||
// Ensure the text field and icon exist | ||
expect(lastNameTextField, findsOneWidget); | ||
expect(editIconButton, findsOneWidget); | ||
|
||
// Tap on the edit icon button to trigger focus | ||
await tester.tap(editIconButton); | ||
await tester.pumpAndSettle(); | ||
|
||
// Assert: Verify the lastNameTextField is focused | ||
expect(lastNameFocusNode.hasFocus, isTrue); | ||
// Verify that the lastNameFocus is focused | ||
final focusedElement = | ||
FocusScope.of(tester.element(lastNameTextField)).focusedChild; | ||
expect(focusedElement, isNotNull); // Ensure there is a focused child | ||
expect( | ||
focusedElement!.hasPrimaryFocus, | ||
isTrue, | ||
); // Ensure it has primary focus | ||
}); | ||
}); | ||
} |