merge(app): land foreground-refresh-guard (run 158)
This commit is contained in:
@@ -90,6 +90,9 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
|
||||
AppRoute get route => _route;
|
||||
|
||||
/// Whether a dialog, popup, or other route is covering the shell page.
|
||||
bool get hasTransientRoute => _navigatorKey.currentState?.canPop() ?? false;
|
||||
|
||||
bool get searchOpen => _route.kind == AppRouteKind.search;
|
||||
|
||||
bool get templatesOpen => _route.kind == AppRouteKind.templates;
|
||||
|
||||
@@ -217,6 +217,7 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
|
||||
// A return to the foreground refreshes only the visible list. Detail routes
|
||||
// (including pipeline definitions and run visits) keep their current data.
|
||||
if (_delegate.hasTransientRoute || _isEditingText) return;
|
||||
final route = _delegate.route;
|
||||
if (route.kind == AppRouteKind.pipelines &&
|
||||
route.pipelineId == null &&
|
||||
@@ -227,6 +228,11 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
}
|
||||
}
|
||||
|
||||
bool get _isEditingText {
|
||||
final focusContext = FocusManager.instance.primaryFocus?.context;
|
||||
return focusContext?.findAncestorWidgetOfExactType<EditableText>() != null;
|
||||
}
|
||||
|
||||
/// A replaced socket drops the attention status baseline so the gap cannot
|
||||
/// replay a transition; the Runs list's next read reseeds the rows.
|
||||
void _attentionSessionChanged() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/pipelines_app.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
@@ -153,6 +153,74 @@ void main() {
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
testWidgets('foreground resume preserves an open dialog and skips refresh', (
|
||||
tester,
|
||||
) async {
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
await pumpApp(tester, provider: provider, client: client);
|
||||
await waitForRequest(tester, channel, 'list_runs');
|
||||
final initialRuns = pipelineRequest(channel, 'list_runs')!;
|
||||
channel.incoming.add(jsonEncode({
|
||||
'id': initialRuns['id'],
|
||||
'type': 'runs',
|
||||
'runs': PipelineFixture().runs,
|
||||
}));
|
||||
await tester.pump();
|
||||
final before = countType(channel, 'list_runs');
|
||||
showDialog<void>(
|
||||
context: tester.element(find.byType(Scaffold).first),
|
||||
builder: (_) => const AlertDialog(content: Text('Still open')),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await resume(tester);
|
||||
|
||||
expect(countType(channel, 'list_runs'), before);
|
||||
expect(find.text('Still open'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
testWidgets('foreground resume skips refresh while a text field has focus', (
|
||||
tester,
|
||||
) async {
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
final client = PipelinesClient(channelFactory: (_) => channel);
|
||||
await pumpApp(tester, provider: provider, client: client);
|
||||
await waitForRequest(tester, channel, 'list_runs');
|
||||
final initialRuns = pipelineRequest(channel, 'list_runs')!;
|
||||
channel.incoming.add(jsonEncode({
|
||||
'id': initialRuns['id'],
|
||||
'type': 'runs',
|
||||
'runs': PipelineFixture().runs,
|
||||
}));
|
||||
await tester.pump();
|
||||
final before = countType(channel, 'list_runs');
|
||||
showDialog<void>(
|
||||
context: tester.element(find.byType(Scaffold).first),
|
||||
builder: (_) => const AlertDialog(content: TextField()),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.tap(find.byType(TextField).last);
|
||||
await tester.pump();
|
||||
|
||||
await resume(tester);
|
||||
|
||||
expect(countType(channel, 'list_runs'), before);
|
||||
expect(FocusManager.instance.primaryFocus?.hasFocus, isTrue);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
testWidgets('foreground resume does not refresh an open run detail', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user