Skip to content

Commit

Permalink
Start implementing Robot with auth flow tests + set optionURLReflects…
Browse files Browse the repository at this point in the history
…ImperativeAPIs in tests
  • Loading branch information
bizz84 committed Nov 16, 2023
1 parent cb295c2 commit e793b69
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ecommerce_app/test/src/features/authentication/auth_flow_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_test/flutter_test.dart';

import '../../robot.dart';

void main() {
testWidgets('Sign in and sign out flow', (tester) async {
final r = Robot(tester);
await r.pumpMyApp();
r.expectFindAllProductCards();
});
}
33 changes: 33 additions & 0 deletions ecommerce_app/test/src/robot.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:ecommerce_app/src/app.dart';
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/products/data/fake_products_repository.dart';
import 'package:ecommerce_app/src/features/products/presentation/products_list/product_card.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';

class Robot {
Robot(this.tester);
final WidgetTester tester;

Future<void> pumpMyApp() async {
// Override repositories
final productsRepository = FakeProductsRepository(addDelay: false);
final authRepository = FakeAuthRepository(addDelay: false);
await tester.pumpWidget(
ProviderScope(
overrides: [
productsRepositoryProvider.overrideWithValue(productsRepository),
authRepositoryProvider.overrideWithValue(authRepository),
],
child: const MyApp(),
),
);
await tester.pumpAndSettle();
}

void expectFindAllProductCards() {
final finder = find.byType(ProductCard);
expect(finder, findsNWidgets(kTestProducts.length));
}
}

0 comments on commit e793b69

Please sign in to comment.