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.
104 lines
2.7 KiB
Dart
104 lines
2.7 KiB
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/retry_action.dart';
|
|
|
|
typedef RetryHandler = Future<JsonMap> Function(String type, JsonMap fields);
|
|
|
|
/// A fake gateway that records every request and never owns a socket.
|
|
class FakeRetryGateway implements ApiGateway {
|
|
FakeRetryGateway(this.handler);
|
|
|
|
final RetryHandler 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();
|
|
|
|
Iterable<({String type, JsonMap fields})> get retries =>
|
|
calls.where((call) => call.type == 'retry_run');
|
|
}
|
|
|
|
JsonMap failedRun({
|
|
num id = 7,
|
|
bool executing = false,
|
|
String status = 'failed',
|
|
String title = 'Nightly build',
|
|
}) => {'id': id, 'title': title, 'status': status, 'executing': executing};
|
|
|
|
JsonMap retriedRun({num id = 8}) =>
|
|
failedRun(id: id, status: 'running', executing: true, title: 'Retry of 7');
|
|
|
|
/// Owns the run like a run-detail screen would, so the callback's returned
|
|
/// server detail is what the action renders next.
|
|
class RetryHost extends StatefulWidget {
|
|
const RetryHost({
|
|
super.key,
|
|
required this.gateway,
|
|
required this.initial,
|
|
required this.changed,
|
|
});
|
|
|
|
final FakeRetryGateway gateway;
|
|
final JsonMap initial;
|
|
final List<JsonMap> changed;
|
|
|
|
@override
|
|
State<RetryHost> createState() => _RetryHostState();
|
|
}
|
|
|
|
class _RetryHostState extends State<RetryHost> {
|
|
late JsonMap _run = widget.initial;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return RetryRunAction(
|
|
run: _run,
|
|
gateway: widget.gateway,
|
|
onRunChanged: (run) {
|
|
widget.changed.add(run);
|
|
setState(() => _run = run);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget retryApp(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)),
|
|
);
|
|
}
|
|
|
|
Future<void> pumpRetry(
|
|
WidgetTester tester, {
|
|
required FakeRetryGateway gateway,
|
|
required List<JsonMap> changed,
|
|
double textScale = 1,
|
|
JsonMap? run,
|
|
}) async {
|
|
await tester.pumpWidget(
|
|
retryApp(
|
|
RetryHost(
|
|
gateway: gateway,
|
|
initial: run ?? failedRun(),
|
|
changed: changed,
|
|
),
|
|
textScale: textScale,
|
|
),
|
|
);
|
|
}
|