import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:motorcycle_dash/features/garage/widgets/motorcycle_photo.dart'; import 'package:motorcycle_dash/services/motorcycle_image_service.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); setUp(() { MotorcycleImageService.resetRegistry(); }); tearDown(() { MotorcycleImageService.resetRegistry(); }); group('MotorcyclePhoto Attribution Sanitization', () { testWidgets('renders sanitized attribution without raw HTML tags or unescaped entities', (tester) async { MotorcycleImageService.registerDescriptor( const MotorcycleImageDescriptor( make: 'TestMake', model: 'TestModel', exactYear: 2024, assetPath: 'assets/images/motorcycles/yamaha_yzf_r6_2001.jpg', caption: '2024 Test Motorcycle', attribution: 'Chanokchon & Team', isPhoto: true, ), ); await tester.pumpWidget( const MaterialApp( home: Scaffold( body: MotorcyclePhoto( year: 2024, make: 'TestMake', model: 'TestModel', showAttribution: true, ), ), ), ); await tester.pumpAndSettle(); // Verify that no raw HTML tags or unescaped entities are displayed expect(find.textContaining(''), findsNothing); expect(find.textContaining('&'), findsNothing); // Verify sanitized text is displayed cleanly expect(find.text('Photo: Chanokchon & Team'), findsOneWidget); }); testWidgets('hides attribution when showAttribution is false', (tester) async { MotorcycleImageService.registerDescriptor( const MotorcycleImageDescriptor( make: 'TestMake', model: 'TestModel', exactYear: 2024, assetPath: 'assets/images/motorcycles/yamaha_yzf_r6_2001.jpg', caption: '2024 Test Motorcycle', attribution: 'Test Photographer', isPhoto: true, ), ); await tester.pumpWidget( const MaterialApp( home: Scaffold( body: MotorcyclePhoto( year: 2024, make: 'TestMake', model: 'TestModel', showAttribution: false, ), ), ), ); await tester.pumpAndSettle(); expect(find.textContaining('Photo:'), findsNothing); }); }); }