Fix part-number and date-code selection in ocr-extract

Part number now picks the longest hyphenated candidate instead of the
first one, matching the documented intent and preventing a short
unrelated token from being reported as the part number (which feeds
the fingerprint used for sorting).

Date code now only accepts YYWW candidates with a plausible year
(10-39) and valid calendar week (01-53), taking the last match when
several qualify; otherwise it stays null instead of guessing wrong,
since a wrong value is worse than a missing one.

Adds regression tests for both cases plus a no-plausible-candidate
case that must yield null.
This commit is contained in:
vchuser
2026-07-28 14:52:28 +02:00
parent 9098a45aec
commit 8d50334915
2 changed files with 39 additions and 5 deletions
+17
View File
@@ -52,3 +52,20 @@ test('leerer Text liefert ein leeres Spec', () => {
assert.equal(spec.capacityGb, null);
assert.equal(spec.partNumber, null);
});
test('waehlt bei der Teilenummer den laengsten Bindestrich-Kandidaten, nicht den ersten', () => {
const spec = extractFields(
'SAMSUNG\nAB1234SN-001\n64GB 4DRx4 PC4-2400\nM386A8K40BM1-CRC4Y\n1908',
);
assert.equal(spec.partNumber, 'M386A8K40BM1-CRC4Y');
});
test('verwirft den Datumscode, wenn mehrere vierstellige Bloecke vorkommen und nur einer plausibel ist', () => {
const spec = extractFields('SAMSUNG\n1234 5678\n64GB 2Rx4 PC4-2666\n9012\n1908');
assert.equal(spec.dateCode, '1908');
});
test('laesst den Datumscode null, wenn kein Kandidat als Jahr-Woche plausibel ist', () => {
const spec = extractFields('SAMSUNG\n9999 0060\n64GB 2Rx4 PC4-2666');
assert.equal(spec.dateCode, null);
});