97 lines
3.3 KiB
Dart
97 lines
3.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
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() {
|
|
for (final cupertino in [false, true]) {
|
|
testWidgets(
|
|
'actual detail confirms cancel and folds accepted state ($cupertino)',
|
|
(tester) async {
|
|
final gateway = _Gateway();
|
|
addTearDown(gateway.events.close);
|
|
final screen = RunsScreen(gateway: gateway, initialRunId: 7);
|
|
await tester.pumpWidget(
|
|
cupertino
|
|
? CupertinoApp(home: CupertinoPageScaffold(child: screen))
|
|
: 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);
|
|
await tester.tap(find.text(cupertino ? 'Back' : 'Back to list'));
|
|
await tester.pumpAndSettle();
|
|
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());
|
|
},
|
|
);
|
|
}
|
|
}
|