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.
119 lines
3.8 KiB
Dart
119 lines
3.8 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/search/domain/search_models.dart';
|
|
import 'package:pipelines_app/features/search/domain/search_query.dart';
|
|
|
|
const unsupported =
|
|
'This server does not support search. Update the Pipelines server, then try again.';
|
|
|
|
void main() {
|
|
test('kind vocabulary is exactly the server vocabulary, All kinds first', () {
|
|
expect(SearchKind.values.map((kind) => kind.wire), [
|
|
'',
|
|
'pipeline',
|
|
'run',
|
|
'step',
|
|
'field',
|
|
'artifact',
|
|
'version',
|
|
]);
|
|
expect(SearchKind.values.map((kind) => kind.label), [
|
|
'All kinds',
|
|
'Pipelines',
|
|
'Runs',
|
|
'Steps',
|
|
'Fields',
|
|
'Artifacts',
|
|
'Versions',
|
|
]);
|
|
expect(SearchKind.fromWire('run'), SearchKind.run);
|
|
expect(SearchKind.fromWire(''), SearchKind.all);
|
|
expect(SearchKind.fromWire('prompts'), SearchKind.all);
|
|
expect(SearchKind.fromWire(null), SearchKind.all);
|
|
});
|
|
|
|
test('both type aliases and kinds are case insensitive', () {
|
|
for (final kind in SearchKind.values.where(
|
|
(kind) => kind != SearchKind.all,
|
|
)) {
|
|
for (final prefix in ['t', 'type', 'T', 'TyPe']) {
|
|
final parsed = parseSearchQuery(
|
|
'$prefix:${kind.wire.toUpperCase()} plan',
|
|
);
|
|
expect(parsed.query, ' plan');
|
|
expect(parsed.kind, kind);
|
|
expect(parsed.hasType, isTrue);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('normal, quoted and unsupported text is preserved byte for byte', () {
|
|
const preserved = [
|
|
' ordinary text\twith\nspacing ',
|
|
'"t:pipeline" "hello world"',
|
|
"'type:artifact'",
|
|
'"escaped \\" t:run"',
|
|
'"unclosed t:run',
|
|
't:prompt type:unknown t: t:PIPELINES',
|
|
'not:t:run t:run,',
|
|
'prefix"t:run"',
|
|
'\\t:run',
|
|
];
|
|
for (final query in preserved) {
|
|
final parsed = parseSearchQuery(query, SearchKind.field);
|
|
expect(parsed.query, query);
|
|
expect(parsed.kind, SearchKind.field);
|
|
expect(parsed.hasType, isFalse);
|
|
}
|
|
expect(
|
|
parseSearchQuery('t:artifact "t:pipeline" report').query,
|
|
' "t:pipeline" report',
|
|
);
|
|
});
|
|
|
|
test('last supported token wins over the selector; unknown tokens stay', () {
|
|
final parsed = parseSearchQuery(
|
|
't:run plan TYPE:artifact t:unknown',
|
|
SearchKind.pipeline,
|
|
);
|
|
expect(parsed.query, ' plan t:unknown');
|
|
expect(parsed.kind, SearchKind.artifact);
|
|
expect(parsed.hasType, isTrue);
|
|
expect(parseSearchQuery('plan', SearchKind.step).kind, SearchKind.step);
|
|
});
|
|
|
|
test('type-only query is distinguishable from literal and blank input', () {
|
|
final typed = parseSearchQuery('t:pipeline');
|
|
expect(typed.query, '');
|
|
expect(typed.kind, SearchKind.pipeline);
|
|
expect(typed.hasType, isTrue);
|
|
final blank = parseSearchQuery('');
|
|
expect(blank.query, '');
|
|
expect(blank.kind, SearchKind.all);
|
|
expect(blank.hasType, isFalse);
|
|
});
|
|
|
|
test('blank text is sendable only with a supported nonempty kind', () {
|
|
for (final kind in SearchKind.values) {
|
|
expect(searchQuerySendable(' \n\t ', kind), kind != SearchKind.all);
|
|
}
|
|
expect(searchQuerySendable('', SearchKind.all), isFalse);
|
|
expect(searchQuerySendable('plan', SearchKind.all), isTrue);
|
|
expect(searchQuerySendable(' plan ', SearchKind.all), isTrue);
|
|
});
|
|
|
|
test(
|
|
'failure copy distinguishes an unsupported server from a plain error',
|
|
() {
|
|
expect(searchFailureText(null), unsupported);
|
|
expect(searchFailureText(' '), unsupported);
|
|
expect(searchFailureText('unknown command: search'), unsupported);
|
|
expect(searchFailureText('unsupported command'), unsupported);
|
|
expect(searchFailureText('boom'), 'boom');
|
|
expect(
|
|
searchFailureText('request timed out after 30000ms'),
|
|
'request timed out after 30000ms',
|
|
);
|
|
},
|
|
);
|
|
}
|