88 lines
2.3 KiB
Dart
88 lines
2.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:kooltap/models/closed_tab.dart';
|
|
import 'package:kooltap/models/closed_tab_item.dart';
|
|
import 'package:kooltap/models/payment_method.dart';
|
|
|
|
ClosedTabItem _item({
|
|
required String id,
|
|
int quantity = 1,
|
|
int unitPriceInCents = 400,
|
|
DateTime? removedAt,
|
|
}) {
|
|
return ClosedTabItem(
|
|
id: id,
|
|
closedTabId: 'closed-1',
|
|
productId: 'prod-1',
|
|
productName: 'Beer',
|
|
quantity: quantity,
|
|
unitPriceInCents: unitPriceInCents,
|
|
purchasedAt: DateTime(2026, 1, 1, 20),
|
|
removedAt: removedAt,
|
|
);
|
|
}
|
|
|
|
ClosedTab _tab(List<ClosedTabItem> items) {
|
|
return ClosedTab(
|
|
id: 'closed-1',
|
|
originalTabId: 'tab-1',
|
|
customerName: 'John',
|
|
closedAt: DateTime(2026, 1, 1, 23),
|
|
paymentMethod: PaymentMethod.cash,
|
|
items: items,
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
group('ClosedTabItem', () {
|
|
test('charges quantity times unit price', () {
|
|
expect(
|
|
_item(id: 'a', quantity: 3, unitPriceInCents: 250).lineTotalInCents,
|
|
750,
|
|
);
|
|
});
|
|
|
|
test('charges nothing once removed', () {
|
|
final removed = _item(id: 'a', removedAt: DateTime(2026, 1, 1, 21));
|
|
|
|
expect(removed.isRemoved, true);
|
|
expect(removed.lineTotalInCents, 0);
|
|
});
|
|
});
|
|
|
|
group('ClosedTab', () {
|
|
test('totals only the purchases that were not removed', () {
|
|
final tab = _tab([
|
|
_item(id: 'a', unitPriceInCents: 400),
|
|
_item(id: 'b', unitPriceInCents: 400),
|
|
_item(id: 'c', unitPriceInCents: 600),
|
|
_item(id: 'd', unitPriceInCents: 400, removedAt: DateTime(2026)),
|
|
]);
|
|
|
|
expect(tab.totalInCents, 1400);
|
|
expect(tab.itemCount, 3);
|
|
});
|
|
|
|
test('is zero when every purchase was removed', () {
|
|
final tab = _tab([
|
|
_item(id: 'a', removedAt: DateTime(2026)),
|
|
_item(id: 'b', removedAt: DateTime(2026)),
|
|
]);
|
|
|
|
expect(tab.totalInCents, 0);
|
|
expect(tab.itemCount, 0);
|
|
});
|
|
});
|
|
|
|
group('PaymentMethod', () {
|
|
test('round-trips through its stored value', () {
|
|
for (final method in PaymentMethod.values) {
|
|
expect(PaymentMethod.fromValue(method.value), method);
|
|
}
|
|
});
|
|
|
|
test('falls back to cash for an unknown value', () {
|
|
expect(PaymentMethod.fromValue('bitcoin'), PaymentMethod.cash);
|
|
});
|
|
});
|
|
}
|