Files
pipelines/app/test/features/pipelines/pipelines_controller_detail_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

154 lines
5.2 KiB
Dart

import 'dart:async';
import 'package:flutter_test/flutter_test.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));
void main() {
test(
'opening a pipeline requests the row version and parses detail',
() async {
final fixture = PipelineFixture();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(fixture.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(1, version: 2);
expect(gateway.callsOf('get_pipeline').single.fields, {
'pipeline_id': 1,
'version': 2,
});
expect(controller.detail?.id, 1);
expect(controller.detail?.resolvedVersion, 2);
expect(controller.selectedVersion, 2);
},
);
test('a stale detail reply cannot replace the newer selection', () async {
final fixture = PipelineFixture();
final first = Completer<Map<String, dynamic>>();
final second = Completer<Map<String, dynamic>>();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(fixture.summaries),
'list_runs' => runListReply(fixture.runs),
'get_pipeline' =>
fields['pipeline_id'] == 1 ? first.future : second.future,
_ => errorReply('unexpected $type'),
},
);
final controller = controllerFor(gateway);
await controller.load();
final firstRequest = controller.openPipeline(1, version: 2);
final secondRequest = controller.openPipeline(2, version: 1);
expect(controller.selectedId, 2);
first.complete(pipelineDetailReply(fixture.details[0]));
await firstRequest;
expect(
controller.detail,
isNull,
reason: 'the late reply belongs to the discarded selection',
);
expect(controller.detailLoading, isTrue);
second.complete(pipelineDetailReply(fixture.details[1]));
await secondRequest;
expect(controller.detail?.id, 2);
expect(controller.detail?.name, 'Beta deploy');
});
test('a late reply after Back cannot reopen the cleared detail', () async {
final fixture = PipelineFixture();
final reply = Completer<Map<String, dynamic>>();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(fixture.summaries),
'list_runs' => runListReply(fixture.runs),
'get_pipeline' => reply.future,
_ => errorReply('unexpected $type'),
},
);
final controller = controllerFor(gateway);
await controller.load();
final request = controller.openPipeline(1, version: 2);
controller.clearSelection();
reply.complete(pipelineDetailReply(fixture.details[0]));
await request;
expect(controller.detail, isNull);
expect(controller.selectedId, isNull);
});
test(
'version selection requests that exact version and latest again',
() async {
final fixture = PipelineFixture();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(fixture.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(1, version: 2);
await controller.selectVersion(1);
expect(controller.selectedVersion, 1);
expect(controller.detail?.source, contains('# selected version 1'));
expect(gateway.callsOf('get_pipeline').last.fields, {
'pipeline_id': 1,
'version': 1,
});
await controller.selectVersion(0);
expect(controller.selectedVersion, 0);
expect(gateway.callsOf('get_pipeline').last.fields, {
'pipeline_id': 1,
'version': 0,
});
},
);
test('a detail refusal keeps the selection and names the reason', () async {
final fixture = PipelineFixture();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(fixture.summaries),
'list_runs' => runListReply(fixture.runs),
'get_pipeline' => errorReply('pipeline 9 was not found'),
_ => errorReply('unexpected $type'),
},
);
final controller = controllerFor(gateway);
await controller.load();
await controller.openPipeline(9);
expect(controller.detailError, 'pipeline 9 was not found');
expect(controller.selectedId, 9);
});
}