| 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:flutter_test/flutter_test.dart'; |
| 3 | import 'package:localmind/features/chat/views/components/chat_bubble/markdown/themed_gpt_markdown.dart'; |
| 4 | |
| 5 | void main() { |
| 6 | testWidgets('renders Markdown image URLs with NetworkImage', (tester) async { |
| 7 | const url = 'https://example.com/picture.png'; |
| 8 | |
| 9 | await tester.pumpWidget( |
| 10 | const MaterialApp( |
| 11 | home: Scaffold( |
| 12 | body: ThemedGptMarkdown( |
| 13 | content: '', |
| 14 | isDark: false, |
| 15 | style: TextStyle(), |
| 16 | ), |
| 17 | ), |
| 18 | ), |
| 19 | ); |
| 20 | |
| 21 | final networkImages = tester |
| 22 | .widgetList<Image>(find.byType(Image)) |
| 23 | .map((image) => image.image) |
| 24 | .whereType<NetworkImage>(); |
| 25 | expect(networkImages.map((image) => image.url), contains(url)); |
| 26 | }); |
| 27 | |
| 28 | testWidgets( |
| 29 | 'MarkdownBodyContent wraps with SelectionArea when selectable is true', |
| 30 | (tester) async { |
| 31 | await tester.pumpWidget( |
| 32 | const MaterialApp( |
| 33 | home: Scaffold( |
| 34 | body: MarkdownBodyContent( |
| 35 | content: 'Hello world', |
| 36 | isDark: false, |
| 37 | selectable: true, |
| 38 | ), |
| 39 | ), |
| 40 | ), |
| 41 | ); |
| 42 | |
| 43 | expect(find.byType(SelectionArea), findsOneWidget); |
| 44 | expect(find.text('Hello world'), findsOneWidget); |
| 45 | }, |
| 46 | ); |
| 47 | |
| 48 | testWidgets( |
| 49 | 'MarkdownBodyContent does not wrap with SelectionArea when selectable is false', |
| 50 | (tester) async { |
| 51 | await tester.pumpWidget( |
| 52 | const MaterialApp( |
| 53 | home: Scaffold( |
| 54 | body: MarkdownBodyContent( |
| 55 | content: 'Streaming content', |
| 56 | isDark: false, |
| 57 | selectable: false, |
| 58 | ), |
| 59 | ), |
| 60 | ), |
| 61 | ); |
| 62 | |
| 63 | expect(find.byType(SelectionArea), findsNothing); |
| 64 | expect(find.text('Streaming content'), findsOneWidget); |
| 65 | }, |
| 66 | ); |
| 67 | } |