165 lines
4.8 KiB
Dart
165 lines
4.8 KiB
Dart
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<void> _pump(
|
|
WidgetTester tester, {
|
|
required bool peek,
|
|
required double reveal,
|
|
double? height,
|
|
}) 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: SizedBox(
|
|
height: height,
|
|
child: 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<ChatTranscriptScrollView>(
|
|
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), 8);
|
|
expect(
|
|
tester.getTopLeft(find.byType(ChatTranscriptScrollView)).dy,
|
|
closeTo(tester.getBottomLeft(header).dy, .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.byWidgetPredicate(
|
|
(widget) => widget is EditableText && !widget.readOnly,
|
|
),
|
|
findsNothing,
|
|
);
|
|
expect(find.byType(EditableText, skipOffstage: false), findsWidgets);
|
|
expect(find.text('Message 0'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets(
|
|
'leaving controls fade and release their viewport height smoothly',
|
|
(tester) async {
|
|
await _pump(tester, peek: true, reveal: .4);
|
|
expect(header, findsOneWidget);
|
|
expect(
|
|
tester.getTopLeft(find.byType(ChatTranscriptScrollView)).dy,
|
|
closeTo(tester.getSize(header).height * .4, .5),
|
|
);
|
|
final fade = tester.widget<FadeTransition>(
|
|
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(
|
|
'a retained peek composer measures naturally in a tiny viewport',
|
|
(tester) async {
|
|
await _pump(tester, peek: true, reveal: 0, height: 60);
|
|
expect(tester.takeException(), isNull);
|
|
expect(
|
|
find.byWidgetPredicate(
|
|
(widget) => widget is EditableText && !widget.readOnly,
|
|
),
|
|
findsNothing,
|
|
);
|
|
expect(
|
|
find.byKey(const ValueKey('chat-composer-s'), skipOffstage: false),
|
|
findsOneWidget,
|
|
);
|
|
},
|
|
);
|
|
|
|
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.byWidgetPredicate(
|
|
(widget) =>
|
|
widget is ChatPaneBarReveal &&
|
|
widget.bar.key == const Key('chat-thread-header'),
|
|
),
|
|
)
|
|
.visitChildren((element) => child = element.widget);
|
|
expect(child?.key, const Key('chat-thread-header'));
|
|
});
|
|
}
|