feat(app): add native retry and restart action
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
import 'package:flutter/cupertino.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_eligibility.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_intent.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
|
||||
|
||||
import 'retry_test_support.dart';
|
||||
|
||||
void main() {
|
||||
test('retry eligibility matches the web canRetry exactly', () {
|
||||
final cases = <(String, JsonMap, bool)>[
|
||||
('failed and stopped', failedRun(), true),
|
||||
('failed but still executing', failedRun(executing: true), false),
|
||||
('running', failedRun(status: 'running'), false),
|
||||
('waiting', failedRun(status: 'waiting'), false),
|
||||
('succeeded', failedRun(status: 'succeeded'), false),
|
||||
('canceled', failedRun(status: 'canceled'), false),
|
||||
];
|
||||
for (final (label, run, expected) in cases) {
|
||||
expect(canRetryRun(run), expected, reason: label);
|
||||
}
|
||||
expect(canRetryRun(null), isFalse);
|
||||
expect(retryRunId(failedRun()), 7);
|
||||
expect(retryRunId({'id': '7'}), isNull);
|
||||
});
|
||||
|
||||
test('a generated retry key is bounded, run-scoped and fresh', () {
|
||||
final first = newRetryRequestKey(7);
|
||||
final second = newRetryRequestKey(7);
|
||||
|
||||
expect(first, startsWith('app-retry-7-'));
|
||||
expect(first.length, lessThanOrEqualTo(128));
|
||||
expect(second.length, lessThanOrEqualTo(128));
|
||||
expect(first, isNot(second));
|
||||
expect(
|
||||
newRetryRequestKey(7, now: DateTime.utc(2026, 1, 1), random: 36),
|
||||
'app-retry-7-${DateTime.utc(2026, 1, 1).microsecondsSinceEpoch}-10',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'material retry asks first, Keep sends nothing, then omits retry_mode',
|
||||
(tester) async {
|
||||
final accepted = retriedRun();
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': accepted},
|
||||
);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
expect(find.byKey(retryActionKey), findsOneWidget);
|
||||
expect(find.byType(FilledButton), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text(retryDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(retryDialogMessage), findsOneWidget);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(AlertDialog),
|
||||
matching: find.text(retryConfirmLabel),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(restartConfirmLabel), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.byKey(retryActionKey), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(1));
|
||||
final fields = gateway.retries.single.fields;
|
||||
expect(fields.keys, containsAll(<String>['run_id', 'request_key']));
|
||||
expect(fields.containsKey('retry_mode'), isFalse);
|
||||
expect(fields['run_id'], 7);
|
||||
expect(fields['request_key'], startsWith('app-retry-7-'));
|
||||
expect(fields['request_key'].length, lessThanOrEqualTo(128));
|
||||
expect(changed.single, equals(accepted));
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.byKey(retryActionKey), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'material restart has its own confirmation and sends retry_mode',
|
||||
(tester) async {
|
||||
final accepted = retriedRun();
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': accepted},
|
||||
);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(restartDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(restartDialogMessage), findsOneWidget);
|
||||
expect(find.text(retryDialogTitle(7)), findsNothing);
|
||||
expect(find.text(retryDialogMessage), findsNothing);
|
||||
expect(find.text(restartConfirmLabel), findsOneWidget);
|
||||
expect(find.byKey(retryRestartKey), findsNothing);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(1));
|
||||
final fields = gateway.retries.single.fields;
|
||||
expect(fields['run_id'], 7);
|
||||
expect(fields['retry_mode'], 'restart');
|
||||
expect(fields['request_key'], startsWith('app-retry-7-'));
|
||||
expect(changed.single, equals(accepted));
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'cupertino retry uses a native prompt and sends only on confirm',
|
||||
(tester) async {
|
||||
final accepted = retriedRun();
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': accepted},
|
||||
);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
changed: changed,
|
||||
cupertino: true,
|
||||
);
|
||||
|
||||
expect(find.byKey(retryActionKey), findsOneWidget);
|
||||
expect(find.byType(CupertinoButton), findsOneWidget);
|
||||
expect(find.byType(FilledButton), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.text(retryDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(retryDialogMessage), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls, isEmpty);
|
||||
expect(find.byType(CupertinoAlertDialog), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(1));
|
||||
final fields = gateway.retries.single.fields;
|
||||
expect(fields['run_id'], 7);
|
||||
expect(fields.containsKey('retry_mode'), isFalse);
|
||||
expect(fields['request_key'], startsWith('app-retry-7-'));
|
||||
expect(changed.single, equals(accepted));
|
||||
expect(find.byType(CupertinoAlertDialog), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('cupertino restart switches to the restart confirmation', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': retriedRun()},
|
||||
);
|
||||
await pumpRetry(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
changed: <JsonMap>[],
|
||||
cupertino: true,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
||||
expect(find.text(restartDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(restartDialogMessage), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.retries.single.fields['retry_mode'], 'restart');
|
||||
});
|
||||
|
||||
testWidgets('the action is absent for runs the web does not retry', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': retriedRun()},
|
||||
);
|
||||
final changed = <JsonMap>[];
|
||||
final cases = <(String, JsonMap, bool)>[
|
||||
('failed', failedRun(), true),
|
||||
('executing', failedRun(executing: true), false),
|
||||
('running', failedRun(status: 'running'), false),
|
||||
('waiting', failedRun(status: 'waiting'), false),
|
||||
('succeeded', failedRun(status: 'succeeded'), false),
|
||||
('canceled', failedRun(status: 'canceled'), false),
|
||||
];
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final (label, run, visible) in cases) {
|
||||
await tester.pumpWidget(
|
||||
retryApp(
|
||||
RetryHost(
|
||||
key: ValueKey('$label-$cupertino'),
|
||||
gateway: gateway,
|
||||
initial: run,
|
||||
changed: changed,
|
||||
),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
find.byKey(retryActionKey),
|
||||
visible ? findsOneWidget : findsNothing,
|
||||
reason: '$label cupertino=$cupertino',
|
||||
);
|
||||
}
|
||||
}
|
||||
expect(gateway.calls, isEmpty);
|
||||
expect(changed, isEmpty);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_eligibility.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
|
||||
|
||||
import 'retry_test_support.dart';
|
||||
|
||||
Future<void> _openAndConfirm(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('a refusal is shown at once and Keep does not wait for resync', (
|
||||
tester,
|
||||
) async {
|
||||
const refusal = 'run 7 is still executing; wait for it to stop completely';
|
||||
final resync = Completer<JsonMap>();
|
||||
final gateway = FakeRetryGateway((type, fields) {
|
||||
if (type == 'retry_run') throw const ProtocolError(refusal);
|
||||
return resync.future;
|
||||
});
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pump();
|
||||
|
||||
expect(gateway.calls.map((call) => call.type), ['retry_run', 'get_run']);
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(find.byKey(retryErrorKey), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<TextButton>(find.byKey(retryKeepKey)).onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
expect(
|
||||
tester.widget<FilledButton>(find.byKey(retryConfirmKey)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(changed, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
|
||||
resync.complete({'run_detail': failedRun(status: 'succeeded')});
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(changed.single['status'], 'succeeded');
|
||||
expect(find.byKey(retryActionKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('server truth that is ineligible blocks a repeat action', (
|
||||
tester,
|
||||
) async {
|
||||
const refusal = 'only failed runs can be retried';
|
||||
final finished = failedRun(status: 'succeeded');
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'retry_run') throw const ProtocolError(refusal);
|
||||
return {'run_detail': finished};
|
||||
});
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.calls.map((call) => call.type), ['retry_run', 'get_run']);
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<FilledButton>(find.byKey(retryConfirmKey)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
tester.widget<TextButton>(find.byKey(retryKeepKey)).onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pump();
|
||||
expect(gateway.calls.map((call) => call.type), ['retry_run', 'get_run']);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.byKey(retryActionKey), findsNothing);
|
||||
expect(changed.single, equals(finished));
|
||||
expect(canRetryRun(changed.single), isFalse);
|
||||
});
|
||||
|
||||
testWidgets('a failed recheck keeps the same key for the uncertain request', (
|
||||
tester,
|
||||
) async {
|
||||
const refusal = 'connection dropped while retrying';
|
||||
var attempts = 0;
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'get_run') throw const NotConnectedError();
|
||||
attempts += 1;
|
||||
if (attempts == 1) throw const ProtocolError(refusal);
|
||||
return {'run_detail': retriedRun()};
|
||||
});
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<FilledButton>(find.byKey(retryConfirmKey)).onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
expect(gateway.retries, hasLength(1));
|
||||
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(2));
|
||||
expect(
|
||||
gateway.retries.last.fields['request_key'],
|
||||
gateway.retries.first.fields['request_key'],
|
||||
);
|
||||
expect(
|
||||
gateway.retries.every((call) => !call.fields.containsKey('retry_mode')),
|
||||
isTrue,
|
||||
);
|
||||
expect(changed.single, equals(retriedRun()));
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a restart retry keeps the mode and key across uncertainty', (
|
||||
tester,
|
||||
) async {
|
||||
var attempts = 0;
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'get_run') throw const NotConnectedError();
|
||||
attempts += 1;
|
||||
if (attempts == 1) throw const ProtocolError('network lost');
|
||||
return {'run_detail': retriedRun()};
|
||||
});
|
||||
await pumpRetry(tester, gateway: gateway, changed: <JsonMap>[]);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(2));
|
||||
expect(gateway.retries.first.fields['retry_mode'], 'restart');
|
||||
expect(gateway.retries.last.fields['retry_mode'], 'restart');
|
||||
expect(
|
||||
gateway.retries.last.fields['request_key'],
|
||||
gateway.retries.first.fields['request_key'],
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a deliberate reopen sends a fresh request key', (tester) async {
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'get_run') throw const NotConnectedError();
|
||||
throw const ProtocolError('server did not answer');
|
||||
});
|
||||
await pumpRetry(tester, gateway: gateway, changed: <JsonMap>[]);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(2));
|
||||
expect(
|
||||
gateway.retries.first.fields['request_key'],
|
||||
isNot(gateway.retries.last.fields['request_key']),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a restart after a dismissed resume uses a fresh key', (
|
||||
tester,
|
||||
) async {
|
||||
var attempts = 0;
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'get_run') throw const NotConnectedError();
|
||||
attempts += 1;
|
||||
if (attempts == 1) throw const ProtocolError('resume refused');
|
||||
return {'run_detail': retriedRun()};
|
||||
});
|
||||
await pumpRetry(tester, gateway: gateway, changed: <JsonMap>[]);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
// A refusal leaves the prompt open; keep the mode frozen and dismiss.
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(2));
|
||||
expect(gateway.retries.first.fields.containsKey('retry_mode'), isFalse);
|
||||
expect(gateway.retries.last.fields['retry_mode'], 'restart');
|
||||
expect(
|
||||
gateway.retries.first.fields['request_key'],
|
||||
isNot(gateway.retries.last.fields['request_key']),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.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/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
|
||||
|
||||
import 'retry_test_support.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('confirm cannot submit twice while the retry is in flight', (
|
||||
tester,
|
||||
) async {
|
||||
final reply = Completer<JsonMap>();
|
||||
final gateway = FakeRetryGateway((type, fields) => reply.future);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
final confirm = find.byKey(retryConfirmKey);
|
||||
await tester.tap(confirm);
|
||||
await tester.tap(confirm);
|
||||
await tester.pump();
|
||||
|
||||
expect(gateway.retries, hasLength(1));
|
||||
expect(
|
||||
tester.widget<FilledButton>(find.byKey(retryConfirmKey)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
tester.widget<TextButton>(find.byKey(retryKeepKey)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
|
||||
reply.complete({'run_detail': retriedRun()});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(changed, hasLength(1));
|
||||
});
|
||||
|
||||
testWidgets('a late retry reply after disposal is ignored safely', (
|
||||
tester,
|
||||
) async {
|
||||
final reply = Completer<JsonMap>();
|
||||
final gateway = FakeRetryGateway((type, fields) => reply.future);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pump();
|
||||
expect(gateway.retries, hasLength(1));
|
||||
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
reply.complete({'run_detail': retriedRun()});
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(changed, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a late resync after disposal is ignored safely', (tester) async {
|
||||
final resync = Completer<JsonMap>();
|
||||
final gateway = FakeRetryGateway((type, fields) {
|
||||
if (type == 'retry_run') throw const ProtocolError('refused');
|
||||
return resync.future;
|
||||
});
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pump();
|
||||
expect(gateway.calls.map((call) => call.type), ['retry_run', 'get_run']);
|
||||
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
resync.complete({'run_detail': retriedRun()});
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(changed, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('both confirmations fit 2x text at a narrow width', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 480);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': retriedRun()},
|
||||
);
|
||||
await pumpRetry(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
changed: <JsonMap>[],
|
||||
cupertino: cupertino,
|
||||
textScale: 2,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull, reason: 'cupertino=$cupertino');
|
||||
expect(find.text(retryDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(retryDialogMessage), findsOneWidget);
|
||||
expect(
|
||||
cupertino
|
||||
? find.byType(CupertinoAlertDialog)
|
||||
: find.byType(AlertDialog),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull, reason: 'restart=$cupertino');
|
||||
expect(find.text(restartDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(restartDialogMessage), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls, isEmpty);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import 'package:flutter/cupertino.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, {required bool cupertino, double textScale = 1}) {
|
||||
Widget media(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: app!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
builder: media,
|
||||
home: CupertinoPageScaffold(child: Center(child: child)),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
builder: media,
|
||||
home: Scaffold(body: Center(child: child)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pumpRetry(
|
||||
WidgetTester tester, {
|
||||
required FakeRetryGateway gateway,
|
||||
required List<JsonMap> changed,
|
||||
bool cupertino = false,
|
||||
double textScale = 1,
|
||||
JsonMap? run,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
retryApp(
|
||||
RetryHost(
|
||||
gateway: gateway,
|
||||
initial: run ?? failedRun(),
|
||||
changed: changed,
|
||||
),
|
||||
cupertino: cupertino,
|
||||
textScale: textScale,
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user