import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart'; import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/navigation_rail.dart'; import 'package:pipelines_app/shell/windows/window_frame.dart'; import 'package:pipelines_app/ui/layout/app_list_avatar.dart'; import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:pipelines_app/ui/theme/app_design.dart'; import 'package:pipelines_app/ui/theme/app_design_tokens.dart'; /// Compact as drawn: thin rows, a narrow icon-only rail, 32px icon buttons /// (40px targets on touch), tight bubbles, a slim window title bar, and no /// clipping at a large text scale. void main() { tearDown(() => debugDefaultTargetPlatformOverride = null); Future pump( WidgetTester tester, Widget child, { AppDesign design = AppDesign.compact, double textScale = 1, double width = 560, }) async { tester.view.physicalSize = Size(width, 900); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); await tester.pumpWidget( MaterialApp( // Built afresh, so the platform this test sets is the theme's. theme: design.build(Brightness.light), home: MediaQuery( data: MediaQueryData( size: Size(width, 900), textScaler: TextScaler.linear(textScale), ), child: Scaffold(body: child), ), ), ); await tester.pumpAndSettle(); } Widget rows() => ListView( children: [ AppListRow( key: const Key('one'), title: const Text('Release train'), time: '09:12', onTap: () {}, ), AppListRow( key: const Key('two'), leading: AppListAvatar.initial('Release', color: Colors.teal), title: const Text('Release notes'), subtitle: const Text('claude-opus ยท /workspace/demo'), time: '10m', selected: true, onTap: () {}, ), ], ); testWidgets('pointer: a 36px single-line row and a ~52px two-line row', ( tester, ) async { debugDefaultTargetPlatformOverride = TargetPlatform.linux; await pump(tester, rows()); // Each row includes its 1px divider. expect(tester.getSize(find.byKey(const Key('one'))).height, 37); final two = tester.getSize(find.byKey(const Key('two'))).height; expect(two, inInclusiveRange(50, 56)); expect( tester.getSize(find.byType(AppListAvatar)).height, DesignDensity.compact.avatarSize, ); debugDefaultTargetPlatformOverride = null; }); testWidgets('touch: rows keep a 40px target', (tester) async { debugDefaultTargetPlatformOverride = TargetPlatform.android; await pump(tester, rows()); expect( tester.getSize(find.byKey(const Key('one'))).height, greaterThanOrEqualTo(41), ); debugDefaultTargetPlatformOverride = null; }); testWidgets('Default rows keep their comfortable size', (tester) async { await pump(tester, rows(), design: AppDesign.standard); expect( tester.getSize(find.byKey(const Key('one'))).height, greaterThan(48), ); expect( tester.getSize(find.byType(AppListAvatar)).height, kAppListAvatarSize, ); }); testWidgets('rows and bubbles do not clip at 2x text', (tester) async { debugDefaultTargetPlatformOverride = TargetPlatform.linux; await pump( tester, Column( children: [ SizedBox(height: 300, child: rows()), const ChatUserBubble(child: Text('Summarise the release notes.')), ], ), textScale: 2, width: 360, ); expect(tester.takeException(), isNull); final one = tester.getSize(find.byKey(const Key('one'))).height; expect(one, greaterThan(37), reason: 'the row grows with its text'); debugDefaultTargetPlatformOverride = null; }); testWidgets('icon buttons: 32px on a pointer device, 40px target on touch', ( tester, ) async { Widget button() => IconButton( key: const Key('b'), onPressed: () {}, icon: const Icon(Icons.add), ); debugDefaultTargetPlatformOverride = TargetPlatform.linux; await pump(tester, Center(child: button())); expect(tester.getSize(find.byKey(const Key('b'))), const Size(32, 32)); debugDefaultTargetPlatformOverride = TargetPlatform.android; await pump(tester, Center(child: button())); expect(tester.getSize(find.byKey(const Key('b'))), const Size(40, 40)); debugDefaultTargetPlatformOverride = null; }); testWidgets('the rail is narrow and icon-only, each icon with a tooltip', ( tester, ) async { await pump( tester, Row( children: [ ShellNavigationRail( selected: AppDestination.runs, icon: (d) => Icon(destinationDetails(d).icon), onSelected: (_) {}, ), const Expanded(child: SizedBox()), ], ), width: 1200, ); final rail = find.byKey(const ValueKey('shell.navigation-rail.surface')); expect(tester.getSize(rail).width, DesignDensity.compact.railWidth); expect( tester.widget(find.byType(NavigationRail)).labelType, NavigationRailLabelType.none, ); for (final destination in shellTabDestinations) { expect( find.byTooltip(destinationDetails(destination).label), findsOneWidget, ); } expect(find.byTooltip('Settings'), findsOneWidget); // Settings' indicator matches the tabs' 56x32 rather than the rail. final indicator = find.descendant( of: find.byKey(const ValueKey('shell.destination.settings')), matching: find.byType(Container), ); expect(tester.getSize(indicator.first), const Size(56, 32)); }); testWidgets('the operator bubble is tight, in the design corners', ( tester, ) async { await pump(tester, const ChatUserBubble(child: Text('Ship it'))); final material = tester.widget( find.descendant( of: find.byType(ChatUserBubble), matching: find.byType(Material), ), ); final shape = material.shape! as RoundedRectangleBorder; expect(shape.borderRadius, BorderRadius.circular(6)); final padding = tester.widget( find.descendant( of: find.byType(ChatUserBubble), matching: find.byType(Padding), ), ); expect( padding.padding, const EdgeInsets.symmetric(horizontal: 12, vertical: 8), ); final gap = chatParagraphGap(tester.element(find.text('Ship it')), 14); expect(gap, closeTo(14 * 0.6, 0.01)); }); testWidgets('a floating window has a 32px title bar and 6px corners', ( tester, ) async { late BuildContext context; await pump( tester, Builder( builder: (c) { context = c; return const SizedBox(); }, ), ); expect(windowTitleBarHeight(context), 32); expect(windowCorners(context), BorderRadius.circular(6)); await pump( tester, Builder( builder: (c) { context = c; return const SizedBox(); }, ), design: AppDesign.paper, ); expect(windowTitleBarHeight(context), 40); expect(windowCorners(context), BorderRadius.circular(windowCornerRadius)); }); }