import "package:flutter/widgets.dart"; import "package:flutter_test/flutter_test.dart"; import "package:garage_ui/garage_ui.dart"; import "support/test_scheme.dart"; // The section's own subtitle. Sits in the header under the title, and stays // there while the section is collapsed - it names the section rather than // being part of its body. Sections deliberately have no `description`; a box // of copy above the rows competed with them, and a row's own description // covers the case anyway. Widget _host(Widget child) => Directionality( textDirection: TextDirection.ltr, child: GarageTheme( data: ThemeData(colorScheme: testScheme, density: const Density()), child: Center(child: SizedBox(width: 420, child: child)), ), ); Widget _section({String? subtitle, bool collapsed = false}) => PropertiesSection( title: "Profile", subtitle: subtitle, scheme: testScheme, collapsed: collapsed, onToggle: () {}, rows: [ PropertyRow( label: "Username", scheme: testScheme, child: const TextField(), ), ], ); void main() { testWidgets("subtitle sits under the title, above the rows", (tester) async { await tester.pumpWidget(_host(_section(subtitle: "a subtitle"))); final title = tester.getRect(find.text("Profile")); final sub = tester.getRect(find.text("a subtitle")); final row = tester.getRect(find.text("Username")); expect(sub.top, greaterThanOrEqualTo(title.bottom)); expect(sub.left, title.left); // same column, clear of the chevron expect(row.top, greaterThan(sub.bottom)); }); testWidgets("subtitle renders at textXxs", (tester) async { await tester.pumpWidget(_host(_section(subtitle: "a subtitle"))); expect( tester.widget(find.text("a subtitle")).style!.fontSize, const Density().textXxs, ); }); testWidgets("subtitle survives collapse", (tester) async { await tester.pumpWidget( _host(_section(subtitle: "a subtitle", collapsed: true)), ); // it names the section, so it stays when the body goes expect(find.text("a subtitle"), findsOneWidget); expect(find.text("Username"), findsNothing); }); }