import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/screen.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart'; import 'package:pipelines_app/shell/destination.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'conversation/chat_thread_fixtures.dart'; /// Server recency order: the list shows Starred by name (apple, Zed), then /// Chats by directory (Recent, Second in /w; Other in /v), then Closed folded. const _rows = [ {'id': 'r', 'title': 'Recent', 'directory': '/w'}, {'id': 'd', 'title': 'Other', 'directory': '/v'}, {'id': 'c', 'title': 'Done', 'directory': '/w', 'closed_at': 1}, {'id': 's', 'title': 'Second', 'directory': '/w'}, {'id': 'z', 'title': 'Zed', 'directory': '/w', 'starred': true}, {'id': 'a', 'title': 'apple', 'directory': '/v', 'starred': true}, ]; class _Gateway extends FakeChatGateway { _Gateway(this.rows); final List rows; @override Future call(String type, [JsonMap fields = const {}]) { if (type == 'chat_sessions') { return Future.value({ 'chat_sessions': [ for (final row in rows) {...row}, ], }); } if (type == 'chat_shells') return Future.value({'chat_shells': []}); return super.call(type, fields); } } /// The app's routing: the route names the open chat; selecting one replaces /// the route, Back returns to the list. Future> _pump( WidgetTester tester, Size size, { List rows = _rows, }) async { SharedPreferences.setMockInitialValues({}); tester.view.physicalSize = size; tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); final gateway = _Gateway(rows)..history = (_) async => chatPage(const []); addTearDown(gateway.close); final route = ValueNotifier(null); addTearDown(route.dispose); await tester.pumpWidget( MaterialApp( home: AdaptiveShell( destination: AppDestination.chat, destinationBodies: { AppDestination.chat: (_) => ValueListenableBuilder( valueListenable: route, builder: (context, id, _) => ChatScreen( gateway: gateway, initialSessionId: id, onSessionSelected: (next) => route.value = next, onBack: () => route.value = null, ), ), }, ), ), ); await tester.pumpAndSettle(); return route; } Finder _thread(String id) => find.byKey(ValueKey('chat-thread-$id')); final _next = find.byKey(const Key('chat-next')); void main() { for (final size in [const Size(1280, 800), const Size(390, 844)]) { testWidgets('Next chat is absent from header and More at $size', ( tester, ) async { await _pump(tester, size); await tester.tap(find.byKey(const Key('chat-row-a'))); await tester.pumpAndSettle(); expect(_thread('a'), findsOneWidget); expect(_next, findsNothing); expect(find.byTooltip('Next chat'), findsNothing); await tester.tap(find.byTooltip('More actions').hitTestable().first); await tester.pumpAndSettle(); expect(find.text('Next chat'), findsNothing); expect(find.text('Add chat pane'), findsOneWidget); await tester.pumpWidget(const SizedBox.shrink()); }); } }