Files
pipelines/app/test/features/search/search_chat_screen_test.dart
T
alan 9adee6cc60 Remove Cupertino UI branches
Keep the public Cupertino-compatible parameters while retaining only the Material implementations and tests. The app is Material-only, so deleting unreachable Cupertino branches reduces dead code without changing the active path.
2026-11-11 02:41:26 +00:00

116 lines
4.0 KiB
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/search/search_screen.dart';
import 'package:pipelines_app/features/search/ui/search_result_slivers.dart';
import 'search_screen_test.dart'
show ImmediateGateway, field, response, search, useNarrowSurface;
import 'search_test_support.dart' show chatHit;
/// Run hits for every kind but chat; chat hits for the chat request.
JsonMap replies(String query, String kind) => kind == 'chat'
? response([
chatHit('ses_a', title: 'API refactor', snippet: 'the release retry'),
chatHit('ses_b', title: 'Release notes'),
])
: response([field]);
Widget host(Widget child) => MaterialApp(home: child);
void main() {
testWidgets('chat hits lead as a Chats group with title, '
'harness, directory and snippet, and open their chat', (tester) async {
useNarrowSurface(tester);
final gateway = ImmediateGateway(replies);
JsonMap? opened;
await tester.pumpWidget(
host(
SearchScreen(
gateway: gateway,
onOpen: (value) => opened = value,
cupertino: false,
),
),
);
await search(tester, 'release');
expect(gateway.calls.single['search'], {
'query': 'release',
'kind': '',
'limit': 0,
});
expect(gateway.chatCalls.single['search'], {
'query': 'release',
'kind': 'chat',
'limit': 0,
});
expect(find.text('Chats (2)'), findsOneWidget);
expect(find.text('Pipelines and runs'), findsOneWidget);
final chats = tester.getTopLeft(find.byKey(searchChatsSectionKey));
final others = tester.getTopLeft(find.byKey(searchOthersSectionKey));
final chatRow = find.byKey(const ValueKey('search.result.chat:ses_a'));
final runRow = find.byKey(const ValueKey('search.result.run:11:4:output'));
expect(chats.dy, lessThan(tester.getTopLeft(chatRow).dy));
expect(tester.getTopLeft(chatRow).dy, lessThan(others.dy));
expect(others.dy, lessThan(tester.getTopLeft(runRow).dy));
expect(find.text('API refactor'), findsOneWidget);
expect(find.text('Release notes'), findsOneWidget);
expect(
find.textContaining('Chat · Claude Code · /work/api'),
findsNWidgets(2),
);
expect(find.textContaining('the release retry'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(chatRow);
await tester.pump();
expect(opened?['target'], 'chat:ses_a');
expect((opened?['chat'] as Map)['session_id'], 'ses_a');
});
testWidgets('Chats selected alone lists chats without group headings', (
tester,
) async {
useNarrowSurface(tester);
final gateway = ImmediateGateway(replies);
await tester.pumpWidget(
MaterialApp(
home: SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false),
),
);
await search(tester, 't:chat release');
expect(gateway.calls, isEmpty);
expect(gateway.chatCalls, hasLength(1));
expect(find.text('API refactor'), findsOneWidget);
expect(find.byKey(searchChatsSectionKey), findsNothing);
expect(find.byKey(searchOthersSectionKey), findsNothing);
});
testWidgets('an older server without chat search keeps its run results and '
'says chats were not searched', (tester) async {
useNarrowSurface(tester);
final gateway = ImmediateGateway((query, kind) {
if (kind == 'chat') {
throw StateError('unknown search kind "chat"; use one of pipeline');
}
return response([field]);
});
await tester.pumpWidget(
MaterialApp(
home: SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: false),
),
);
await search(tester, 'release');
expect(
find.byKey(const ValueKey('search.result.run:11:4:output')),
findsOneWidget,
);
expect(find.byKey(searchChatsNoteKey), findsOneWidget);
expect(find.textContaining('does not search chats'), findsOneWidget);
});
}