import 'package:clide/src/svg/svg_document.dart'; import 'package:clide/widgets/src/draw/drawing_card.dart'; import 'package:clide/widgets/src/svg/svg_painter.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import '../../helpers/kernel_fixture.dart'; import '../../helpers/widget_harness.dart'; void main() { late KernelFixture f; setUp(() async => f = await KernelFixture.create()); tearDown(() async => f.dispose()); Widget card({String? label, String? description}) => SizedBox( width: 400, child: DrawingCard( document: buildSvgDocument(''), label: label, description: description, ), ); testWidgets('renders the SVG region with both captions', (tester) async { await tester.pumpWidget(anchoredHarness(f, card(label: 'Build pipeline', description: 'how it connects'))); expect(find.byType(SvgView), findsOneWidget); expect(find.text('Build pipeline'), findsOneWidget); expect(find.text('how it connects'), findsOneWidget); }); testWidgets('omits captions when label and description are absent', (tester) async { await tester.pumpWidget(anchoredHarness(f, card())); expect(find.byType(SvgView), findsOneWidget); expect(find.text('Build pipeline'), findsNothing); }); testWidgets('renders per-object captions from data-* annotations (T-318)', (tester) async { final doc = buildSvgDocument( '', ); await tester.pumpWidget(anchoredHarness(f, SizedBox(width: 400, child: DrawingCard(document: doc)))); await tester.pump(); expect(find.text('Node A'), findsOneWidget); expect(find.text('the entry point'), findsOneWidget); }); testWidgets('a source disclosure folds the d2 source under a collapser (T-494)', (tester) async { await tester.pumpWidget( anchoredHarness( f, SizedBox( width: 400, child: DrawingCard( document: buildSvgDocument(''), source: 'a -> b: hello', sourceLabel: 'view d2 source', ), ), ), ); await tester.pump(); // The disclosure header shows; the source is folded away until expanded. expect(find.text('view d2 source'), findsOneWidget); expect(find.text('a -> b: hello'), findsNothing); await tester.tap(find.text('view d2 source')); await tester.pumpAndSettle(); expect(find.text('a -> b: hello'), findsOneWidget); }); testWidgets('a data-lightbox element fires onLightbox when tapped (T-318)', (tester) async { var tapped = false; final doc = buildSvgDocument(''); await tester.pumpWidget( anchoredHarness( f, SizedBox( width: 400, child: DrawingCard(document: doc, onLightbox: () => tapped = true), ), ), ); await tester.pump(); await tester.tap(find.byType(DrawingCard)); expect(tapped, isTrue); }); }