Last active
May 14, 2022 22:12
-
-
Save ndungudedan/054124f3e1c2c28b33d95f9422f7d747 to your computer and use it in GitHub Desktop.
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
void main() { | |
group('Home widget Test -', () { | |
testWidgets("Testing home Widgets", (tester) async { | |
//we call our helper function to return a materal app. | |
await tester.pumpWidget(createHomeScreen()); | |
//We find a widget of type of TextFormField and according to our | |
//UI we expect to have 2 of that type. | |
//If less or more are found, the test fails | |
expect(find.byType(TextFormField), findsNWidgets(2)); | |
expect(find.byType(TextButton), findsOneWidget); | |
expect(find.byType(IconButton), findsOneWidget); | |
expect(find.byType(Form), findsOneWidget); | |
expect(find.byIcon(Icons.favorite_border_outlined), findsOneWidget); | |
}); | |
testWidgets('Testing Navigation To Favorites Page', (tester) async { | |
await tester.pumpWidget(createHomeScreen()); | |
//we tell the tester to tap the icon button it finds | |
await tester.tap(find.byType(IconButton)); | |
//so that the state of the app can be updated | |
await tester.pumpAndSettle(); | |
//we confirm that our screen navigated to the expected onr | |
expect(find.byType(FavoritesPage), findsOneWidget); | |
}); | |
}); | |
group('Home Add Note Tests', () { | |
testWidgets("Empty Inputs on Text Fields", (tester) async { | |
await tester.pumpWidget(createHomeScreen()); | |
await tester.tap(find.byType(TextButton)); | |
await tester.pumpAndSettle(const Duration(seconds: 2)); | |
expect( | |
find.descendant( | |
of: find.byType(TextFormField).at(0), | |
matching: find.text('Please Enter a Title')), | |
findsOneWidget); | |
expect( | |
find.descendant( | |
of: find.byType(TextFormField).at(1), | |
matching: find.text('Please Enter a Description')), | |
findsOneWidget); | |
}); | |
testWidgets("Check Space Input On Text Fields", (tester) async { | |
await tester.pumpWidget(createHomeScreen()); | |
//we find all text inputs and select the first and second | |
//then we instruct the tester to input blank space into the field | |
await tester.enterText(find.byType(TextFormField).at(0), ' '); | |
await tester.enterText(find.byType(TextFormField).at(1), ' '); | |
await tester.tap(find.byType(TextButton)); | |
await tester.pumpAndSettle(); | |
expect(find.text('Please Fill All Details'), findsOneWidget); | |
}); | |
testWidgets("Check On Adding Note", (tester) async { | |
await tester.pumpWidget(createHomeScreen()); | |
//we find all text inputs and select the first and second | |
//we input text into the fields | |
await tester.enterText( | |
find.byType(TextFormField).at(0), 'GoodMorning Buddy'); | |
await tester.enterText(find.byType(TextFormField).at(1), 'Happy Coding'); | |
await tester.tap(find.byType(TextButton)); | |
await tester.pumpAndSettle(); | |
//we check whether the snackbar with the following text is displayed | |
expect(find.text('Note Added'), findsOneWidget); | |
TextField textField = | |
find.byType(TextField).at(0).evaluate().first.widget as TextField; | |
//we also confirm the input fields are cleared after input | |
expect(textField.controller!.text, ''); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment