9551eceaed
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
192 lines
5.6 KiB
Dart
192 lines
5.6 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';
|
|
|
|
class ImmediateGateway implements ApiGateway {
|
|
ImmediateGateway(this.reply);
|
|
|
|
final JsonMap Function(String query, String kind) reply;
|
|
final calls = <JsonMap>[];
|
|
|
|
/// The `kind: chat` searches sent beside the others.
|
|
final chatCalls = <JsonMap>[];
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
|
final search = Map<String, dynamic>.from(fields['search'] as Map);
|
|
(search['kind'] == 'chat' ? chatCalls : calls).add(Map.of(fields));
|
|
return reply(search['query'] as String, search['kind'] as String);
|
|
}
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
}
|
|
|
|
class FailingThenSucceedingGateway implements ApiGateway {
|
|
FailingThenSucceedingGateway(this.success);
|
|
|
|
final JsonMap success;
|
|
var calls = 0;
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
|
final search = fields['search'];
|
|
if (search is Map && search['kind'] == 'chat') return success;
|
|
calls++;
|
|
if (calls == 1) throw StateError('unknown command: search');
|
|
return success;
|
|
}
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
}
|
|
|
|
JsonMap hit({
|
|
required String kind,
|
|
required String target,
|
|
required Map<String, dynamic> payload,
|
|
}) => {'kind': kind, 'target': target, ...payload};
|
|
|
|
JsonMap response(List<JsonMap> results) => {
|
|
'search_results': {
|
|
'results': results,
|
|
'truncated': false,
|
|
'scanned_steps': 4,
|
|
'scanned_bytes': 512,
|
|
'cap': 50,
|
|
'scan_bound_bytes': 1 << 20,
|
|
},
|
|
};
|
|
|
|
final pipeline = hit(
|
|
kind: 'pipeline',
|
|
target: 'pipeline:7',
|
|
payload: {
|
|
'pipeline': {'id': 7, 'name': 'Release planner', 'version': 3, 'stages': 4},
|
|
},
|
|
);
|
|
final field = hit(
|
|
kind: 'field',
|
|
target: 'run:11:4:output',
|
|
payload: {
|
|
'matched_field': 'output',
|
|
'field': {
|
|
'run_id': 11,
|
|
'sequence': 4,
|
|
'field': 'output',
|
|
'snippet': 'the release is ready',
|
|
},
|
|
},
|
|
);
|
|
|
|
void useNarrowSurface(WidgetTester tester) {
|
|
tester.view.physicalSize = const Size(390, 844);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
}
|
|
|
|
Widget largeText(Widget child) => MediaQuery(
|
|
data: const MediaQueryData(textScaler: TextScaler.linear(2)),
|
|
child: child,
|
|
);
|
|
|
|
Future<void> search(WidgetTester tester, String query) async {
|
|
await tester.enterText(find.byKey(const ValueKey('search.field')), query);
|
|
await tester.pump(const Duration(milliseconds: 300));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
void main() {
|
|
for (final width in [390.0, 1000.0]) {
|
|
testWidgets(
|
|
'Material search is native and usable at width $width and 2x text',
|
|
(tester) async {
|
|
useNarrowSurface(tester);
|
|
tester.view.physicalSize = Size(width, 844);
|
|
final gateway = ImmediateGateway((_, _) => response([pipeline, field]));
|
|
JsonMap? opened;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: largeText(
|
|
SearchScreen(gateway: gateway, onOpen: (value) => opened = value),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(find.byType(SearchBar), findsNothing);
|
|
expect(find.byType(TextField), findsOneWidget);
|
|
expect(find.byKey(const ValueKey('search.kind')), findsOneWidget);
|
|
expect(find.byTooltip('Kind: All kinds'), findsOneWidget);
|
|
expect(gateway.calls, isEmpty);
|
|
|
|
await search(tester, 'release');
|
|
|
|
expect(gateway.calls.single, {
|
|
'search': {'query': 'release', 'kind': '', 'limit': 0},
|
|
});
|
|
expect(find.text('Release planner'), findsOneWidget);
|
|
expect(find.textContaining('the release is ready'), findsOneWidget);
|
|
expect(find.textContaining('4 results'), findsNothing);
|
|
expect(tester.takeException(), isNull);
|
|
|
|
await tester.tap(
|
|
find.byKey(const ValueKey('search.result.pipeline:7')),
|
|
);
|
|
expect(opened?['target'], 'pipeline:7');
|
|
expect(opened?['kind'], 'pipeline');
|
|
},
|
|
);
|
|
}
|
|
|
|
testWidgets('a read-only hit cannot be opened', (tester) async {
|
|
useNarrowSurface(tester);
|
|
final unknown = hit(
|
|
kind: 'future_kind',
|
|
target: 'widget:7',
|
|
payload: const {},
|
|
);
|
|
final gateway = ImmediateGateway((_, _) => response([unknown]));
|
|
JsonMap? opened;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: SearchScreen(gateway: gateway, onOpen: (value) => opened = value),
|
|
),
|
|
);
|
|
await search(tester, 'widget');
|
|
|
|
expect(find.textContaining('read-only'), findsOneWidget);
|
|
await tester.tap(find.byKey(const ValueKey('search.result.widget:7')));
|
|
expect(opened, isNull);
|
|
});
|
|
|
|
testWidgets('an unsupported server shows its sentence and retry recovers', (
|
|
tester,
|
|
) async {
|
|
useNarrowSurface(tester);
|
|
final gateway = FailingThenSucceedingGateway(response([pipeline]));
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: SearchScreen(gateway: gateway, onOpen: (_) {}),
|
|
),
|
|
);
|
|
await search(tester, 'release');
|
|
|
|
expect(
|
|
find.text(
|
|
'This server does not support search. Update the Pipelines server, then try again.',
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.byKey(const ValueKey('search.retry')), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(const ValueKey('search.retry')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.calls, 2);
|
|
expect(find.text('Release planner'), findsOneWidget);
|
|
expect(find.byKey(const ValueKey('search.retry')), findsNothing);
|
|
});
|
|
}
|