Files
pipelines/app/test/features/search/search_bar_layout_test.dart
T
alan 06f6eda360 Merge branch 'worktree-agent-a82ec5e9fdf8ca159' into integrate/gaps-e
# Conflicts:
#	app/test/features/search/search_bar_layout_test.dart
2026-10-31 04:31:13 +00:00

210 lines
7.3 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/search/search_screen.dart';
import 'package:pipelines_app/features/search/ui/search_bar_controls.dart';
import 'package:pipelines_app/features/search/ui/search_bounds_note.dart';
import 'package:pipelines_app/features/search/ui/search_layout.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
import 'search_screen_test.dart'
show ImmediateGateway, field, pipeline, response;
void _size(WidgetTester tester, double width) {
tester.view.physicalSize = Size(width, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
}
Future<void> _search(WidgetTester tester, String query) async {
await tester.enterText(find.byKey(searchFieldKey), query);
await tester.pump(const Duration(milliseconds: 300));
await tester.pumpAndSettle();
}
Widget _app(bool cupertino, Widget child) =>
cupertino ? CupertinoApp(home: child) : MaterialApp(home: child);
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host: the field, Kind and help live in the bar pill', (
tester,
) async {
_size(tester, 390);
final gateway = ImmediateGateway((_, _) => response([pipeline]));
await tester.pumpWidget(
_app(
cupertino,
SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino),
),
);
for (final key in [searchFieldKey, searchKindKey, searchHelpKey]) {
expect(
find.descendant(
of: find.byType(SegmentedBar),
matching: find.byKey(key),
),
findsOneWidget,
reason: '$key is in the bar',
);
}
// One field per platform: no elevated SearchBar, no dropdown.
expect(find.byType(SearchBar), findsNothing);
expect(find.byType(DropdownButton), findsNothing);
expect(
find.byType(CupertinoSearchTextField),
cupertino ? findsOneWidget : findsNothing,
);
// The syntax help is behind the info button, not on the page.
expect(find.text(searchTokenHint), findsNothing);
await tester.tap(find.byKey(searchHelpKey));
await tester.pumpAndSettle();
expect(find.text(searchTokenHint), findsOneWidget);
});
testWidgets('$host: stats appear only for a truncated answer', (
tester,
) async {
_size(tester, 390);
var truncated = false;
final gateway = ImmediateGateway((_, _) {
final reply = response([pipeline]);
(reply['search_results'] as Map)['truncated'] = truncated;
return reply;
});
await tester.pumpWidget(
_app(
cupertino,
SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino),
),
);
await _search(tester, 'release');
expect(find.text('Release planner'), findsOneWidget);
expect(find.byKey(searchBoundsKey), findsNothing);
expect(find.textContaining('scanned'), findsNothing);
truncated = true;
await _search(tester, 'releases');
expect(find.byKey(searchBoundsKey), findsOneWidget);
expect(find.textContaining('Results truncated'), findsOneWidget);
});
testWidgets('$host: rows are the shared row: title, kind-led line', (
tester,
) async {
_size(tester, 390);
final gateway = ImmediateGateway((_, _) => response([field]));
await tester.pumpWidget(
_app(
cupertino,
SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino),
),
);
await _search(tester, 'release');
final row = find.byKey(const ValueKey('search.result.run:11:4:output'));
expect(row, findsOneWidget);
expect(tester.widget<AppListRow>(row).cupertino, cupertino);
// The kind leads the one muted line, before the snippet.
expect(
find.descendant(of: row, matching: find.textContaining('Field · ')),
findsOneWidget,
);
expect(
find.descendant(
of: row,
matching: find.textContaining('the release is ready'),
),
findsOneWidget,
);
});
testWidgets('$host: results run behind the bar in a capped column', (
tester,
) async {
_size(tester, 1200);
final gateway = ImmediateGateway((_, _) => response([pipeline]));
await tester.pumpWidget(
_app(
cupertino,
SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino),
),
);
await _search(tester, 'release');
// The scroll view reaches the top edge; its first row starts below
// the floating bar.
final scroll = find.byType(CustomScrollView);
expect(tester.getTopLeft(scroll).dy, 0);
final barBottom = tester.getBottomLeft(find.byType(SegmentedBar)).dy;
final row = find.byKey(const ValueKey('search.result.pipeline:7'));
expect(tester.getTopLeft(row).dy, greaterThanOrEqualTo(barBottom - 8));
// Start-aligned under the bar's inset, no wider than the cap.
final rect = tester.getRect(row);
expect(rect.left, greaterThanOrEqualTo(kSearchContentInset));
expect(rect.right, lessThanOrEqualTo(kSearchContentInset + 840));
// The search pill keeps to its own cap on a wide window.
expect(
tester.getSize(find.byKey(searchBarControlsKey)).width,
lessThanOrEqualTo(kSearchPillMaxWidth),
);
});
for (final width in [390.0, 1200.0]) {
testWidgets('$host: at $width the field takes the title\'s place and '
'the results line up with it', (tester) async {
_size(tester, width);
final gateway = ImmediateGateway((_, _) => response([pipeline]));
await tester.pumpWidget(
_app(
cupertino,
SearchScreen(
gateway: gateway,
onOpen: (_) {},
cupertino: cupertino,
),
),
);
await _search(tester, 'release');
final bar = find.byType(SegmentedBar);
// No Search title pill: the field's pill is the bar's only piece.
expect(
find.descendant(of: bar, matching: find.text('Search')),
findsNothing,
);
expect(
find.descendant(of: bar, matching: find.byType(GlassPill)),
findsOneWidget,
);
final pill = tester.getRect(
find.descendant(of: bar, matching: find.byType(GlassPill)),
);
expect(pill.left, kSearchContentInset);
expect(
pill.width,
width - 2 * kSearchContentInset < kSearchPillMaxWidth
? width - 2 * kSearchContentInset
: kSearchPillMaxWidth,
);
// The field fills the pill beside Kind and the help.
final field = tester.getRect(find.byKey(searchFieldKey));
expect(field.width, greaterThan(pill.width * 0.6));
// The result column shares the pill's edges.
final row = tester.getRect(
find.byKey(const ValueKey('search.result.pipeline:7')),
);
expect(row.left, pill.left);
expect(row.right, pill.right);
});
}
}
}