import 'package:flutter_test/flutter_test.dart'; import 'package:kooltab2/models/bar_tab.dart'; import 'package:kooltab2/models/tab_item.dart'; void main() { group('BarTab', () { group('totalInCents', () { test('calculates total from items', () { final tab = BarTab( id: 'tab-1', customerName: 'John', status: 'open', 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', status: 'open', 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', status: 'open', 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', status: 'open', openedAt: DateTime.now(), items: const [], ); expect(tab.itemCount, 0); }); }); group('formattedTotal', () { test('formats total with euro symbol', () { final tab = BarTab( id: 'tab-1', customerName: 'John', status: 'open', openedAt: DateTime.now(), items: const [ TabItem( id: 'item-1', tabId: 'tab-1', productId: 'prod-1', productName: 'Beer', quantity: 2, unitPriceInCents: 425, ), ], ); expect(tab.formattedTotal, '€8.50'); }); }); group('isOpen', () { test('returns true for open status', () { final tab = BarTab( id: 'tab-1', customerName: 'John', status: 'open', openedAt: DateTime.now(), items: const [], ); expect(tab.isOpen, true); }); test('returns false for closed status', () { final tab = BarTab( id: 'tab-1', customerName: 'John', status: 'closed', openedAt: DateTime.now(), items: const [], ); expect(tab.isOpen, false); }); }); }); }