import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:marianum_mobile/view/pages/talk/widgets/message_markdown.dart';

Future<void> _pump(WidgetTester tester, String data) async {
  await tester.pumpWidget(
    MaterialApp(
      home: Scaffold(body: MessageMarkdown(data: data)),
    ),
  );
}

void main() {
  group('MessageMarkdown – supported subset', () {
    testWidgets('renders bold, italic and strikethrough text', (tester) async {
      await _pump(tester, '**bold** _italic_ ~~struck~~');
      expect(find.textContaining('bold', findRichText: true), findsWidgets);
      expect(find.textContaining('italic', findRichText: true), findsWidgets);
      expect(find.textContaining('struck', findRichText: true), findsWidgets);
    });

    testWidgets('renders headings without the # markers', (tester) async {
      await _pump(tester, '# Heading');
      expect(find.textContaining('Heading', findRichText: true), findsWidgets);
      expect(find.textContaining('#', findRichText: true), findsNothing);
    });

    testWidgets('renders task-list checkboxes', (tester) async {
      await _pump(tester, '- [x] done\n- [ ] open');
      expect(find.byIcon(Icons.check_box_outlined), findsOneWidget);
      expect(find.byIcon(Icons.check_box_outline_blank), findsOneWidget);
    });
  });

  group('MessageMarkdown – enforced limits (Rahmen)', () {
    testWidgets('shows raw HTML literally instead of interpreting it', (
      tester,
    ) async {
      await _pump(tester, 'a <b>tag</b> here');
      // The angle-bracket tags must survive as visible text, never as styling.
      expect(find.textContaining('<b>', findRichText: true), findsWidgets);
    });

    testWidgets('never fetches images, only shows their alt text', (
      tester,
    ) async {
      await _pump(tester, '![altText](https://example.com/pic.png)');
      expect(find.byType(Image), findsNothing);
      expect(find.textContaining('altText', findRichText: true), findsWidgets);
    });
  });
}
