Files
clide/test/widgets/draw/drawing_card_test.dart
jpmschweitzerandClaude Opus 4.8 5f8fa6af10 feat(draw): fold the d2 source into a "view source" disclosure (T-494)
The rendered diagram leads; the d2 source carries through the draw bus and
folds into a collapsed ClideCollapserCard beneath the card (D-78 display-
only). en+nl catalogs. Also switches the d2 test to a null-aware element.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-29 12:08:33 +02:00

87 lines
3.2 KiB
Dart

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('<svg viewBox="0 0 20 10"><rect width="20" height="10" fill="#FF0000"/></svg>'),
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(
'<svg viewBox="0 0 100 50"><rect x="10" y="10" width="40" height="20" data-label="Node A" data-description="the entry point"/></svg>',
);
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('<svg viewBox="0 0 20 10"><rect width="20" height="10"/></svg>'),
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('<svg viewBox="0 0 100 50"><rect x="0" y="0" width="100" height="50" data-lightbox=""/></svg>');
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);
});
}