Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add widget tests for checking animation of status alert widget #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion test/widget_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ void main() {
backgroundColor: Colors.green,
);

final iconButton = Builder(builder: (context) {
return IconButton(
icon: Icon(Icons.favorite_border),
onPressed: () {
StatusAlert.show(
context,
duration: Duration(seconds: 2),
maxWidth: 20,
title: 'Loved',
subtitle: 'We\'ll recommend more like this For You.',
configuration: IconConfiguration(icon: Icons.favorite_border),
);
},
);
});

testWidgets('Widget should render correctly', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(statusAlert));
Expand Down Expand Up @@ -114,9 +130,34 @@ void main() {
expect(iconWidget.color, Colors.blue);
});
});

testWidgets('Alert should appears after onTap ', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(iconButton));

await tester.tap(find.byIcon(Icons.favorite_border));
await tester.pumpAndSettle();
expect(find.byType(StatusAlertBaseWidget), findsOneWidget);
});
});

testWidgets('Alert should disappears after duration', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(iconButton));

await tester.tap(find.byIcon(Icons.favorite_border));
await tester.pumpAndSettle();
await new Future.delayed(new Duration(seconds: 3));
await tester.pumpAndSettle();
expect(find.byType(StatusAlertBaseWidget), findsNothing);
});
});
});
}

Widget _wrapWithMaterialApp(Widget testWidget) {
return MaterialApp(home: testWidget);
return MaterialApp(
home: Scaffold(
body: testWidget,
));
}