feat: add rows count (broken), fix: bug with low stock items

This commit is contained in:
2026-08-02 23:23:28 +02:00
parent f5b2041612
commit 6060ca2713
19 changed files with 373 additions and 41 deletions
+64
View File
@@ -0,0 +1,64 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:kooltab2/models/product.dart';
import 'package:kooltab2/models/tab_item.dart';
import 'package:kooltab2/services/bar_tab_service.dart';
import 'package:kooltab2/services/product_service.dart';
import 'package:kooltab2/viewmodels/bar_screen_view_model.dart';
import 'package:kooltab2/viewmodels/inventory_view_model.dart';
import 'package:mocktail/mocktail.dart';
class MockBarTabService extends Mock implements BarTabService {}
class MockProductService extends Mock implements ProductService {}
void main() {
late MockBarTabService barTabService;
late MockProductService productService;
late InventoryViewModel inventory;
late BarScreenViewModel viewModel;
setUp(() {
barTabService = MockBarTabService();
productService = MockProductService();
inventory = InventoryViewModel(productService: productService);
viewModel = BarScreenViewModel(
barTabService: barTabService,
inventory: inventory,
);
});
test(
'does not increase a tab item when its product is out of stock',
() async {
const product = Product(
id: 'prod-1',
name: 'Chips',
category: 'Snacks',
stockQuantity: 0,
lowStockThreshold: 5,
priceInCents: 150,
);
const item = TabItem(
id: 'item-1',
tabId: 'tab-1',
productId: 'prod-1',
productName: 'Chips',
quantity: 20,
unitPriceInCents: 150,
);
when(
() => productService.getProducts(),
).thenAnswer((_) async => [product]);
await inventory.load();
await expectLater(
viewModel.changeItemQuantity(item, 21),
throwsA(isA<InsufficientStockException>()),
);
expect(viewModel.errorMessage, isNull);
verifyNoMoreInteractions(barTabService);
},
);
}
+1 -1
View File
@@ -218,7 +218,7 @@ void main() {
expect(
() => service.decreaseStock('low-stock', 5),
throwsA(isA<Exception>()),
throwsA(isA<InsufficientStockException>()),
);
});
});