import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart'; import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/list_detail.dart'; import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; void main() { for (final scale in [1.0, 2.0]) { testWidgets('chat list stays above labeled navigation ($scale)', ( tester, ) async { tester.view.physicalSize = const Size(640, 900); tester.view.devicePixelRatio = 1; tester.platformDispatcher.textScaleFactorTestValue = scale; addTearDown(tester.view.reset); addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); String? opened; final sessions = [ for (var i = 0; i < 14; i++) { 'id': 's$i', 'title': 'Chat item $i', 'model': 'model', 'directory': '/work/project-$i', }, ]; Widget list() => MaterialSessionList( sections: [(title: 'Chats', sessions: sessions)], emptyMessage: null, duplicateTitles: const {}, onOpen: (row) => opened = row['id'] as String, onRename: (_) {}, onClose: (_) {}, onReopen: (_) {}, onStar: (_) {}, onHide: (_) {}, onClearSearch: null, isUnseen: (_) => false, errorFor: (_) => null, ); final shell = AdaptiveShell( destination: AppDestination.chat, destinationBodies: { AppDestination.chat: (_) => ListDetailPanes(list: list(), detail: const SizedBox.expand()), }, ); await tester.pumpWidget(MaterialApp(home: shell)); await tester.pumpAndSettle(); final navigation = tester.getRect( find.byKey(FloatingDestinationBar.rowKey), ); final scrollView = find.byType(CustomScrollView); final viewport = tester.getRect(scrollView); expect(viewport.bottom, lessThanOrEqualTo(navigation.top + .5)); expect(viewport.width, greaterThan(0)); final scrollable = tester.state( find.descendant(of: scrollView, matching: find.byType(Scrollable)), ); scrollable.position.jumpTo(scrollable.position.maxScrollExtent); await tester.pumpAndSettle(); final last = find.byKey(const Key('chat-row-s13')); expect( tester.getRect(last).bottom, lessThanOrEqualTo(navigation.top + .5), ); final metadata = find.descendant( of: last, matching: find.text('model ยท /work/project-13'), ); expect(metadata, findsOneWidget); expect( tester.getRect(metadata).bottom, lessThanOrEqualTo(navigation.top + .5), ); await tester.tap(find.text('Chat item 13')); await tester.pump(); expect(opened, 's13'); final retainedOffset = scrollable.position.pixels; tester.view.physicalSize = const Size(1440, 900); await tester.pumpAndSettle(); expect( tester.state( find.descendant(of: scrollView, matching: find.byType(Scrollable)), ), same(scrollable), ); // The list is narrower at 640 (no rail) than beside the rail, so its // rows re-wrap into a shorter scroll extent: the offset is kept up to // that extent, and no further. final kept = retainedOffset < scrollable.position.maxScrollExtent ? retainedOffset : scrollable.position.maxScrollExtent; expect(scrollable.position.pixels, closeTo(kept, .5)); expect(tester.takeException(), isNull); }); } }