51140cd3b7
Pure request/parse/row logic in lib/features/search/domain, a gateway-backed repository, and Material plus Cupertino bodies. The header and rows share one scroll view, and the server's truncation, scan and cap facts stay visible even when a bounded scan returns no matches. Tests cover the exact search envelope, token parsing, stale replies, retry, truncation bounds and platform layouts. A Web-only fixture and CDP probe support rendered verification; the screen is not yet registered in the shell.
107 lines
3.0 KiB
Dart
107 lines
3.0 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/search/data/search_repository.dart';
|
|
import 'package:pipelines_app/features/search/domain/search_models.dart';
|
|
|
|
class RecordingGateway implements ApiGateway {
|
|
String? type;
|
|
JsonMap fields = {};
|
|
JsonMap reply = {};
|
|
Object? failure;
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
|
this.type = type;
|
|
this.fields = Map.of(fields);
|
|
if (failure case final error?) throw error;
|
|
return reply;
|
|
}
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
}
|
|
|
|
void main() {
|
|
test(
|
|
'search sends exactly search/query/kind/limit and parses bounds',
|
|
() async {
|
|
final gateway = RecordingGateway()
|
|
..reply = {
|
|
'search_results': {
|
|
'query': 'plan',
|
|
'kind': 'run',
|
|
'results': [
|
|
{
|
|
'kind': 'run',
|
|
'target': 'run:11',
|
|
'run': {'id': 11},
|
|
},
|
|
],
|
|
'truncated': true,
|
|
'scanned_steps': 27,
|
|
'scanned_bytes': 4096,
|
|
'cap': 50,
|
|
'scan_bound_bytes': 1048576,
|
|
},
|
|
};
|
|
final repository = SearchRepository(gateway);
|
|
|
|
final response = await repository.search(
|
|
query: 'plan',
|
|
kind: SearchKind.run,
|
|
);
|
|
|
|
expect(gateway.type, 'search');
|
|
expect(gateway.fields, {
|
|
'search': {'query': 'plan', 'kind': 'run', 'limit': 0},
|
|
});
|
|
expect(response, isNotNull);
|
|
expect(response!.query, 'plan');
|
|
expect(response.kind, SearchKind.run);
|
|
expect(response.results.single['target'], 'run:11');
|
|
expect(response.truncated, isTrue);
|
|
expect(response.scannedSteps, 27);
|
|
expect(response.scannedBytes, 4096);
|
|
expect(response.cap, 50);
|
|
expect(response.scanBoundBytes, 1048576);
|
|
},
|
|
);
|
|
|
|
test('all-kinds search still sends the empty kind field', () async {
|
|
final gateway = RecordingGateway()
|
|
..reply = {
|
|
'search_results': {'results': <JsonMap>[]},
|
|
};
|
|
await SearchRepository(gateway).search(query: 'plan', kind: SearchKind.all);
|
|
expect(gateway.fields, {
|
|
'search': {'query': 'plan', 'kind': '', 'limit': 0},
|
|
});
|
|
});
|
|
|
|
test(
|
|
'a reply without search_results is null, not an empty success',
|
|
() async {
|
|
final gateway = RecordingGateway()..reply = {'type': 'pong'};
|
|
final response = await SearchRepository(
|
|
gateway,
|
|
).search(query: 'plan', kind: SearchKind.all);
|
|
expect(response, isNull);
|
|
},
|
|
);
|
|
|
|
test('server refusals propagate to the caller unchanged', () async {
|
|
final gateway = RecordingGateway()
|
|
..failure = StateError('permission denied');
|
|
await expectLater(
|
|
SearchRepository(gateway).search(query: 'plan', kind: SearchKind.all),
|
|
throwsA(
|
|
isA<StateError>().having(
|
|
(error) => error.message,
|
|
'message',
|
|
'permission denied',
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|