import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pad_scanner/pages/registration/registration_calculations.dart'; import 'package:pad_scanner/services/api_service.dart'; void main() { group('registration calculations', () { test('calculates overview stats by item status', () { final stats = overviewStats( _overview([ _item('R1', status: 'not_shelved'), _item('R2', status: 'on_shelf'), _item('R3', status: 'transferred'), ]), ); expect(stats.totalCount, 3); expect(stats.shelvedCount, 1); expect(stats.transferredCount, 1); }); test('splits overview items into scanned and unscanned groups', () { final sections = splitOverviewItems( overview: _overview([_item('R1'), _item('R2'), _item('R3')]), zongpaiNos: ['R1', 'R3'], ); expect(sections.scanned.map((item) => item.zongpaiNo), ['R1', 'R3']); expect(sections.unscanned.map((item) => item.zongpaiNo), ['R2']); expect(sections.hasDivider, isTrue); }); test('finds located scanned items', () { final overview = _overview([ _item('R1', status: 'on_shelf'), _item('R2', status: 'transferred'), _item('R3', status: 'on_shelf'), ]); expect( findOnShelfItemsInScanned( overview: overview, zongpaiNos: ['R1', 'R2'], ).map((item) => item.zongpaiNo), ['R1'], ); expect( findTransferredItemsInScanned( overview: overview, zongpaiNos: ['R1', 'R2'], ).map((item) => item.zongpaiNo), ['R2'], ); expect( hasAnyLocatedInScanned(overview: overview, zongpaiNos: ['R1']), isTrue, ); expect( hasAnyLocatedInScanned(overview: overview, zongpaiNos: ['R4']), isFalse, ); }); test('maps row colors for scanned and unscanned states', () { expect( registrationBarColor( status: 'on_shelf', isScanned: true, isTransitTarget: false, ), Colors.red, ); expect( registrationRowBgColor( status: 'transferred', isScanned: false, isTransitTarget: false, ), const Color(0xFFFFF3E0), ); }); }); } PaichaOverviewResult _overview(List items) { return PaichaOverviewResult( success: true, totalCount: items.length, items: items, ); } PaichaOverviewItem _item(String zongpaiNo, {String status = 'not_shelved'}) { return PaichaOverviewItem(zongpaiNo: zongpaiNo, quantity: 1, status: status); }