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
+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);
},
);
}