import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:app_pfm_ocr_v2/features/editor/product_editor_screen.dart'; import 'package:app_pfm_ocr_v2/main.dart'; import 'package:app_pfm_ocr_v2/core/storage/local_storage.dart'; import 'package:app_pfm_ocr_v2/models/document_model.dart'; import 'package:shared_preferences/shared_preferences.dart'; class MockLocalStorage extends LocalStorage { @override Future init() async {} @override List getAllDocuments() => []; @override Future savePendingDocument(Map data) async {} @override Future removePendingDocument(String id) async {} @override List> getAllPendingDocuments() => []; } void main() { testWidgets('shows an explicit retry state instead of fabricated SKU matches when the backend is unreachable', (tester) async { SharedPreferences.setMockInitialValues({}); final container = ProviderContainer( overrides: [localStorageProvider.overrideWithValue(MockLocalStorage())], ); addTearDown(container.dispose); await tester.pumpWidget( UncontrolledProviderScope( container: container, child: const MaterialApp( home: ProductEditorScreen(pendingId: null), ), ), ); await tester.pumpAndSettle(const Duration(seconds: 5)); // The old behavior fabricated these exact hardcoded matches on any // fetch failure - they must never appear again. expect(find.textContaining('FIESTA SPICY CHICKEN NUGGET'), findsNothing); expect(find.textContaining('AKUMO NUGGET COIN'), findsNothing); expect(find.textContaining('98.5'), findsNothing); // old fake 0.985 confidence expect(find.text('Gagal Memuat Klasifikasi Produk'), findsOneWidget); expect(find.widgetWithText(ElevatedButton, 'Coba Lagi'), findsOneWidget); }); }