parent
f747efee9d
commit
6bb5e0e9bb
@ -0,0 +1,31 @@ |
||||
import 'package:flutter_test/flutter_test.dart'; |
||||
import 'package:thesis_shop/bloc/cart_bloc.dart'; |
||||
import 'package:thesis_shop/bloc/product_bloc.dart'; |
||||
|
||||
import 'product_service_mock.dart'; |
||||
|
||||
class ProductBlocMock implements ProductBloc { |
||||
const ProductBlocMock(); |
||||
@override |
||||
Future<void> dispose() async {} |
||||
|
||||
@override |
||||
Sink<LoadProductEvent> get loadProductSink => throw UnimplementedError(); |
||||
|
||||
@override |
||||
final ProductsState productsState = const ProductsState.loaded(demoProducts); |
||||
|
||||
@override |
||||
Stream<ProductsState> get productsStateStream => |
||||
Stream.value(productsState).asBroadcastStream(); |
||||
} |
||||
|
||||
void main() { |
||||
test('test cart bloc', () async { |
||||
const productBlocMock = ProductBlocMock(); |
||||
final cartBloc = CartBloc(productBlocMock); |
||||
final expectedCart = {demoProducts.first: 1}; |
||||
expectLater(cartBloc.cartStream, emits(expectedCart)); |
||||
cartBloc.quantityEventSink.add(IncreaseQuantityEvent(demoProducts.first)); |
||||
}); |
||||
} |
@ -0,0 +1,49 @@ |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter_test/flutter_test.dart'; |
||||
import 'package:thesis_shop/bloc/cart_bloc.dart'; |
||||
import 'package:thesis_shop/bloc/product_bloc.dart'; |
||||
import 'package:thesis_shop/bloc/user_bloc.dart'; |
||||
import 'package:thesis_shop/bloc_provider.dart'; |
||||
import 'package:thesis_shop/screens/cart/total_price_text.dart'; |
||||
|
||||
import 'product_service_mock.dart'; |
||||
|
||||
class CartBlocMock implements CartBloc { |
||||
@override |
||||
Stream<int> numberOfProductsStream = const Stream.empty(); |
||||
|
||||
@override |
||||
Cart get cart => throw UnimplementedError(); |
||||
|
||||
@override |
||||
Stream<Cart> get cartStream => throw UnimplementedError(); |
||||
|
||||
@override |
||||
Future<void> dispose() async {} |
||||
|
||||
@override |
||||
final int numberOfProducts = 1; |
||||
|
||||
@override |
||||
Sink<ChangeQuantityEvent> get quantityEventSink => throw UnimplementedError(); |
||||
|
||||
@override |
||||
double get totalPrice => 10.00; |
||||
|
||||
@override |
||||
Stream<double> get totalPriceStream => Stream.value(totalPrice); |
||||
} |
||||
|
||||
void main() { |
||||
testWidgets('test total price widget', (tester) async { |
||||
final blocProvider = BlocProvider( |
||||
userBloc: UserBloc(), |
||||
productBloc: ProductBloc(MockedProductService(), UserBloc()), |
||||
cartBloc: CartBlocMock()); |
||||
final appStateWithTotalPrice = AppState( |
||||
blocProvider: blocProvider, |
||||
child: const MaterialApp(home: TotalPriceText())); |
||||
await tester.pumpWidget(appStateWithTotalPrice); |
||||
expect(find.text("Gesamtpreis: 10.00€"), findsOneWidget); |
||||
}); |
||||
} |
Loading…
Reference in new issue