Files
pipelines/app/test/features/runs/actions/title_test_support.dart
T
alan 364fd5b538 Remove Cupertino run action branches
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.
2026-11-11 04:18:26 +00:00

103 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/actions/title_action.dart';
typedef TitleHandler = Future<JsonMap> Function(String type, JsonMap fields);
/// A fake gateway that records every request and never owns a socket.
class FakeTitleGateway implements ApiGateway {
FakeTitleGateway(this.handler);
final TitleHandler 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 titledRun({
num id = 7,
String? title = 'Nightly build',
String status = 'succeeded',
String prompt = 'the submitted prompt',
}) => {
'id': id,
'title': title,
'status': status,
'input': {'prompt': prompt},
};
JsonMap renamedRun({num id = 7, String title = 'Release build'}) =>
titledRun(id: id, title: title, status: 'succeeded');
/// Owns the run like a run-detail screen would, so the callback's returned
/// server detail is what the action renders next. Re-pumping with a different
/// initial run updates the action in place, as a refreshed detail does.
class TitleHost extends StatefulWidget {
const TitleHost({
super.key,
required this.gateway,
required this.initial,
required this.changed,
});
final FakeTitleGateway gateway;
final JsonMap initial;
final List<JsonMap> changed;
@override
State<TitleHost> createState() => _TitleHostState();
}
class _TitleHostState extends State<TitleHost> {
late JsonMap _run = widget.initial;
@override
void didUpdateWidget(covariant TitleHost oldWidget) {
super.didUpdateWidget(oldWidget);
if (!identical(oldWidget.initial, widget.initial)) {
_run = widget.initial;
}
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('${_run['title'] ?? ''}', key: titleHostTitleKey),
RunTitleAction(
run: _run,
gateway: widget.gateway,
onRunChanged: (run) {
widget.changed.add(run);
setState(() => _run = run);
},
),
],
);
}
}
const titleHostTitleKey = ValueKey<String>('rename-host-title');
Widget titleApp(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)),
);
}