feat(boxing): handle multi-code paichan switches
This commit is contained in:
60
test/services/boxing_context_test.dart
Normal file
60
test/services/boxing_context_test.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pad_scanner/services/boxing_context.dart';
|
||||
|
||||
void main() {
|
||||
group('decideMultiCodePaichanContext', () {
|
||||
test('first scan records context and fills recommended box if empty', () {
|
||||
final decision = decideMultiCodePaichanContext(
|
||||
lastPaichanNo: null,
|
||||
currentPaichanNo: 'W00009',
|
||||
currentBoxNoText: '',
|
||||
maxBoxNo: 3,
|
||||
);
|
||||
|
||||
expect(decision.change, PaichanContextChange.firstScan);
|
||||
expect(decision.boxNoToApply, 4);
|
||||
expect(decision.isSwitched, isFalse);
|
||||
});
|
||||
|
||||
test('same paichan keeps current box number', () {
|
||||
final decision = decideMultiCodePaichanContext(
|
||||
lastPaichanNo: 'W00009',
|
||||
currentPaichanNo: 'W00009',
|
||||
currentBoxNoText: '8',
|
||||
maxBoxNo: 3,
|
||||
);
|
||||
|
||||
expect(decision.change, PaichanContextChange.samePaichan);
|
||||
expect(decision.boxNoToApply, isNull);
|
||||
expect(decision.isSwitched, isFalse);
|
||||
});
|
||||
|
||||
test('switched paichan resets to new paichan max box plus one', () {
|
||||
final decision = decideMultiCodePaichanContext(
|
||||
lastPaichanNo: 'W00009',
|
||||
currentPaichanNo: 'W00010',
|
||||
currentBoxNoText: '8',
|
||||
maxBoxNo: 1,
|
||||
);
|
||||
|
||||
expect(decision.change, PaichanContextChange.switchedPaichan);
|
||||
expect(decision.boxNoToApply, 2);
|
||||
expect(decision.isSwitched, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'same paichan defensively fills recommended box when box is empty',
|
||||
() {
|
||||
final decision = decideMultiCodePaichanContext(
|
||||
lastPaichanNo: 'W00009',
|
||||
currentPaichanNo: 'W00009',
|
||||
currentBoxNoText: '',
|
||||
maxBoxNo: 4,
|
||||
);
|
||||
|
||||
expect(decision.change, PaichanContextChange.samePaichan);
|
||||
expect(decision.boxNoToApply, 5);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user