fix(app): the Run dialog waits for the stored pending intent after a reload
This commit is contained in:
@@ -218,6 +218,23 @@ class PipelinesController extends ChangeNotifier {
|
||||
_notify();
|
||||
}
|
||||
|
||||
/// The unresolved launch for one pinned definition, read from the device
|
||||
/// store first, so the Run dialog opened right after a reload offers the
|
||||
/// same request key instead of minting a new one.
|
||||
Future<RunPipelineIntent?> loadPendingRun(int pipelineId, int version) async {
|
||||
final key = '$pipelineId@$version';
|
||||
if (_loadedPendingRuns.add(key)) {
|
||||
final generation = _pendingRunGenerations[key] ?? 0;
|
||||
final intent = await _pendingRunStore.read(pipelineId, version);
|
||||
if (!_disposed &&
|
||||
(_pendingRunGenerations[key] ?? 0) == generation &&
|
||||
intent != null) {
|
||||
_pendingRuns[key] = intent;
|
||||
}
|
||||
}
|
||||
return _pendingRuns[key];
|
||||
}
|
||||
|
||||
/// The unresolved launch for one pinned definition, if any.
|
||||
RunPipelineIntent? pendingRunFor(int pipelineId, int version) {
|
||||
final key = '$pipelineId@$version';
|
||||
|
||||
@@ -48,11 +48,16 @@ class _RunPipelineActionState extends State<RunPipelineAction> {
|
||||
if (_dialogOpen) return;
|
||||
_dialogOpen = true;
|
||||
try {
|
||||
final pending = await widget.controller.loadPendingRun(
|
||||
_pipelineId,
|
||||
_version,
|
||||
);
|
||||
if (!mounted) return;
|
||||
await showRunPipelineDialog(
|
||||
context: context,
|
||||
detail: widget.detail,
|
||||
gateway: widget.gateway,
|
||||
pending: widget.controller.pendingRunFor(_pipelineId, _version),
|
||||
pending: pending,
|
||||
onSubmit: _submit,
|
||||
onPendingChanged: (intent) {
|
||||
if (intent == null) {
|
||||
|
||||
@@ -435,6 +435,49 @@ void main() {
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('an unknown launch survives a reload with the same key', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final fixture = PipelineFixture();
|
||||
final navigated = <int>[];
|
||||
final keys = <String>[];
|
||||
var attempts = 0;
|
||||
final gateway = launchGateway(
|
||||
fixture,
|
||||
onLaunch: (fields) {
|
||||
attempts++;
|
||||
keys.add(fields['request_key'] as String);
|
||||
if (attempts == 1) throw StateError('Connection closed');
|
||||
return acceptedRun(87);
|
||||
},
|
||||
onLookup: (_) => noRun(),
|
||||
);
|
||||
await pumpScreen(tester, gateway, navigated);
|
||||
await openDetail(tester);
|
||||
await tester.tap(find.byKey(runPipelineActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await fillFields(tester);
|
||||
await tester.tap(find.byKey(runPipelineConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(runPipelineCheckRetryLabel), findsOneWidget);
|
||||
|
||||
// A reload: the screen and its controller are gone; only the device
|
||||
// store remains.
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await pumpScreen(tester, gateway, navigated);
|
||||
await openDetail(tester);
|
||||
await tester.tap(find.byKey(runPipelineActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(runPipelineCheckRetryLabel), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(runPipelineConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(keys, hasLength(2));
|
||||
expect(keys[1], keys[0]);
|
||||
expect(navigated, [87]);
|
||||
});
|
||||
|
||||
testWidgets('closing and reopening an unknown launch restores check/retry', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user