This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(CustomRatingField): Initial commit
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'package:biersommelier/components/CustomRatingField.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('Custom Rating tests', () { | ||
testWidgets('Test Default Values', (WidgetTester tester) async{ | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: CustomRatingField( | ||
onRatingSelected: (rating) {}, | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(CustomRatingField), findsOneWidget); | ||
expect(find.byWidgetPredicate( | ||
(widget) => | ||
widget is Image && | ||
(widget.image as AssetImage).assetName == 'assets/icons/review_empty.png', | ||
), | ||
findsNWidgets(5), | ||
); | ||
}); | ||
|
||
testWidgets('Test with initial Rating of 3', (WidgetTester tester) async{ | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: CustomRatingField( | ||
initialRating: 3, | ||
onRatingSelected: (rating) {}, | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(CustomRatingField), findsOneWidget); | ||
expect(find.byWidgetPredicate( | ||
(widget) => | ||
widget is Image && | ||
(widget.image as AssetImage).assetName == 'assets/icons/review_empty.png', | ||
), | ||
findsNWidgets(2), | ||
); | ||
expect(find.byWidgetPredicate( | ||
(widget) => | ||
widget is Image && | ||
(widget.image as AssetImage).assetName == 'assets/icons/review_full.png', | ||
), | ||
findsNWidgets(3), | ||
); | ||
}); | ||
|
||
testWidgets('Test if the User makes an input', (WidgetTester tester) async{ | ||
int selectedRating = 0; | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: CustomRatingField( | ||
onRatingSelected: (rating) { | ||
selectedRating = rating; | ||
}, | ||
), | ||
), | ||
); | ||
|
||
expect(selectedRating, 0); | ||
|
||
await tester.tap(find.byType(GestureDetector).at(1)); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
expect(selectedRating, 2); | ||
|
||
expect(find.byWidgetPredicate( | ||
(widget) => | ||
widget is Image && | ||
(widget.image as AssetImage).assetName == 'assets/icons/review_empty.png', | ||
), | ||
findsNWidgets(3), | ||
); | ||
expect(find.byWidgetPredicate( | ||
(widget) => | ||
widget is Image && | ||
(widget.image as AssetImage).assetName == 'assets/icons/review_full.png', | ||
), | ||
findsNWidgets(2), | ||
); | ||
}); | ||
}); | ||
} |