MotorSignal-App/test/motorcycle_photo_attributio...

85 lines
2.6 KiB
Dart

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: '<a href="//commons.wikimedia.org/wiki/User:Chanokchon">Chanokchon</a> &amp; 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('<a href='), findsNothing);
expect(find.textContaining('</a>'), findsNothing);
expect(find.textContaining('&amp;'), 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);
});
});
}