Files
pipelines/app/test/features/search/search_controller_failure_test.dart
T
alan 51140cd3b7 feat(app): add native omni-search screen over the search gateway
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.
2026-10-21 16:41:30 +01:00

91 lines
2.6 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/search/domain/search_controller.dart';
import 'package:pipelines_app/features/search/domain/search_query.dart';
import 'search_test_support.dart';
void main() {
test('a server error is shown, and retry issues a fresh request', () async {
final gateway = QueuedGateway();
final controller = controllerFor(gateway);
addTearDown(controller.dispose);
controller.updateQuery('plan');
await pumpEventQueue();
gateway.fail(0, StateError('server is down'));
await pumpEventQueue();
expect(controller.bodyKind, SearchBodyKind.error);
expect(controller.error, contains('server is down'));
final retry = controller.retry();
await pumpEventQueue();
expect(gateway.calls, hasLength(2));
expect(gateway.lastSearch, {'query': 'plan', 'kind': '', 'limit': 0});
gateway.succeed(
1,
envelope([
{
'kind': 'pipeline',
'target': 'pipeline:7',
'pipeline': {'id': 7},
},
]),
);
await retry;
expect(controller.error, isNull);
expect(controller.results, hasLength(1));
expect(controller.bodyKind, SearchBodyKind.results);
});
test('a stale failure never replaces the newest query state', () async {
final gateway = QueuedGateway();
final controller = controllerFor(gateway);
addTearDown(controller.dispose);
controller.updateQuery('first');
await pumpEventQueue();
controller.updateQuery('second');
await pumpEventQueue();
gateway.fail(0, StateError('stale failure'));
await pumpEventQueue();
expect(controller.error, isNull);
expect(controller.loading, isTrue);
expect(controller.bodyKind, SearchBodyKind.searching);
gateway.succeed(
1,
envelope([
{
'kind': 'pipeline',
'target': 'pipeline:9',
'pipeline': {'id': 9},
},
]),
);
await pumpEventQueue();
expect(controller.error, isNull);
expect(controller.results.single['target'], 'pipeline:9');
expect(controller.bodyKind, SearchBodyKind.results);
});
test(
'a missing search_results payload reports the unsupported copy',
() async {
final gateway = QueuedGateway();
final controller = controllerFor(gateway);
addTearDown(controller.dispose);
controller.updateQuery('plan');
await pumpEventQueue();
gateway.succeed(0, {'type': 'pong'});
await pumpEventQueue();
expect(controller.bodyKind, SearchBodyKind.error);
expect(controller.error, unsupportedSearchCopy);
},
);
}