diff --git a/lib/screens/cart/total_price_text.dart b/lib/screens/cart/total_price_text.dart index 2aa5950..1a5f39f 100644 --- a/lib/screens/cart/total_price_text.dart +++ b/lib/screens/cart/total_price_text.dart @@ -14,7 +14,7 @@ class TotalPriceText extends StatelessWidget { child: Padding( padding: const EdgeInsets.all(8.0), child: Text( - 'Gesamtpreis: $totalPrice', + 'Gesamtpreis: $totalPrice€', style: Theme.of(context).textTheme.labelLarge?.copyWith(fontSize: 24), ), ), diff --git a/test/cart_store_test.dart b/test/cart_store_test.dart new file mode 100644 index 0000000..36c67ee --- /dev/null +++ b/test/cart_store_test.dart @@ -0,0 +1,19 @@ +import 'dart:async'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:thesis_shop/models/remote_resource.dart'; +import 'package:thesis_shop/store/cart_store.dart'; + +import 'product_service_mock.dart'; + +void main() { + test('test cart store', () async { + final cartStore = CartStore(); + cartStore.updateProductList(const RemoteResource.finished(demoProducts)); + final callbackStream = StreamController(); + cartStore.addListener(() => callbackStream.add(true)); + cartStore.increaseAmount(demoProducts.first); + expect(cartStore.amountOfProduct(demoProducts.first), 1); + await expectLater(callbackStream.stream, emits(true)); + }); +} diff --git a/test/product_service_mock.dart b/test/product_service_mock.dart index d3dbb63..c54d122 100644 --- a/test/product_service_mock.dart +++ b/test/product_service_mock.dart @@ -1,15 +1,17 @@ import 'package:thesis_shop/models/product.dart'; import 'package:thesis_shop/service/product_service.dart'; +const demoProducts = [ + Product(title: 'Bananen', price: 3), + Product(title: 'Äpfel', price: 2), + Product(title: 'Birnen', price: 2.5), + Product(title: 'Kirschen', price: 1.2), +]; + class MockedProductService implements ProductService { @override Future> fetchProducts() async { - return const [ - Product(title: 'Bananen', price: 3), - Product(title: 'Äpfel', price: 2), - Product(title: 'Birnen', price: 2.5), - Product(title: 'Kirschen', price: 1.2), - ]; + return demoProducts; } @override diff --git a/test/total_price_test.dart b/test/total_price_test.dart new file mode 100644 index 0000000..fbc1078 --- /dev/null +++ b/test/total_price_test.dart @@ -0,0 +1,26 @@ +// ignore_for_file: unnecessary_cast + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:provider/provider.dart'; +import 'package:thesis_shop/screens/cart/total_price_text.dart'; +import 'package:thesis_shop/store/cart_store.dart'; + +class CartStoreMock extends CartStore { + @override + double get totalPrice => 10.0; +} + +void main() { + testWidgets('test total price', (tester) async { + final widgetTree = MaterialApp( + home: ChangeNotifierProvider.value( + value: CartStoreMock() as CartStore, + child: const TotalPriceText(), + ), + ); + await tester.pumpWidget(widgetTree); + final correctText = find.text("Gesamtpreis: 10.00€"); + expect(correctText, findsOneWidget); + }); +}