Make Settings a first-class destination

Keep Settings location, selection, history, and persistence separate from Pipelines so /settings restores and navigates independently. Update focused navigation coverage and defer notification loading to avoid a mid-build Runs-tab update.
This commit is contained in:
2026-11-12 11:12:49 +00:00
parent 82418d31a7
commit 95902e3e49
12 changed files with 370 additions and 128 deletions
+12 -10
View File
@@ -657,15 +657,15 @@ class _PipelinesAppState extends State<PipelinesApp>
setState(() => _pendingRunSearch = null);
}
/// The last location within each tab, including Settings under Pipelines.
/// Explicit Back is separate from tab selection and same-tab retaps.
/// The last location within each destination, Settings included. Explicit
/// Back is separate from destination selection and same-destination retaps.
String get _navigationScope =>
widget.serverId ?? widget.server.uri?.toString() ?? '';
late final TabLocations _tabLocations;
Map<AppDestination, AppRoute> get _tabRoutes => _tabLocations.routes;
// A Settings visit owns the Pipelines tab's return location, but must not
// clear the still-mounted Pipelines body's selection or editor underneath.
// The last route each destination's body showed. A Settings visit records
// only Settings here, so the still-mounted Pipelines selection stays intact.
final _bodyRoutes = <AppDestination, AppRoute>{};
void _rememberBodyRoute(AppRoute route) {
@@ -741,7 +741,12 @@ class _PipelinesAppState extends State<PipelinesApp>
return;
}
}
_tabLocations.record(shown);
// Templates and Schedules are transient Settings sub-pages. Remember the
// Settings route under them, so selecting Settings later opens /settings
// rather than reopening the sub-page.
final subPage = shown.kind == AppRouteKind.templates ||
shown.kind == AppRouteKind.schedules;
_tabLocations.record(subPage ? _delegate.shellRoute : shown);
_rememberBodyRoute(_delegate.shellRoute);
_rememberChatRoute(shown);
final pending = _pendingRunSearch;
@@ -857,9 +862,6 @@ class _PipelinesAppState extends State<PipelinesApp>
onDestinationSelected: _selectDestination,
onDestinationReselected: _reselectDestination,
onOpenChat: _focusOpenChatComposer,
onClosePage: () => _delegate.goTo(
_bodyRoutes[AppDestination.pipelines] ?? AppRoute.pipelines,
),
destinationBodies: {
AppDestination.pipelines: (_) => FirstRunWalkthroughGate(
store: _walkthroughStore,
@@ -948,8 +950,8 @@ class _PipelinesAppState extends State<PipelinesApp>
onOpen: _openSearchResult,
embedded: true,
),
// Settings is a page of the Pipelines tab (its bar's gear), not a
// tab; the shell shows it with Back to Pipelines.
// Settings is a destination of its own; the shell selects it alone and
// its Back returns to the destination opened before it.
AppDestination.settings: (context) => SettingsScreen(
terminalLayout: _terminals.layout,
client: _session.client,
+4 -3
View File
@@ -1,12 +1,13 @@
import '../shell/destination.dart';
import 'app_route.dart';
/// Settings and its pages occupy the Pipelines tab, not an independent tab.
/// The destination that owns [route]. Settings and its sub-pages (Templates,
/// Schedules) belong to Settings itself, never to Pipelines.
AppDestination tabForRoute(AppRoute route) => switch (route.kind) {
AppRouteKind.pipelines ||
AppRouteKind.pipelines => AppDestination.pipelines,
AppRouteKind.settings ||
AppRouteKind.templates ||
AppRouteKind.schedules => AppDestination.pipelines,
AppRouteKind.schedules => AppDestination.settings,
AppRouteKind.runs => AppDestination.runs,
AppRouteKind.chat => AppDestination.chat,
AppRouteKind.search => AppDestination.search,
+7 -2
View File
@@ -32,17 +32,22 @@ class TabLocationsSnapshot {
}
final routes = <AppDestination, AppRoute>{};
for (final entry in (data['routes'] as Map).entries) {
final tab = shellTabDestinations
final tab = AppDestination.values
.where((tab) => tab.name == entry.key)
.firstOrNull;
final path = entry.value;
if (tab == null || path is! String || !path.startsWith('/')) continue;
final route = AppRoute.parse(path);
if (route.path != path || tabForRoute(route) != tab) continue;
// Templates and Schedules are transient sub-pages, never a saved place.
if (route.kind == AppRouteKind.templates ||
route.kind == AppRouteKind.schedules) {
continue;
}
routes[tab] = durableTabRoute(route);
}
final active =
shellTabDestinations
AppDestination.values
.where((tab) => tab.name == data['active'])
.firstOrNull ??
AppDestination.pipelines;
@@ -84,7 +84,11 @@ class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
final notifications = widget.notifications;
if (notifications != null) {
notifications.onOpenRun = _openRunById;
unawaited(notifications.load().then((_) => _publish()));
// Its load notifies listeners at once; start it after this build, so a
// Runs tab first shown from another tab does not rebuild mid-build.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) unawaited(notifications.load().then((_) => _publish()));
});
}
}
+17 -20
View File
@@ -26,7 +26,6 @@ class AdaptiveShell extends StatefulWidget {
this.destination,
this.onDestinationSelected,
this.onDestinationReselected,
this.onClosePage,
this.onSearch,
this.onOpenChat,
this.attentionCount = 0,
@@ -53,7 +52,6 @@ class AdaptiveShell extends StatefulWidget {
/// already shown (a re-select). The host decides what it means; Chat reopens
/// its active chats. Null keeps re-selects as plain selections.
final ValueChanged<AppDestination>? onDestinationReselected;
final VoidCallback? onClosePage;
/// Opens the transient Search page. Null hides the action, so the plain
/// shell tests and compositions without routing keep their tab set only.
@@ -166,8 +164,8 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
// Full-screen detail routes cover the shell themselves. Keep the root tabs
// mounted/layout-ready underneath, so Back does not resize or reveal them
// only after the outgoing page has finished its native animation.
// Settings is shown as a page of the Pipelines tab: the tab bar keeps
// Pipelines selected and the bar offers Back to it.
// Settings is a destination of its own: a page with no tab of the bar
// selected, and Back returns to the destination opened before it.
final page = !shellTabDestinations.contains(_selected);
final details = destinationDetails(_selected);
final contents = AppDestination.values.map((destination) {
@@ -227,7 +225,8 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
alignment: AlignmentDirectional.bottomStart,
child: FloatingDestinationBar(
showLabels: true,
currentIndex: shellTabDestinations.indexOf(shellTabFor(_selected)),
// A page (Settings) selects no tab: -1 highlights none.
currentIndex: shellTabDestinations.indexOf(_selected),
onTap: (value) => _tapDestination(shellTabDestinations[value]),
items: _destinationItems(),
alignment: split ? AlignmentDirectional.bottomStart : null,
@@ -252,12 +251,13 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
// heights; panes beside a list read the real ones from here.
final media = MediaQuery.of(context);
final system = media.padding;
// A page (Settings) closes to Pipelines on the system Back too; at a
// tab's root Back returns to the tab opened before it. Only with neither
// does Back reach the platform, so Android's (predictive) Back closes the
// app only from the first tab. Pages pushed over the shell (an item,
// Search, a dialog) pop before this scope is asked. The scope is always
// there, so opening the page never remounts the shell.
// A page (Settings) closes to the destination opened before it on the
// system Back too; at a tab's root Back returns to the destination opened
// before it. Only with neither does Back reach the platform, so Android's
// (predictive) Back closes the app only from the first destination. Pages
// pushed over the shell (an item, Search, a dialog) pop before this scope
// is asked. The scope is always there, so opening the page never remounts
// the shell.
Widget backable(Widget child) => PopScope(
canPop: !page && _history.isEmpty,
onPopInvokedWithResult: (didPop, _) {
@@ -326,24 +326,21 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
);
}
/// Leaves a page destination (Settings) for the tab it belongs to.
/// Leaves a page destination (Settings) for the destination selected before
/// it. With none recorded (a launch straight onto Settings) it opens Pipelines.
void _closePage() {
final close = widget.onClosePage;
if (close != null) {
close();
} else {
_select(shellTabFor(_selected));
}
_select(_history.takePrevious() ?? AppDestination.pipelines);
}
/// The system Back the shell handles: it closes a page, or else returns to
/// the previous tab unless the open item's own pane closes a page first.
/// the previous destination unless the open item's own pane closes a page
/// first.
void _back({required bool page}) {
if (page) {
_closePage();
return;
}
if (_nestedCanPop[shellTabFor(_selected)] ?? false) return;
if (_nestedCanPop[_selected] ?? false) return;
final previous = _history.takePrevious();
if (previous != null) _select(previous);
}
+5 -11
View File
@@ -2,10 +2,11 @@ import 'package:flutter/material.dart';
enum AppDestination { pipelines, runs, chat, search, settings }
/// The destinations the shell's tab bar (or, on a wide window, its rail) offers,
/// in order. Settings is a destination the shell can show (its route is
/// `/settings`), but it opens as a page, from the rail's foot on a wide window
/// or the Pipelines bar's gear on a phone, instead of being a tab.
/// The destinations the floating tab bar (or, on a wide window, the rail's
/// tabs) offers, in order. Settings is a destination of its own, not a tab of
/// Pipelines: it is selected alone, from the rail's foot on a wide window or as
/// the phone bar's last item, and no tab in this list is highlighted while it
/// is shown.
const List<AppDestination> shellTabDestinations = [
AppDestination.pipelines,
AppDestination.runs,
@@ -13,13 +14,6 @@ const List<AppDestination> shellTabDestinations = [
AppDestination.search,
];
/// The tab that owns [destination] in the tab bar: itself, or Pipelines for
/// Settings (reached from the Pipelines bar).
AppDestination shellTabFor(AppDestination destination) =>
shellTabDestinations.contains(destination)
? destination
: AppDestination.pipelines;
/// The label and icons for [value].
///
({String label, IconData icon}) destinationDetails(AppDestination value) =>
+17 -18
View File
@@ -1,40 +1,39 @@
import 'destination.dart';
/// The tabs the operator left, most recent first, for the system Back.
/// The destinations the operator left, most recent first, for the system Back.
///
/// Every tab change (a tap, a search result or notification opening
/// another tab) goes through [record]: the tab being left moves to the top
/// and the tab being opened leaves the stack, so each tab appears at most once
/// and the current tab is never in it. A page that belongs to a tab
/// (Settings, of Pipelines) is that tab here.
/// Every destination change (a tap, a search result or notification opening
/// another destination) goes through [record]: the destination being left moves
/// to the top and the destination being opened leaves the stack, so each
/// destination appears at most once and the current one is never in it.
/// Settings is a destination of its own, so leaving it returns to whatever was
/// selected before it.
///
/// [takePrevious] steps back: it removes the top tab and returns it, and the
/// next [record] that opens that tab does not push the tab being left, so Back
/// never builds a forward trail.
/// [takePrevious] steps back: it removes the top destination and returns it, and
/// the next [record] that opens that destination does not push the one being
/// left, so Back never builds a forward trail.
class TabHistory {
final List<AppDestination> _tabs = [];
AppDestination? _returningTo;
/// The left tabs, most recent first.
/// The left destinations, most recent first.
List<AppDestination> get tabs => List.unmodifiable(_tabs);
bool get isEmpty => _tabs.isEmpty;
/// Notes a change of the shown destination from [from] to [to].
void record(AppDestination from, AppDestination to) {
final left = shellTabFor(from);
final opened = shellTabFor(to);
if (left == opened) return;
final returning = _returningTo == opened;
if (from == to) return;
final returning = _returningTo == to;
_returningTo = null;
_tabs.remove(opened);
_tabs.remove(to);
if (returning) return;
_tabs
..remove(left)
..insert(0, left);
..remove(from)
..insert(0, from);
}
/// The tab Back returns to, removed from the stack; null when empty.
/// The destination Back returns to, removed from the stack; null when empty.
AppDestination? takePrevious() {
if (_tabs.isEmpty) return null;
final previous = _tabs.removeAt(0);
+92
View File
@@ -0,0 +1,92 @@
# Settings is its own destination
Settings belonged to the Pipelines destination in four places: the route-to-tab
map (`tabForRoute`), the shell's tab mapping (`shellTabFor`, now removed), the
tab history, and the shell's `onClosePage` override that sent a Settings close
to Pipelines. Each now treats Settings as `AppDestination.settings`.
## Behaviour
- `/settings` (and `/settings/templates`, `/schedules`) belong to Settings. The
Settings location is persisted under its own key; Pipelines never receives it.
- Only Settings is selected while it is shown: the phone bar's last item, no
highlighted tab in the floating bar (`currentIndex` -1), and no rail tab (the
rail's foot item only).
- Leaving Settings (system Back, or the bar's Back while it exists) returns to
the destination opened before it, from the shell's history. With none recorded
(a launch straight onto `/settings`) it opens Pipelines.
- Re-selecting Pipelines from Settings opens Pipelines' own last location; it
never reopens Settings.
- A reload on `/settings` restores Settings. Older saved snapshots that stored
Settings under Pipelines are dropped on load (the path no longer matches).
## Other change
`NeedsYouRunsHeading` (features/attention) called `notifications.load()` in
`initState`. That load notifies listeners synchronously, so a Runs tab first
shown from another tab (Settings to Runs) rebuilt an `AnimatedBuilder` mid-build
and threw. The load now starts after the first frame. This is outside the
Settings lane; it is needed for Settings to Runs to run without an error.
## Focused tests
Command: `tool/memwatch/full.sh` with ten paths (see the run's output). Result:
68 passed, 0 failed.
- test/application/tab_locations_test.dart
- test/application/tab_location_navigation_test.dart (9 tests, new coverage:
Settings state across Pipelines to Settings to Runs to Settings; re-selecting
Pipelines does not show Settings; on `/settings` only Settings is selected in
the phone bar, the floating bar and the rail; reload restores Settings)
- test/application/settings_page_test.dart
- test/application/templates_wiring_test.dart
- test/shell/tab_history_back_test.dart
- test/shell/navigation_rail_test.dart
- test/shell/shell_navigation_bar_test.dart
- test/shell/floating_tab_bar_test.dart
- test/features/attention/notify/notification_manager_wiring_test.dart
- test/features/runs/ui/runs_list_widget_test.dart
`tool/analyze.sh`: clean.
### Harness notes
- Two test files (`tab_location_navigation_test.dart`, `settings_page_test.dart`)
now mark the first-run walkthrough as seen. Without that the walkthrough
overlay on Pipelines absorbed the bar taps; on untouched HEAD the same tests
failed for that reason. No expectation for the app's behaviour was changed to
pass them.
- Expectations that encoded Settings-as-Pipelines were changed to the new
behaviour: tab location keys, the malformed-snapshot case (`settings` is now a
valid key), and the routed history test (Back now returns to Chat, then Runs).
## Limitations and compatibility with run 419
- Run 419 removes Settings' Back arrow (`shell.back`) and the gear. The new
navigation test uses the platform Back (`handlePopRoute`) and the bar, so it
does not depend on either. `navigation_rail_test.dart` and
`settings_page_test.dart` still tap `shell.back` and the gear; they will need
the same change when 419 lands.
- The shell's `onClosePage` parameter is removed (its only user was
`pipelines_app.dart`). Any 419 code that still passes it will not compile.
- Ctrl+A from Settings still goes to Runs (unchanged behaviour).
- No device or browser capture was taken here; visual states belong to ui-review.
## Review fix: Settings sub-pages never saved as Settings' place
`_routeChanged` recorded `_delegate.route` directly, so with Templates or
Schedules open the Settings location became `/templates` or `/schedules`.
Selecting Settings then reopened that sub-page. Now a Templates or Schedules
route records the Settings route the shell renders underneath
(`_delegate.shellRoute`). `TabLocationsSnapshot.decode` also drops stored
`templates`/`schedules` routes, so an older snapshot cannot restore one.
Regression: `tab_location_navigation_test.dart`, "selecting Settings after a
Settings sub-page opens /settings" (Pipelines, Schedules via the bar button, a
pushed `/runs`, then Settings). It fails with the fix reverted and passes with it.
Unit: `tab_locations_test.dart`, "a stored Settings sub-page is never restored".
Focused results (memwatch, two files): 24 passed, 0 failed. Analyzer: clean.
Known, not changed: Schedules opened from Pipelines still returns to Settings
(`openSchedules` sets the return route to Settings), so Settings shows under it.
+2 -1
View File
@@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/settings/settings_screen.dart';
import 'package:pipelines_app/features/walkthrough/walkthrough_store.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -22,7 +23,7 @@ void main() {
required String location,
required Size size,
}) async {
SharedPreferences.setMockInitialValues({});
SharedPreferences.setMockInitialValues({walkthroughSeenKey: true});
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -9,9 +10,11 @@ import 'package:pipelines_app/application/tab_locations_store.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/settings/settings_screen.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/features/walkthrough/walkthrough_store.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/shell_navigation_bar.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import '../bar_action.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../features/pipelines/fixtures.dart';
import 'pipelines_app_test.dart' show webServer;
@@ -55,43 +58,125 @@ Future<void> tab(WidgetTester tester, String name) async {
await tester.pump(const Duration(milliseconds: 500));
}
/// The system Back, as the platform sends it (not a tap on the page's own bar).
Future<void> systemBack(WidgetTester tester) async {
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
}
void main() {
setUp(() => SharedPreferences.setMockInitialValues({}));
testWidgets('Settings is retained inside Pipelines across tab switches', (
// The first-run walkthrough would sit over the Pipelines tab and absorb the
// bar taps these tests make; a device that has seen it has no overlay.
setUp(
() => SharedPreferences.setMockInitialValues({walkthroughSeenKey: true}),
);
testWidgets('Settings keeps its state across Pipelines, Runs and back', (
tester,
) async {
final app = await mount(tester);
await replyPipelines(tester, app.channel, PipelineFixture());
await tester.pumpAndSettle();
await tapBarAction(
tester,
find.byKey(const Key('pipelines-open-settings')),
'Settings',
);
await tester.pumpAndSettle();
await tab(tester, 'settings');
expect(app.provider.value.uri.path, '/settings');
final settingsState = tester.state(find.byType(SettingsScreen));
await tab(tester, 'chat');
expect(app.provider.value.uri.path, '/chat');
await tab(tester, 'pipelines');
await tab(tester, 'runs');
expect(app.provider.value.uri.path, '/runs');
expect(find.byType(SettingsScreen), findsNothing);
await tab(tester, 'settings');
expect(app.provider.value.uri.path, '/settings');
expect(tester.state(find.byType(SettingsScreen)), same(settingsState));
await tab(tester, 'pipelines');
expect(
app.provider.value.uri.path,
'/settings',
reason: 'tab retap is not Back',
);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(
app.provider.value.uri.path,
'/pipelines',
reason: 'explicit Back still exits Settings',
);
expect(app.provider.value.uri.path, '/pipelines');
expect(tester.takeException(), isNull);
});
testWidgets('re-selecting Pipelines does not show Settings', (tester) async {
final app = await mount(tester);
await replyPipelines(tester, app.channel, PipelineFixture());
await tester.pumpAndSettle();
await tab(tester, 'settings');
expect(app.provider.value.uri.path, '/settings');
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/pipelines');
expect(find.byType(SettingsScreen), findsNothing);
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/pipelines');
expect(find.byType(SettingsScreen), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets('on /settings only Settings is selected in the bar and rail', (
tester,
) async {
await mount(tester, route: '/settings');
await tester.pumpAndSettle();
// A phone: the bar's last destination is Settings.
expect(
tester
.widget<NavigationBar>(
find.byKey(const ValueKey('shell.navigation-bar')),
)
.selectedIndex,
shellBarDestinations.indexOf(AppDestination.settings),
);
// A window beside the list-detail minimum: the floating tab bar lights no
// tab, Pipelines included.
tester.view.physicalSize = const Size(650, 1000);
await tester.pumpAndSettle();
expect(
tester
.widget<FloatingDestinationBar>(find.byType(FloatingDestinationBar))
.currentIndex,
-1,
);
// A wide window: the rail selects no tab and Settings alone is selected.
tester.view.physicalSize = const Size(1100, 1000);
await tester.pumpAndSettle();
expect(
tester
.widget<NavigationRail>(
find.byKey(const ValueKey('shell.navigation-rail')),
)
.selectedIndex,
isNull,
);
expect(find.byType(SettingsScreen), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('selecting Settings after a Settings sub-page opens /settings', (
tester,
) async {
final app = await mount(tester);
await replyPipelines(tester, app.channel, PipelineFixture());
await tester.pumpAndSettle();
// Schedules is a Settings sub-page, opened from the Pipelines bar.
await tester.tap(find.byKey(const Key('pipelines-open-schedules')));
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/schedules');
// Leave the sub-page for Runs, as a pushed URL would, then select Settings.
await tester.binding.handlePushRoute('/runs');
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/runs');
await tab(tester, 'settings');
expect(app.provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('reload on /settings restores Settings', (tester) async {
final first = await mount(tester, route: '/settings');
await tester.pumpAndSettle();
expect(first.provider.value.uri.path, '/settings');
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
final restored = await mount(tester, route: '/');
await tester.pumpAndSettle();
expect(restored.provider.value.uri.path, '/settings');
expect(find.byType(SettingsScreen), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets(
'per-tab locations survive app recreation; an explicit deep link wins',
(tester) async {
@@ -117,11 +202,12 @@ void main() {
linked.provider.value.uri.toString(),
'/runs/8/stage/plan?visit=2',
);
await tab(tester, 'pipelines');
await tab(tester, 'settings');
expect(linked.provider.value.uri.path, '/settings');
expect(tester.takeException(), isNull);
},
);
testWidgets(
'a delayed read merges locations without redirecting a user move',
(tester) async {
@@ -131,18 +217,19 @@ void main() {
expect(store.writes, isEmpty);
store.read!.complete(
const TabLocationsSnapshot(
active: AppDestination.pipelines,
routes: {AppDestination.pipelines: AppRoute.settings},
active: AppDestination.settings,
routes: {AppDestination.settings: AppRoute.settings},
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(app.provider.value.uri.path, '/chat');
await tab(tester, 'pipelines');
await tab(tester, 'settings');
expect(app.provider.value.uri.path, '/settings');
expect(tester.takeException(), isNull);
},
);
testWidgets('an explicit root URL does not restore a different active tab', (
tester,
) async {
@@ -151,7 +238,7 @@ void main() {
active: AppDestination.runs,
routes: {
AppDestination.runs: AppRoute.run(9),
AppDestination.pipelines: AppRoute.settings,
AppDestination.settings: AppRoute.settings,
},
);
final app = await mount(tester, route: '/pipelines', store: store);
@@ -162,6 +249,7 @@ void main() {
expect(app.provider.value.uri.path, '/pipelines');
expect(tester.takeException(), isNull);
});
testWidgets('Settings does not clear the mounted Pipelines detail', (
tester,
) async {
@@ -171,28 +259,66 @@ void main() {
final fixture = PipelineFixture();
await replyPipelines(tester, app.channel, fixture);
await tester.pumpAndSettle();
final firstList = pipelineRequest(app.channel, 'list_pipelines')!['id'];
final firstRuns = pipelineRequest(app.channel, 'list_runs')!['id'];
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pump();
// The wide layout re-reads the list and the runs; their replies come
// before the detail's, as the transport serializes requests.
final reread = await waitForLaterRequest(
tester,
app.channel,
'list_pipelines',
firstList as String,
);
app.channel.incoming.add(
jsonEncode({
'id': reread['id'],
'type': 'pipelines',
'pipelines': fixture.summaries,
}),
);
await tester.pump();
final rerunRuns = await waitForLaterRequest(
tester,
app.channel,
'list_runs',
firstRuns as String,
);
app.channel.incoming.add(
jsonEncode({'id': rerunRuns['id'], 'type': 'runs', 'runs': fixture.runs}),
);
await tester.pump();
await waitForRequest(tester, app.channel, 'chat_sessions');
final sessions = pipelineRequest(app.channel, 'chat_sessions')!;
app.channel.incoming.add(
jsonEncode({
'id': sessions['id'],
'type': 'chat_sessions',
'chat_sessions': <Object>[],
}),
);
await tester.pump();
await replyPipelineDetail(tester, app.channel, fixture);
await tester.pumpAndSettle();
expect(app.provider.value.uri.path, '/pipelines/1');
final before = tester.widget<PipelinesScreen>(find.byType(PipelinesScreen));
expect(before.initialPipelineId, 1);
final pipelineState = tester.state(find.byType(PipelinesScreen));
// Wide: the rail offers Settings (the toolbar gear is gone).
expect(find.byKey(const Key('pipelines-open-settings')), findsNothing);
await tester.tap(find.byKey(const ValueKey('shell.destination.settings')));
await tester.pumpAndSettle();
await tab(tester, 'settings');
expect(app.provider.value.uri.path, '/settings');
final hidden = find.byType(PipelinesScreen, skipOffstage: false);
expect(tester.widget<PipelinesScreen>(hidden).initialPipelineId, 1);
expect(tester.state(hidden), same(pipelineState));
await tab(tester, 'chat');
await tab(tester, 'pipelines');
expect(app.provider.value.uri.path, '/settings');
expect(app.provider.value.uri.path, '/pipelines/1');
expect(tester.widget<PipelinesScreen>(hidden).initialPipelineId, 1);
await tester.tap(find.byKey(const Key('shell.back')));
await tester.pumpAndSettle();
await tab(tester, 'settings');
expect(app.provider.value.uri.path, '/settings');
// Back returns to the destination opened before Settings: the open
// pipeline, whose state is still mounted.
await systemBack(tester);
expect(app.provider.value.uri.path, '/pipelines/1');
expect(tester.state(find.byType(PipelinesScreen)), same(pipelineState));
expect(
@@ -203,10 +329,12 @@ void main() {
);
expect(tester.takeException(), isNull);
});
testWidgets('ordinary root with query restores its tab', (tester) async {
final store = MemoryTabLocationsStore()
..value = const TabLocationsSnapshot(
routes: {AppDestination.pipelines: AppRoute.settings},
active: AppDestination.settings,
routes: {AppDestination.settings: AppRoute.settings},
);
final app = await mount(tester, route: '/?preview=1', store: store);
await tester.pumpAndSettle();
+30 -17
View File
@@ -60,22 +60,24 @@ class GatedPreferencesTabLocationsStore
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
test('Settings and nested pages retain Pipelines ownership', () async {
test('Settings and its sub-pages keep their own location', () async {
final store = MemoryTabLocationsStore();
final tabs = TabLocations(store);
tabs.record(AppRoute.settings);
tabs.record(AppRoute.chat);
await tabs.restore(restoreActive: false);
await tabs.settled;
expect(tabs.routes[AppDestination.pipelines], AppRoute.settings);
expect(tabs.routes[AppDestination.settings], AppRoute.settings);
expect(tabs.routes[AppDestination.pipelines], isNull);
expect(tabs.routes[AppDestination.chat], AppRoute.chat);
expect(store.value.routes[AppDestination.pipelines], AppRoute.settings);
expect(store.value.routes[AppDestination.settings], AppRoute.settings);
tabs.record(AppRoute.template('release'));
await tabs.settled;
expect(
store.value.routes[AppDestination.pipelines],
store.value.routes[AppDestination.settings],
AppRoute.template('release'),
);
expect(store.value.routes.containsKey(AppDestination.pipelines), isFalse);
});
test('canonical details survive serialization, decisions do not replay', () {
final snapshot = TabLocationsSnapshot.decode(
@@ -124,7 +126,18 @@ void main() {
},
}),
);
expect(saved.routes, isEmpty);
expect(saved.routes, {AppDestination.settings: AppRoute.settings});
});
test('a stored Settings sub-page is never restored as the saved place', () {
for (final path in ['/templates', '/schedules']) {
final saved = TabLocationsSnapshot.decode(
jsonEncode({
'version': 1,
'routes': {'settings': path},
}),
);
expect(saved.routes, isEmpty, reason: path);
}
});
test(
'delayed restore merges untouched tabs but never overwrites user navigation',
@@ -143,7 +156,7 @@ void main() {
TabLocationsSnapshot(
active: AppDestination.pipelines,
routes: {
AppDestination.pipelines: AppRoute.settings,
AppDestination.settings: AppRoute.settings,
AppDestination.runs: AppRoute.run(5),
},
),
@@ -151,7 +164,7 @@ void main() {
expect(await restoring, isNull);
await tabs.settled;
expect(tabs.routes[AppDestination.runs], AppRoute.run(12));
expect(tabs.routes[AppDestination.pipelines], AppRoute.settings);
expect(tabs.routes[AppDestination.settings], AppRoute.settings);
expect(store.value.active, AppDestination.runs);
},
);
@@ -160,8 +173,8 @@ void main() {
() async {
final store = MemoryTabLocationsStore()
..value = const TabLocationsSnapshot(
active: AppDestination.pipelines,
routes: {AppDestination.pipelines: AppRoute.settings},
active: AppDestination.settings,
routes: {AppDestination.settings: AppRoute.settings},
);
final ordinary = TabLocations(store)
..record(AppRoute.pipelines, visited: false);
@@ -191,7 +204,7 @@ void main() {
first.complete(true);
await tabs.settled;
expect(store.value.active, AppDestination.runs);
expect(store.value.routes[AppDestination.pipelines], AppRoute.settings);
expect(store.value.routes[AppDestination.settings], AppRoute.settings);
expect(store.value.routes[AppDestination.runs], AppRoute.run(9));
},
);
@@ -204,7 +217,7 @@ void main() {
expect(
await a.save(
const TabLocationsSnapshot(
routes: {AppDestination.pipelines: AppRoute.settings},
routes: {AppDestination.settings: AppRoute.settings},
),
),
isTrue,
@@ -212,7 +225,7 @@ void main() {
expect(
(await const SharedPreferencesTabLocationsStore(
scope: 'server-a',
).load()).routes[AppDestination.pipelines],
).load()).routes[AppDestination.settings],
AppRoute.settings,
);
expect((await b.load()).routes, isEmpty);
@@ -228,7 +241,7 @@ void main() {
await tabs.settled;
expect(tabs.persistenceFailed, isTrue);
expect(store.writes, isEmpty);
expect(tabs.routes[AppDestination.pipelines], AppRoute.settings);
expect(tabs.routes[AppDestination.settings], AppRoute.settings);
},
);
test('a failed write does not prevent a later navigation save', () async {
@@ -252,7 +265,7 @@ void main() {
tabs.dispose();
store.read!.complete(
const TabLocationsSnapshot(
routes: {AppDestination.pipelines: AppRoute.settings},
routes: {AppDestination.settings: AppRoute.settings},
),
);
expect(await restoring, isNull);
@@ -285,7 +298,7 @@ void main() {
await replacement.settled;
expect(store.value.active, AppDestination.runs);
expect(store.value.routes[AppDestination.runs], AppRoute.run(12));
expect(store.value.routes[AppDestination.pipelines], AppRoute.settings);
expect(store.value.routes[AppDestination.settings], AppRoute.settings);
expect(
store.value.routes[AppDestination.chat],
AppRoute.chat,
@@ -323,7 +336,7 @@ void main() {
final saved = await newStore.load();
expect(saved.active, AppDestination.runs);
expect(saved.routes[AppDestination.runs], AppRoute.run(18));
expect(saved.routes[AppDestination.pipelines], AppRoute.settings);
expect(saved.routes[AppDestination.settings], AppRoute.settings);
expect(saved.routes[AppDestination.chat], AppRoute.chat);
},
);
@@ -363,7 +376,7 @@ void main() {
AppRoute.chatSession('last-open-chat'),
);
expect(saved.routes[AppDestination.runs], isNull);
expect(saved.routes[AppDestination.pipelines], AppRoute.settings);
expect(saved.routes[AppDestination.settings], AppRoute.settings);
},
);
}
+13 -7
View File
@@ -55,16 +55,23 @@ void main() {
expect(history.tabs, [AppDestination.pipelines, AppDestination.chat]);
});
test('a page counts as its tab, and Back builds no forward trail', () {
test('Settings is its own entry, and Back builds no forward trail', () {
final history = TabHistory();
history.record(AppDestination.runs, AppDestination.pipelines);
history.record(AppDestination.pipelines, AppDestination.settings);
expect(history.tabs, [AppDestination.runs]);
history.record(AppDestination.settings, AppDestination.chat);
expect(history.tabs, [AppDestination.pipelines, AppDestination.runs]);
history.record(AppDestination.settings, AppDestination.chat);
expect(history.tabs, [
AppDestination.settings,
AppDestination.pipelines,
AppDestination.runs,
]);
expect(history.takePrevious(), AppDestination.settings);
history.record(AppDestination.chat, AppDestination.settings);
expect(history.tabs, [AppDestination.pipelines, AppDestination.runs]);
expect(history.takePrevious(), AppDestination.pipelines);
history.record(AppDestination.chat, AppDestination.pipelines);
history.record(AppDestination.settings, AppDestination.pipelines);
expect(history.tabs, [AppDestination.runs]);
expect(history.takePrevious(), AppDestination.runs);
history.record(AppDestination.pipelines, AppDestination.runs);
@@ -248,9 +255,8 @@ void main() {
await tester.pumpAndSettle();
_expectShown(AppDestination.settings);
// Settings closes to Pipelines first, as it always has.
await _back(tester);
expect(router.route, AppRoute.pipelines);
// Settings is a destination of its own: Back returns to the one opened
// before it, chat, then runs, then the platform.
await _back(tester);
expect(router.route.kind, AppRouteKind.chat);
await _back(tester);