Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
test(CustomRatingField): Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
YaharonYH authored and moverval committed Jan 4, 2024
1 parent 29c7ff7 commit fb27d18
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions test/CustomRatingField_test.dart
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),
);
});
});
}

0 comments on commit fb27d18

Please sign in to comment.