1
0
Fork 0
Browse Source

Add tests

riverpod
Jonas Franz 6 months ago
parent
commit
64b58d03a4
  1. 14
      test/cart_test.dart
  2. 14
      test/product_service_mock.dart
  3. 21
      test/total_price_test.dart

14
test/cart_test.dart

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
// ignore_for_file: invalid_use_of_protected_member
import 'package:flutter_test/flutter_test.dart';
import 'package:thesis_shop/stores/cart_store.dart';
import 'product_service_mock.dart';
void main() {
test('test cart store', () {
final cartStore = CartStore();
cartStore.increaseAmountOfProduct(demoProducts.first);
expect(cartStore.state[demoProducts.first.title], 1);
});
}

14
test/product_service_mock.dart

@ -1,15 +1,17 @@ @@ -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<List<Product>> 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

21
test/total_price_test.dart

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:thesis_shop/screens/cart/total_price_text.dart';
import 'package:thesis_shop/stores/cart_store.dart';
void main() {
testWidgets('test total price widget', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: ProviderScope(
overrides: [
totalPriceProvider.overrideWithValue(10.0),
],
child: const TotalPriceText(),
),
),
);
expect(find.text('Gesamtpreis: 10.00€'), findsOneWidget);
});
}
Loading…
Cancel
Save