import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/chat/conversation/chat_pane_presentation.dart'; import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart'; import 'package:pipelines_app/features/chat/conversation/chat_transcript_scroll_view.dart'; import 'chat_thread_fixtures.dart'; /// The conversation's bar under a workspace presentation: shown for the /// active chat, offstage for a resting peek (whose transcript starts at the /// top), fading out in place while the chat is becoming the peek. Future _pump( WidgetTester tester, { required bool peek, required double reveal, }) async { final gateway = FakeChatGateway(); addTearDown(gateway.close); gateway.history = (_) async => chatPage([ for (var index = 0; index < 4; index++) chatMessage( 'm$index', index.isEven ? 'user' : 'assistant', parts: [ {'type': 'text', 'text': 'Message $index'}, ], ), ]); gateway.subscribe = () async => const {}; await tester.pumpWidget( MaterialApp( home: Scaffold( body: ChatPanePresentation( peek: peek, barReveal: AlwaysStoppedAnimation(reveal), child: ChatThreadView( gateway: gateway, sessionId: 's', title: 'Presented', onBack: () {}, ), ), ), ), ); await tester.pumpAndSettle(); } void main() { final header = find.byKey(const Key('chat-thread-header')); double listTop(WidgetTester tester) => tester .widget( find.byKey(const ValueKey('chat-thread-s')), ) .padding .top; testWidgets('the active chat shows its bar and keeps the list clear', ( tester, ) async { await _pump(tester, peek: false, reveal: 1); expect(header, findsOneWidget); expect(listTop(tester), greaterThan(8)); expect(listTop(tester), closeTo(tester.getSize(header).height + 8, .5)); }); testWidgets('a resting peek keeps its bar offstage and reads from the top', ( tester, ) async { await _pump(tester, peek: true, reveal: 0); expect(header, findsNothing); expect( find.byKey(const Key('chat-thread-header'), skipOffstage: false), findsOneWidget, ); expect(listTop(tester), 8); expect(find.text('Message 0'), findsOneWidget); }); testWidgets('a leaving bar fades in place, keeping the list clear', ( tester, ) async { await _pump(tester, peek: true, reveal: .4); expect(header, findsOneWidget); expect(listTop(tester), closeTo(tester.getSize(header).height + 8, .5)); final fade = tester.widget( find.ancestor(of: header, matching: find.byType(FadeTransition)).first, ); expect(fade.opacity.value, .4); expect( find.ancestor(of: header, matching: find.byType(IgnorePointer)), findsWidgets, ); }); testWidgets('without a presentation the bar is itself', (tester) async { final gateway = FakeChatGateway(); addTearDown(gateway.close); gateway.history = (_) async => chatPage(const []); gateway.subscribe = () async => const {}; await tester.pumpWidget( MaterialApp( home: Scaffold( body: ChatThreadView( gateway: gateway, sessionId: 's', title: 'Alone', onBack: () {}, ), ), ), ); await tester.pumpAndSettle(); expect(header, findsOneWidget); Widget? child; tester .element(find.byType(ChatPaneBarReveal)) .visitChildren((element) => child = element.widget); expect(child?.key, const Key('chat-thread-header')); }); }