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/conversation/chat_question_group.dart'; const _answer = 'Postgres 16 on the managed cluster, with read replicas in both regions ' 'and nightly backups kept for thirty days'; JsonMap _form() => { 'id': 'form-1', 'title': 'Database', 'resolved': true, 'answers': {'q0': _answer}, 'fields': [ { 'key': 'q0', 'title': 'Which database should the release use?', 'type': 'string', 'custom': true, 'options': [ {'value': 'Postgres', 'label': 'Postgres'}, ], }, ], }; final _chip = find.byKey(const ValueKey('chat-question-chip-form-1')); final _answerLine = find.byKey(const ValueKey('chat-question-answer-form-1')); Future _pump(WidgetTester tester) async { await tester.binding.setSurfaceSize(const Size(390, 844)); addTearDown(() => tester.binding.setSurfaceSize(null)); await tester.pumpWidget( MaterialApp( home: Scaffold( body: Align( alignment: AlignmentDirectional.topStart, child: ChatQuestionChip(form: _form()), ), ), ), ); } void main() { test('the summary splits into the question and its outcome', () { final parts = chatQuestionSummaryParts(_form()); expect(parts.question, 'Which database should the release use?'); expect(parts.outcome, _answer); expect( chatQuestionSummary(_form()), 'Which database should the release use? ยท $_answer', ); }); testWidgets('a settled question shows its whole answer on its own line', ( tester, ) async { await _pump(tester); final question = find.text('Which database should the release use?'); expect(question, findsOneWidget); expect(find.text(_answer), findsOneWidget); // The answer wraps in full rather than ellipsizing on the question's line. final answer = tester.widget(_answerLine); expect(answer.maxLines, isNull); expect(answer.overflow, isNot(TextOverflow.ellipsis)); final line = tester.getRect(question); final rect = tester.getRect(_answerLine); expect(rect.top, greaterThanOrEqualTo(line.bottom)); expect(rect.height, greaterThan(line.height * 1.5)); // Both lines start together, after the leading icon. expect(rect.left, line.left); // It is emphasised above the muted question. final context = tester.element(_answerLine); expect(answer.style?.color, Theme.of(context).colorScheme.onSurface); expect(tester.takeException(), isNull); }); testWidgets('its chevron is the expand affordance and turns while open', ( tester, ) async { await _pump(tester); expect(find.byIcon(Icons.expand_less), findsNothing); expect( find.descendant(of: _chip, matching: find.byIcon(Icons.chevron_right)), findsOneWidget, ); double turns() => tester .widget( find.descendant(of: _chip, matching: find.byType(AnimatedRotation)), ) .turns; expect(turns(), 0); await tester.tap(_chip); await tester.pumpAndSettle(); expect(find.byKey(const Key('chat-question-sheet')), findsOneWidget); expect(turns(), 0.25); Navigator.of( tester.element(find.byKey(const Key('chat-question-sheet'))), ).pop(); await tester.pumpAndSettle(); expect(turns(), 0); }); }