Files
pipelines/app/test/features/runs/ui/run_cancel_wiring_test.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

87 lines
2.8 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/status/run_status_icon.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/actions/cancel_wording.dart';
import 'package:pipelines_app/features/runs/screen.dart';
class _Gateway implements ApiGateway {
final events = StreamController<JsonMap>.broadcast();
final requests = <({String type, JsonMap fields})>[];
final canceled = Completer<JsonMap>();
final JsonMap run = {
'id': 7,
'title': 'Controlled run',
'name': 'fixture',
'status': 'running',
'executing': true,
'steps': <JsonMap>[],
};
@override
Stream<JsonMap> get frames => events.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
requests.add((type: type, fields: fields));
return switch (type) {
'list_runs' => Future.value({
'runs': [Map.of(run)],
}),
'get_run' => Future.value({'run_detail': Map.of(run)}),
'cancel_run' => canceled.future,
_ => Future.error(UnsupportedError(type)),
};
}
}
void main() {
testWidgets('actual detail confirms cancel and folds accepted state', (
tester,
) async {
final gateway = _Gateway();
addTearDown(gateway.events.close);
final screen = RunsScreen(gateway: gateway, initialRunId: 7);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: screen)));
await tester.pumpAndSettle();
await tester.tap(find.byKey(cancelActionKey));
await tester.pumpAndSettle();
expect(find.text('Cancel run 7?'), findsOneWidget);
expect(gateway.requests.where((r) => r.type == 'cancel_run'), isEmpty);
await tester.tap(find.byKey(cancelKeepKey));
await tester.pumpAndSettle();
expect(gateway.requests.where((r) => r.type == 'cancel_run'), isEmpty);
await tester.tap(find.byKey(cancelActionKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(cancelConfirmKey));
await tester.pump();
expect(
gateway.requests.where((r) => r.type == 'cancel_run').single.fields,
{'run_id': 7},
);
expect(find.text('canceled'), findsNothing);
gateway.canceled.complete({
'run_detail': {
...gateway.run,
'status': 'canceled',
'executing': false,
},
});
await tester.pumpAndSettle();
expect(find.byKey(cancelActionKey), findsNothing);
expect(find.text('canceled'), findsOneWidget);
// The held list is already visible beside the detail.
expect(
find.byWidgetPredicate(
(widget) => widget is RunStatusIcon && widget.label == 'canceled',
),
findsWidgets,
reason: 'The accepted server state must also update the held list row',
);
await tester.pumpWidget(const SizedBox.shrink());
});
}