import 'package:flutter/cupertino.dart'; 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/ui/sessions/chat_sessions_screen.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_session_local.dart'; import 'fake_chat_gateway.dart'; /// In-memory device-local store; widget tests never read real preferences. class MemoryChatSessionLocalStore implements ChatSessionLocalStore { MemoryChatSessionLocalStore([this.state]); ChatSessionLocal? state; @override Future load() async => state ?? const ChatSessionLocal(); @override Future save(ChatSessionLocal next) async => state = next; } List sampleSessions() => [ {'id': 's1', 'title': 'Starred chat', 'directory': '/work', 'starred': true}, {'id': 's2', 'title': 'Open chat', 'directory': '/work'}, {'id': 's3', 'title': 'Elsewhere chat', 'directory': '/else'}, { 'id': 's4', 'title': 'Closed chat', 'directory': '/else', 'closed_at': '2026-01-01', }, { 'id': 's5', 'title': 'Starred closed', 'directory': '/work', 'starred': true, 'closed_at': '2026-01-02', }, ]; Future pumpMaterialChat( WidgetTester tester, FakeChatGateway gateway, { ValueChanged? onOpen, }) async { await tester.pumpWidget( MaterialApp( theme: ThemeData(platform: TargetPlatform.android), home: ChatSessionsScreen( gateway: gateway, onOpen: onOpen ?? (_) {}, localStore: MemoryChatSessionLocalStore(), ), ), ); await tester.pumpAndSettle(); } Future pumpCupertinoChat( WidgetTester tester, FakeChatGateway gateway, { ValueChanged? onOpen, }) async { await tester.pumpWidget( CupertinoApp( home: ChatSessionsScreen( gateway: gateway, onOpen: onOpen ?? (_) {}, localStore: MemoryChatSessionLocalStore(), ), ), ); await tester.pumpAndSettle(); } /// The screen's iOS/macOS path: Cupertino controls under the app's ordinary /// `MaterialApp` root, with no Material or CupertinoTheme ancestor. Future pumpIosMaterialChat( WidgetTester tester, FakeChatGateway gateway, { ValueChanged? onOpen, }) async { await tester.pumpWidget( MaterialApp( theme: ThemeData(platform: TargetPlatform.iOS), home: ChatSessionsScreen( gateway: gateway, onOpen: onOpen ?? (_) {}, localStore: MemoryChatSessionLocalStore(), ), ), ); await tester.pumpAndSettle(); } /// Narrows the test surface to a phone so long messages must wrap. void usePhoneSurface(WidgetTester tester) { tester.view.physicalSize = const Size(390, 844); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); } /// The project's smallest supported acceptance size with 2x text. void useSmallTextSurface(WidgetTester tester) { tester.view.physicalSize = const Size(320, 640); tester.view.devicePixelRatio = 1; tester.platformDispatcher.textScaleFactorTestValue = 2; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); }