Files
pipelines/app/test/features/pipelines/pipelines_controller_load_test.dart
T
alan a44f31b989 feat(app): add native pipelines list and detail screen
Read-only Pipelines screen for the Flutter client:

- list_pipelines and list_runs with a last-run join, plus get_pipeline
  with an explicit version (0 = latest); no mutation requests.
- Name, run-presence, last-run-status and schedule filters; six sort
  orders; clear filters; truthful loading, empty and error states.
- Detail Summary, selectable Source and version history with selection
  and return to latest.
- Sequenced list/detail requests so stale replies cannot replace a newer
  selection or open a cleared one; refresh keeps the selected pipeline
  and version.
- Material controls on Android/desktop and Cupertino on iOS; a
  per-label segmented tab row at narrow widths and scaled text, with the
  native control kept wherever an equal share fits.
- Fixture probe entry and Chrome scripts for the rendered evidence;
  widget tests cover filters, sorting, formatting, sequencing, layout
  and the tab row.

Graph rendering remains P2: the Graph tab states that it is pending and
exposes a host hook. PipelinesScreen is not yet registered in the shell.

Evidence and limits: app/notes/P1.md.
2026-10-21 19:09:29 +01:00

164 lines
5.7 KiB
Dart

import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/pipelines/pipeline_query.dart';
import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
import 'fixtures.dart';
PipelinesController controllerFor(FakeGateway gateway) =>
PipelinesController(PipelinesRepository(gateway));
Future<void> settle() => Future<void>.delayed(Duration.zero);
void main() {
test(
'load sends exact list and runs requests and parses the envelopes',
() async {
final fixture = PipelineFixture();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(fixture.summaries),
'list_runs' => runListReply(fixture.runs),
_ => errorReply('unexpected $type'),
},
);
final controller = controllerFor(gateway);
await controller.load();
expect(gateway.calls.map((call) => call.type).toList(), [
'list_pipelines',
'list_runs',
]);
expect(gateway.calls[0].fields, isEmpty);
expect(gateway.calls[1].fields, isEmpty);
expect(controller.pipelines.map((pipeline) => pipeline.id), [1, 2, 3]);
expect(controller.pipelinesLoaded, isTrue);
expect(controller.runsLoaded, isTrue);
expect(controller.latestRuns[1]?.id, 42);
expect(controller.listError, isNull);
expect(controller.runsError, isNull);
},
);
test('refresh keeps the selected pipeline and requested version', () async {
final fixture = PipelineFixture();
final summaries = List<Map<String, dynamic>>.of(fixture.summaries);
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(summaries),
'list_runs' => runListReply(fixture.runs),
'get_pipeline' => pipelineDetailReply(
fixture.detailFor(
fields['pipeline_id'] as int,
fields['version'] as int,
)!,
),
_ => errorReply('unexpected $type'),
},
);
final controller = controllerFor(gateway);
await controller.load();
await controller.openPipeline(2, version: 1);
summaries[1] = pipelineSummary(id: 2, name: 'Beta deploy renamed');
await controller.load();
expect(controller.selectedId, 2);
expect(controller.selectedVersion, 1);
expect(controller.detail?.id, 2);
expect(controller.pipelines[1].name, 'Beta deploy renamed');
expect(gateway.callsOf('get_pipeline').last.fields, {
'pipeline_id': 2,
'version': 1,
});
});
test(
'server refusals are shown verbatim and a list failure is retryable',
() async {
final gateway = FakeGateway(
(type, fields) => errorReply('server offline'),
);
final controller = controllerFor(gateway);
await controller.load();
expect(controller.listError, 'server offline');
expect(controller.pipelinesLoaded, isFalse);
expect(controller.runsError, 'server offline');
},
);
test('a runs failure is truthful without discarding pipelines', () async {
final fixture = PipelineFixture();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(fixture.summaries),
'list_runs' => errorReply('runs unavailable'),
_ => errorReply('unexpected $type'),
},
);
final controller = controllerFor(gateway);
await controller.load();
expect(controller.pipelinesLoaded, isTrue);
expect(controller.pipelines, isNotEmpty);
expect(controller.runsLoaded, isFalse);
expect(controller.runsError, 'runs unavailable');
});
test('run facets wait for a known run history', () async {
final fixture = PipelineFixture();
final runsReply = Completer<Map<String, dynamic>>();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(fixture.summaries),
'list_runs' => runsReply.future,
_ => errorReply('unexpected $type'),
},
);
final controller = controllerFor(gateway);
controller.setFilters(const PipelineFilters(presence: RunPresence.noRuns));
final loading = controller.load();
await settle();
expect(controller.pipelinesLoaded, isTrue);
expect(controller.runsLoaded, isFalse);
expect(controller.visiblePipelines.length, 3);
runsReply.complete(runListReply(fixture.runs));
await loading;
expect(controller.runsLoaded, isTrue);
expect(controller.visiblePipelines.map((pipeline) => pipeline.id), [3]);
});
test('a stale list refresh cannot overwrite newer rows', () async {
final first = Completer<Map<String, dynamic>>();
final second = Completer<Map<String, dynamic>>();
var listCalls = 0;
final gateway = FakeGateway((type, fields) {
if (type == 'list_runs') return runListReply(const []);
if (type == 'list_pipelines') {
listCalls++;
return listCalls == 1 ? first.future : second.future;
}
return errorReply('unexpected $type');
});
final controller = controllerFor(gateway);
final firstLoad = controller.load();
final secondLoad = controller.load();
second.complete(pipelineListReply([pipelineSummary(id: 2, name: 'Newer')]));
await secondLoad;
first.complete(pipelineListReply([pipelineSummary(id: 1, name: 'Older')]));
await firstLoad;
expect(controller.pipelines.single.name, 'Newer');
expect(controller.listLoading, isFalse);
});
test('pipeline errors keep a readable message', () {
expect(
pipelineErrorMessage(const PipelineRequestException('exact refusal')),
'exact refusal',
);
expect(pipelineErrorMessage(Exception('broken')), 'broken');
});
}