No content changes: git diff --ignore-all-space over these files is empty. The churn came from editing on Windows against a repo checked out with LF.
92 lines
3.1 KiB
Dart
92 lines
3.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:app_pfm_ocr_v2/features/editor/product_scan_response_parser.dart';
|
|
|
|
void main() {
|
|
group('parseSkuMasterList', () {
|
|
test('unwraps the v1 {status,data} envelope into a list of maps', () {
|
|
final response = {
|
|
'status': 'success',
|
|
'data': [
|
|
{'no_sku': '12010119', 'nama_item': 'FIESTA NUGGET CHEESE 123 400 GR/PAC', 'standar_jumlah': 'PAC'},
|
|
{'no_sku': '12010115', 'nama_item': 'FIESTA NUGGET ZOO 400 GR/PAC'},
|
|
],
|
|
};
|
|
|
|
final result = parseSkuMasterList(response);
|
|
|
|
expect(result.length, 2);
|
|
expect(result[0]['no_sku'], '12010119');
|
|
expect(result[0]['nama_item'], 'FIESTA NUGGET CHEESE 123 400 GR/PAC');
|
|
expect(result[1]['no_sku'], '12010115');
|
|
});
|
|
|
|
test('returns an empty list when data is an empty array', () {
|
|
final result = parseSkuMasterList({'status': 'success', 'data': []});
|
|
expect(result, isEmpty);
|
|
});
|
|
|
|
test('returns an empty list when data is missing entirely', () {
|
|
final result = parseSkuMasterList({'status': 'success'});
|
|
expect(result, isEmpty);
|
|
});
|
|
});
|
|
|
|
group('parseScanProductResponse', () {
|
|
test('unwraps possibleMatches and extracted_expired_date from the nested v1 envelope', () {
|
|
final response = {
|
|
'status': 'success',
|
|
'data': {
|
|
'classification': {'top1_name': 'FIESTA NUGGET CHEESE'},
|
|
'ocr': {
|
|
'extracted_sku': '12010119',
|
|
'extracted_expired_date': '15/12/2026',
|
|
},
|
|
'possibleMatches': [
|
|
{'no_sku': '12010119', 'nama_item': 'FIESTA NUGGET CHEESE 123 400 GR/PAC', 'score': 0.725, 'isBestMatch': true},
|
|
{'no_sku': '12010115', 'nama_item': 'FIESTA NUGGET ZOO 400 GR/PAC', 'score': 0.5, 'isBestMatch': false},
|
|
],
|
|
},
|
|
};
|
|
|
|
final result = parseScanProductResponse(response);
|
|
|
|
expect(result.matches.length, 2);
|
|
expect(result.matches[0]['no_sku'], '12010119');
|
|
expect(result.matches[0]['nama_item'], 'FIESTA NUGGET CHEESE 123 400 GR/PAC');
|
|
expect(result.matches[0]['confidence'], 0.725);
|
|
expect(result.extractedExpiryDate, '15/12/2026');
|
|
});
|
|
|
|
test('returns an empty match list and empty date when possibleMatches is empty', () {
|
|
final response = {
|
|
'status': 'success',
|
|
'data': {
|
|
'classification': {},
|
|
'ocr': {'extracted_expired_date': ''},
|
|
'possibleMatches': [],
|
|
},
|
|
};
|
|
|
|
final result = parseScanProductResponse(response);
|
|
|
|
expect(result.matches, isEmpty);
|
|
expect(result.extractedExpiryDate, '');
|
|
});
|
|
|
|
test('degrades gracefully when ocr is missing entirely', () {
|
|
final response = {
|
|
'status': 'success',
|
|
'data': {
|
|
'classification': {},
|
|
'possibleMatches': <Map<String, dynamic>>[],
|
|
},
|
|
};
|
|
|
|
final result = parseScanProductResponse(response);
|
|
|
|
expect(result.matches, isEmpty);
|
|
expect(result.extractedExpiryDate, '');
|
|
});
|
|
});
|
|
}
|