Files
kooltab/test/bar_tab_model_test.dart
T
2026-10-08 04:12:36 +02:00

90 lines
2.2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:kooltap/models/bar_tab.dart';
import 'package:kooltap/models/tab_item.dart';
void main() {
group('BarTab', () {
group('totalInCents', () {
test('calculates total from items', () {
final tab = BarTab(
id: 'tab-1',
customerName: 'John',
openedAt: DateTime.now(),
items: [
const TabItem(
id: 'item-1',
tabId: 'tab-1',
productId: 'prod-1',
productName: 'Beer',
quantity: 2,
unitPriceInCents: 400,
),
const TabItem(
id: 'item-2',
tabId: 'tab-1',
productId: 'prod-2',
productName: 'Wine',
quantity: 1,
unitPriceInCents: 600,
),
],
);
expect(tab.totalInCents, 1400);
});
test('returns 0 for empty tab', () {
final tab = BarTab(
id: 'tab-1',
customerName: 'John',
openedAt: DateTime.now(),
items: const [],
);
expect(tab.totalInCents, 0);
});
});
group('itemCount', () {
test('sums quantities of all items', () {
final tab = BarTab(
id: 'tab-1',
customerName: 'John',
openedAt: DateTime.now(),
items: [
const TabItem(
id: 'item-1',
tabId: 'tab-1',
productId: 'prod-1',
productName: 'Beer',
quantity: 3,
unitPriceInCents: 400,
),
const TabItem(
id: 'item-2',
tabId: 'tab-1',
productId: 'prod-2',
productName: 'Wine',
quantity: 2,
unitPriceInCents: 600,
),
],
);
expect(tab.itemCount, 5);
});
test('returns 0 for empty tab', () {
final tab = BarTab(
id: 'tab-1',
customerName: 'John',
openedAt: DateTime.now(),
items: const [],
);
expect(tab.itemCount, 0);
});
});
});
}