Organize settings into retained topic tabs

This commit is contained in:
2026-11-07 19:36:02 +00:00
parent 6b654693d9
commit fc4aa1652f
11 changed files with 434 additions and 101 deletions
@@ -18,6 +18,7 @@ import 'package:pipelines_app/features/settings/settings_trust_warning.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
import 'fake_channel.dart';
import 'settings_topic_test_helper.dart';
void main() {
testWidgets('groups start at the bar inset and stop at the reading width', (
@@ -34,7 +35,7 @@ void main() {
expect(rect.width, closeTo(settingsContentMaxWidth, 0.01));
}
// A header's text lines up with its rows' text.
final header = tester.getRect(find.text('Connection'));
final header = tester.getRect(find.text('Connection').last);
expect(
header.left,
closeTo(settingsPageSidePadding + settingsRowInset, 0.01),
@@ -65,23 +66,31 @@ void main() {
}
// The trust warning is the Connection group's footer, not a card.
expect(find.byType(SettingsTrustWarning), findsOneWidget);
final title = tester.widget<Text>(find.text('Connection'));
final theme = Theme.of(tester.element(find.text('Connection')));
final title = tester.widget<Text>(find.text('Connection').last);
final theme = Theme.of(tester.element(find.text('Connection').last));
expect(title.style?.color, theme.colorScheme.primary);
});
testWidgets('content starts below the bar and scrolls behind it', (
testWidgets('content starts below the bar and persistent topic tabs', (
tester,
) async {
const barHeight = 72.0;
await _pump(tester, topPadding: barHeight);
final first = tester.getRect(find.byType(SettingsGroup).first);
expect(first.top, closeTo(barHeight + settingsPageTopPadding, 0.01));
// No top SafeArea: the scroll view itself reaches the top edge.
expect(
tester.getRect(find.byKey(const ValueKey('settings.scroll'))).top,
0,
first.top,
closeTo(
barHeight +
tester.getSize(find.byType(TabBar)).height +
settingsPageTopPadding,
0.01,
),
);
// The topic selector stays above each page scroll view.
expect(
tester.getRect(find.byKey(const ValueKey('settings.scroll')).last).top,
barHeight + tester.getSize(find.byType(TabBar)).height,
);
});
@@ -117,8 +126,9 @@ void main() {
addTearDown(notifications.dispose);
await _pump(tester, notifications: notifications);
expect(find.text('Notifications'), findsOneWidget);
expect(find.text('Connection'), findsOneWidget);
await selectSettingsTopic(tester, 'Notifications');
expect(find.text('Notifications'), findsNWidgets(2));
expect(find.text('Connection').last, findsOneWidget);
});
testWidgets('Cupertino keeps the compact secondary field label', (
@@ -226,4 +236,5 @@ Future<void> _pump(
);
await tester.pump();
await tester.pump();
await selectSettingsTopic(tester, 'Connection');
}
@@ -10,6 +10,7 @@ import 'package:pipelines_app/features/settings/settings_screen.dart';
import 'package:pipelines_app/features/settings/settings_store.dart';
import 'fake_channel.dart';
import 'settings_topic_test_helper.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
void main() {
@@ -30,7 +31,7 @@ void main() {
);
expect(find.text('Settings'), findsOneWidget);
expect(find.text('Connection'), findsOneWidget);
expect(find.text('Connection').last, findsOneWidget);
expect(find.text('Workspace'), findsOneWidget);
expect(find.text('Not connected'), findsOneWidget);
expect(find.text('Saved workspace: /srv/pipelines'), findsOneWidget);
@@ -163,7 +164,9 @@ void main() {
findsOneWidget,
);
expect(find.text('Connect'), findsNothing);
// The only other request is the ntfy settings load, queued behind ping.
// Notification settings are loaded only when their topic is opened.
expect(factory.last.decodedOutgoing, hasLength(1));
await selectSettingsTopic(tester, 'Notifications');
_answerNtfySettings(factory.last);
await tester.pump();
await tester.pump();
@@ -205,6 +208,7 @@ void main() {
expect(find.text(serverDetailsPending), findsNothing);
expect(find.text('Server build unavailable'), findsOneWidget);
expect(find.text('Server time unavailable'), findsOneWidget);
await selectSettingsTopic(tester, 'Notifications');
_answerNtfySettings(factory.last);
await tester.pump();
});
@@ -284,7 +288,12 @@ void main() {
await tester.scrollUntilVisible(
find.byKey(SettingsKeys.saveWorkspace),
200,
scrollable: find.byType(Scrollable).first,
scrollable: find
.descendant(
of: find.byKey(const ValueKey('settings-topic-connection')),
matching: find.byType(Scrollable),
)
.first,
);
expect(find.byKey(SettingsKeys.saveWorkspace), findsOneWidget);
expect(tester.takeException(), isNull);
@@ -383,6 +392,7 @@ Future<void> _pump(
);
await tester.pump();
await tester.pump();
await selectSettingsTopic(tester, 'Connection');
return;
}
await tester.pumpWidget(
@@ -402,6 +412,7 @@ Future<void> _pump(
);
await tester.pump();
await tester.pump();
await selectSettingsTopic(tester, 'Connection');
}
/// Answers the Settings screen's queued ntfy-settings load on [channel].
@@ -66,9 +66,9 @@ void main() {
(widget) => widget is ColoredBox && widget.color.toARGB32() == grouped,
),
);
expect(page, findsOneWidget);
expect(tester.getTopLeft(page).dy, 0);
// The groups start below the bar and scroll behind it.
expect(page, findsWidgets);
expect(tester.getTopLeft(page.last).dy, 0);
// The groups start below the bar and persistent category selector.
final bar = tester.getRect(find.byType(SegmentedBar));
expect(
tester.getTopLeft(find.byType(SettingsGroup).first).dy,
@@ -90,7 +90,7 @@ void main() {
tester
.getTopLeft(find.byKey(const ValueKey<String>('settings.scroll')))
.dy,
0,
greaterThan(tester.getRect(find.byType(SegmentedBar)).bottom),
);
});
}
@@ -0,0 +1,124 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/settings_tabs.dart';
import 'settings_topic_test_helper.dart';
class _Page extends StatefulWidget {
const _Page({required this.name, required this.onMount});
final String name;
final VoidCallback onMount;
@override
State<_Page> createState() => _PageState();
}
class _PageState extends State<_Page> {
final text = TextEditingController();
final scroll = ScrollController();
@override
void initState() {
super.initState();
widget.onMount();
}
@override
void dispose() {
text.dispose();
scroll.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => SingleChildScrollView(
controller: scroll,
child: Column(
children: [
CupertinoTextField(controller: text),
for (var i = 0; i < 80; i++) Text('${widget.name} item $i'),
],
),
);
}
void main() {
for (final cupertino in [false, true]) {
testWidgets('lazy topic pages retain draft and scroll ($cupertino)', (
tester,
) async {
final mounts = <SettingsTopic, int>{};
final tabs = SettingsTopicTabs(
pages: {
for (final topic in SettingsTopic.values)
topic: (_) => _Page(
name: topic.name,
onMount: () =>
mounts.update(topic, (count) => count + 1, ifAbsent: () => 1),
),
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: tabs))
: MaterialApp(home: Scaffold(body: tabs)),
);
expect(mounts, {SettingsTopic.appearance: 1});
final appearance = tester.state<_PageState>(find.byType(_Page));
appearance.text.text = 'Keep this draft';
appearance.scroll.jumpTo(150);
await tester.pump();
await selectSettingsTopic(tester, 'Connection');
expect(mounts, {
SettingsTopic.appearance: 1,
SettingsTopic.connection: 1,
});
final connection = tester.state<_PageState>(find.byType(_Page));
connection.text.text = 'Unsubmitted server';
connection.scroll.jumpTo(280);
await selectSettingsTopic(tester, 'Appearance');
expect(tester.state(find.byType(_Page)), same(appearance));
expect(appearance.text.text, 'Keep this draft');
expect(appearance.scroll.offset, 150);
await selectSettingsTopic(tester, 'Connection');
expect(tester.state(find.byType(_Page)), same(connection));
expect(connection.text.text, 'Unsubmitted server');
expect(connection.scroll.offset, 280);
expect(mounts.values, everyElement(1));
});
testWidgets('all topics reachable at narrow large text ($cupertino)', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final tabs = SettingsTopicTabs(
pages: {
for (final topic in SettingsTopic.values)
topic: (_) => Text('${topic.label} content'),
},
);
Widget scale(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
builder: scale,
home: CupertinoPageScaffold(child: tabs),
)
: MaterialApp(
builder: scale,
home: Scaffold(body: tabs),
),
);
for (final topic in SettingsTopic.values) {
await selectSettingsTopic(tester, topic.label);
expect(find.text('${topic.label} content'), findsOneWidget);
expect(tester.takeException(), isNull);
}
});
}
}
@@ -0,0 +1,9 @@
import 'package:flutter_test/flutter_test.dart';
Future<void> selectSettingsTopic(WidgetTester tester, String topic) async {
final label = find.text(topic).first;
await tester.ensureVisible(label);
await tester.tap(label);
await tester.pump();
await tester.pump(const Duration(milliseconds: 350));
}