feat(app): expose recorded human decisions in native run detail
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/decision_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/screen.dart';
|
||||
|
||||
class _DecisionGateway implements ApiGateway {
|
||||
final events = StreamController<JsonMap>.broadcast();
|
||||
final decisions = <JsonMap>[];
|
||||
final reply = Completer<JsonMap>();
|
||||
final JsonMap run = {
|
||||
'id': 9,
|
||||
'title': 'Human checkpoint',
|
||||
'name': 'fixture',
|
||||
'status': 'waiting',
|
||||
'executing': false,
|
||||
'current_stage': 'gate',
|
||||
'graph': {
|
||||
'stages': [
|
||||
{
|
||||
'key': 'gate',
|
||||
'type': 'human',
|
||||
'edges': {'approve': '#success'},
|
||||
},
|
||||
],
|
||||
},
|
||||
'steps': [
|
||||
{
|
||||
'sequence': 1,
|
||||
'stage': 'gate',
|
||||
'status': 'waiting',
|
||||
'output': {
|
||||
'prompt': 'Please review this recorded checkpoint.',
|
||||
'options': ['approve'],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => events.stream;
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) =>
|
||||
switch (type) {
|
||||
'list_runs' => Future.value({
|
||||
'runs': [run],
|
||||
}),
|
||||
'get_run' => Future.value({'run_detail': run}),
|
||||
'decide_run' => _decide(fields),
|
||||
_ => Future.error(UnsupportedError(type)),
|
||||
};
|
||||
Future<JsonMap> _decide(JsonMap fields) {
|
||||
decisions.add(fields);
|
||||
return reply.future;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'actual detail exposes and confirms recorded decision ($cupertino)',
|
||||
(tester) async {
|
||||
final gateway = _DecisionGateway();
|
||||
addTearDown(gateway.events.close);
|
||||
final screen = RunsScreen(gateway: gateway, initialRunId: 9);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: screen))
|
||||
: MaterialApp(home: Scaffold(body: screen)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(decisionWaitingTitle), findsOneWidget);
|
||||
await tester.tap(find.byKey(decisionActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('Please review this recorded checkpoint.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.text('approve'));
|
||||
await tester.enterText(find.byKey(decisionFeedbackKey), ' checked ');
|
||||
await tester.pump();
|
||||
expect(gateway.decisions, isEmpty);
|
||||
await tester.tap(find.text(decisionConfirmLabel));
|
||||
await tester.pump();
|
||||
expect(gateway.decisions.single, {
|
||||
'run_id': 9,
|
||||
'stage': 'gate',
|
||||
'option': 'approve',
|
||||
'feedback': 'checked',
|
||||
});
|
||||
gateway.reply.complete({
|
||||
'run_detail': {
|
||||
...gateway.run,
|
||||
'status': 'succeeded',
|
||||
'executing': false,
|
||||
},
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(decisionActionKey), findsNothing);
|
||||
expect(find.text(decisionWaitingTitle), findsNothing);
|
||||
expect(find.text('succeeded'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user