-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completed code and tests for section 11
# Conflicts: # ecommerce_app/lib/src/features/products/presentation/product_screen/leave_review_action.dart # ecommerce_app/lib/src/features/reviews/data/fake_purchases_repository.dart
- Loading branch information
Showing
6 changed files
with
126 additions
and
17 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
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
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
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import 'package:ecommerce_app/src/constants/test_products.dart'; | ||
import 'package:ecommerce_app/src/features/authentication/data/fake_auth_repository.dart'; | ||
import 'package:ecommerce_app/src/features/authentication/domain/app_user.dart'; | ||
import 'package:ecommerce_app/src/features/products/data/fake_products_repository.dart'; | ||
import 'package:ecommerce_app/src/features/reviews/application/reviews_service.dart'; | ||
import 'package:ecommerce_app/src/features/reviews/data/fake_reviews_repository.dart'; | ||
import 'package:ecommerce_app/src/features/reviews/domain/review.dart'; | ||
|
@@ -11,21 +13,25 @@ import '../../../mocks.dart'; | |
|
||
void main() { | ||
const testUser = AppUser(uid: 'abc', email: '[email protected]'); | ||
const testProductId = '1'; | ||
final testProductId = kTestProducts[0].id; | ||
final testReview = | ||
Review(rating: 5, comment: '', date: DateTime(2022, 7, 31)); | ||
late MockAuthRepository authRepository; | ||
late MockReviewsRepository reviewsRepository; | ||
late MockProductsRepository productsRepository; | ||
|
||
setUp(() { | ||
authRepository = MockAuthRepository(); | ||
reviewsRepository = MockReviewsRepository(); | ||
productsRepository = MockProductsRepository(); | ||
}); | ||
|
||
ReviewsService makeReviewsService() { | ||
final container = ProviderContainer( | ||
overrides: [ | ||
authRepositoryProvider.overrideWithValue(authRepository), | ||
reviewsRepositoryProvider.overrideWithValue(reviewsRepository), | ||
productsRepositoryProvider.overrideWithValue(productsRepository), | ||
], | ||
); | ||
addTearDown(container.dispose); | ||
|
@@ -54,6 +60,14 @@ void main() { | |
uid: testUser.uid, | ||
review: testReview, | ||
)).thenAnswer((_) => Future.value()); | ||
when(() => reviewsRepository.fetchReviews(testProductId)) | ||
.thenAnswer((_) => Future.value([])); | ||
when(() => productsRepository.getProduct(testProductId)).thenReturn( | ||
kTestProducts[0], | ||
); | ||
when(() => productsRepository.setProduct( | ||
kTestProducts[0], | ||
)).thenAnswer((_) => Future.value()); | ||
final reviewsService = makeReviewsService(); | ||
// run | ||
await reviewsService.submitReview(productId: '1', review: testReview); | ||
|
41 changes: 41 additions & 0 deletions
41
.../test/src/features/reviews/presentation/leave_review_screen/leave_review_screen_test.dart
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,41 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../../../../robot.dart'; | ||
|
||
void main() { | ||
Future<void> purchaseOneProduct(Robot r) async { | ||
// add to cart | ||
await r.products.selectProduct(); | ||
await r.products.setProductQuantity(3); | ||
await r.cart.addToCart(); | ||
await r.cart.openCart(); | ||
r.cart.expectFindNCartItems(1); | ||
// checkout | ||
await r.checkout.startCheckout(); | ||
await r.auth.enterAndSubmitEmailAndPassword(); | ||
r.cart.expectFindNCartItems(1); | ||
await r.checkout.startPayment(); | ||
// when a payment is complete, user is taken to the orders page | ||
r.orders.expectFindNOrders(1); | ||
await r.closePage(); // close orders page | ||
} | ||
|
||
testWidgets('purchase product, leave review, update it', (tester) async { | ||
final r = Robot(tester); | ||
await r.pumpMyApp(); | ||
await purchaseOneProduct(r); | ||
await r.products.selectProduct(); | ||
// leave review | ||
r.reviews.expectFindLeaveReview(); | ||
await r.reviews.tapLeaveReviewButton(); | ||
await r.reviews.createAndSubmitReview('Love it!'); | ||
r.reviews.expectFindOneReview(); | ||
r.reviews.expectFindText('Love it!'); | ||
// update review | ||
r.reviews.expectFindUpdateReview(); | ||
await r.reviews.tapUpdateReviewButton(); | ||
await r.reviews.updateAndSubmitReview('Great!'); | ||
r.reviews.expectFindOneReview(); | ||
r.reviews.expectFindText('Great!'); | ||
}); | ||
} |
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