364fd5b538
Keep the Material-only run action behavior while preserving public Cupertino parameters for callers that will be cleaned up separately. Narrow the related tests to the supported Material path.
91 lines
2.4 KiB
Dart
91 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/runs/actions/cancel_run_action.dart';
|
|
|
|
typedef CancelHandler = Future<JsonMap> Function(String type, JsonMap fields);
|
|
|
|
/// A fake gateway that records every request and never owns a socket.
|
|
class FakeCancelGateway implements ApiGateway {
|
|
FakeCancelGateway(this.handler);
|
|
|
|
final CancelHandler handler;
|
|
final List<({String type, JsonMap fields})> calls = [];
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
|
final copy = Map<String, dynamic>.from(fields);
|
|
calls.add((type: type, fields: copy));
|
|
return handler(type, copy);
|
|
}
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
}
|
|
|
|
JsonMap executingRun({
|
|
num id = 7,
|
|
bool executing = true,
|
|
String status = 'running',
|
|
int exportPending = 0,
|
|
bool cancelRequested = false,
|
|
bool cleanupUnconfirmed = false,
|
|
}) => {
|
|
'id': id,
|
|
'title': 'Nightly build',
|
|
'status': status,
|
|
'executing': executing,
|
|
'export_pending_sequence': exportPending,
|
|
'cancel_requested': cancelRequested,
|
|
'cleanup_unconfirmed': cleanupUnconfirmed,
|
|
};
|
|
|
|
JsonMap acceptedCancelRun() =>
|
|
executingRun(executing: false, status: 'canceled', cancelRequested: true);
|
|
|
|
/// Owns the run like a run-detail screen would, so the callback's returned
|
|
/// server detail is what the action renders next.
|
|
class CancelHost extends StatefulWidget {
|
|
const CancelHost({
|
|
super.key,
|
|
required this.gateway,
|
|
required this.initial,
|
|
required this.changed,
|
|
});
|
|
|
|
final FakeCancelGateway gateway;
|
|
final JsonMap initial;
|
|
final List<JsonMap> changed;
|
|
|
|
@override
|
|
State<CancelHost> createState() => _CancelHostState();
|
|
}
|
|
|
|
class _CancelHostState extends State<CancelHost> {
|
|
late JsonMap _run = widget.initial;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CancelRunAction(
|
|
run: _run,
|
|
gateway: widget.gateway,
|
|
onRunChanged: (run) {
|
|
widget.changed.add(run);
|
|
setState(() => _run = run);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget cancelApp(Widget child, {double textScale = 1}) {
|
|
Widget media(BuildContext context, Widget? app) => MediaQuery(
|
|
data: MediaQuery.of(
|
|
context,
|
|
).copyWith(textScaler: TextScaler.linear(textScale)),
|
|
child: app!,
|
|
);
|
|
return MaterialApp(
|
|
builder: media,
|
|
home: Scaffold(body: Center(child: child)),
|
|
);
|
|
}
|