Organize settings into retained topic tabs
This commit is contained in:
@@ -18,6 +18,7 @@ import 'settings_group.dart';
|
|||||||
import 'storage/settings_storage_section.dart';
|
import 'storage/settings_storage_section.dart';
|
||||||
import 'health/settings_health_section.dart';
|
import 'health/settings_health_section.dart';
|
||||||
import 'settings_page_body.dart';
|
import 'settings_page_body.dart';
|
||||||
|
import 'settings_tabs.dart';
|
||||||
import 'settings_notifications_section.dart';
|
import 'settings_notifications_section.dart';
|
||||||
import 'settings_ntfy_section.dart';
|
import 'settings_ntfy_section.dart';
|
||||||
import 'settings_device_delivery_section.dart';
|
import 'settings_device_delivery_section.dart';
|
||||||
@@ -35,6 +36,8 @@ import 'server_connections.dart';
|
|||||||
import 'saved_servers_section.dart';
|
import 'saved_servers_section.dart';
|
||||||
import 'managed_connection_section.dart';
|
import 'managed_connection_section.dart';
|
||||||
|
|
||||||
|
part 'settings_topic_pages.dart';
|
||||||
|
|
||||||
/// The Settings destination: the server connection and the server-side
|
/// The Settings destination: the server connection and the server-side
|
||||||
/// workspace, in native Material (native platforms) or Cupertino (iOS) controls.
|
/// workspace, in native Material (native platforms) or Cupertino (iOS) controls.
|
||||||
///
|
///
|
||||||
@@ -169,83 +172,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final servers = widget.servers;
|
final content = SettingsTopicTabs(pages: _topicPages());
|
||||||
final content = SettingsPageBody(
|
|
||||||
children: <Widget>[
|
|
||||||
if (servers != null) ...<Widget>[
|
|
||||||
SavedServersSection(connections: servers),
|
|
||||||
ManagedConnectionSection(
|
|
||||||
client: widget.client,
|
|
||||||
controller: _controller,
|
|
||||||
),
|
|
||||||
] else
|
|
||||||
SettingsConnectionSection(
|
|
||||||
controller: _controller,
|
|
||||||
serverUrlField: _serverUrlField,
|
|
||||||
),
|
|
||||||
// A phone signs in at the web login; a browser has its own.
|
|
||||||
if (widget.showSignIn)
|
|
||||||
_single(
|
|
||||||
'Sign in',
|
|
||||||
SettingsSignInSection(
|
|
||||||
endpoint: _endpoint,
|
|
||||||
onChanged: _reconnectAfterSignIn,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// The web page links the Android app the server offers.
|
|
||||||
if (widget.showAndroidDownload)
|
|
||||||
_single('Android app', const SettingsAndroidDownloadSection()),
|
|
||||||
// A phone installs newer builds from the server.
|
|
||||||
if (widget.showSignIn && appUpdatesSupported)
|
|
||||||
_single('App updates', SettingsUpdatesSection(endpoint: _endpoint)),
|
|
||||||
SettingsWorkspaceSection(
|
|
||||||
controller: _controller,
|
|
||||||
workspaceField: _workspaceField,
|
|
||||||
),
|
|
||||||
_single(
|
|
||||||
'Data management',
|
|
||||||
SettingsStorageSection(gateway: widget.client),
|
|
||||||
),
|
|
||||||
_single('Server', SettingsHealthSection(gateway: widget.client)),
|
|
||||||
// A device-local choice: a browser and a phone keep their own.
|
|
||||||
SettingsAnimationSection(
|
|
||||||
controller:
|
|
||||||
widget.animationSpeed ?? AnimationSpeedController.instance,
|
|
||||||
),
|
|
||||||
SettingsFontSection(
|
|
||||||
controller: widget.fonts ?? AppFontController.instance,
|
|
||||||
),
|
|
||||||
if (widget.notifications case final notifications?)
|
|
||||||
SettingsNotificationsSection(controller: notifications),
|
|
||||||
if (widget.deliveryService case final service? when service.supported)
|
|
||||||
SettingsDeviceDeliverySection(
|
|
||||||
bridge: service,
|
|
||||||
controller: widget.deliveryServiceController,
|
|
||||||
requestNotificationPermission: widget.notifications == null
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
await widget.notifications!.requestPermission();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
// The server's ntfy choices, beside the in-app permission.
|
|
||||||
SettingsNtfySection(
|
|
||||||
gateway: widget.client,
|
|
||||||
connected:
|
|
||||||
widget.client.state.kind == transport.ConnectionKind.connected,
|
|
||||||
),
|
|
||||||
if (widget.onOpenSchedules != null || widget.onOpenTemplates != null)
|
|
||||||
SettingsGroup(
|
|
||||||
title: 'Library',
|
|
||||||
leadingRows: true,
|
|
||||||
children: <Widget>[
|
|
||||||
if (widget.onOpenSchedules case final open?)
|
|
||||||
SettingsSchedulesSection(onOpen: open),
|
|
||||||
if (widget.onOpenTemplates case final open?)
|
|
||||||
SettingsTemplatesSection(onOpen: open),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
if (widget.embedded) {
|
if (widget.embedded) {
|
||||||
// Under the shell's bar the Cupertino page is the grouped background
|
// Under the shell's bar the Cupertino page is the grouped background
|
||||||
// right up to the top edge: the bar's scrim takes the same colour, so
|
// right up to the top edge: the bar's scrim takes the same colour, so
|
||||||
@@ -271,10 +198,4 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
body: content,
|
body: content,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A group holding one free-form block (a form, a status with buttons).
|
|
||||||
Widget _single(String title, Widget child) => SettingsGroup(
|
|
||||||
title: title,
|
|
||||||
children: <Widget>[SettingsGroupItem(child: child)],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'settings_layout.dart';
|
||||||
|
import 'settings_theme.dart';
|
||||||
|
import 'settings_page_body.dart';
|
||||||
|
|
||||||
|
enum SettingsTopic {
|
||||||
|
appearance('Appearance'),
|
||||||
|
connection('Connection'),
|
||||||
|
notifications('Notifications'),
|
||||||
|
tools('Tools'),
|
||||||
|
updates('Updates');
|
||||||
|
|
||||||
|
const SettingsTopic(this.label);
|
||||||
|
final String label;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Topic pages are created on first visit, then retained with their drafts and
|
||||||
|
/// independent scroll positions. Hidden pages do not tick animations.
|
||||||
|
class SettingsTopicTabs extends StatefulWidget {
|
||||||
|
const SettingsTopicTabs({super.key, required this.pages});
|
||||||
|
final Map<SettingsTopic, WidgetBuilder> pages;
|
||||||
|
@override
|
||||||
|
State<SettingsTopicTabs> createState() => _SettingsTopicTabsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SettingsTopicTabsState extends State<SettingsTopicTabs>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
late final TabController _tabs;
|
||||||
|
SettingsTopic _selected = SettingsTopic.appearance;
|
||||||
|
final Set<SettingsTopic> _visited = {SettingsTopic.appearance};
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_tabs = TabController(length: SettingsTopic.values.length, vsync: this);
|
||||||
|
_tabs.addListener(_changed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _changed() {
|
||||||
|
final next = SettingsTopic.values[_tabs.index];
|
||||||
|
if (next == _selected) return;
|
||||||
|
setState(() {
|
||||||
|
_selected = next;
|
||||||
|
_visited.add(next);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_tabs.removeListener(_changed);
|
||||||
|
_tabs.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final tabs = usesCupertinoControls(context)
|
||||||
|
? SingleChildScrollView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: settingsPageSidePadding,
|
||||||
|
),
|
||||||
|
child: CupertinoSlidingSegmentedControl<SettingsTopic>(
|
||||||
|
groupValue: _selected,
|
||||||
|
children: {
|
||||||
|
for (final topic in SettingsTopic.values)
|
||||||
|
topic: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: settingsControlGap,
|
||||||
|
),
|
||||||
|
child: Text(topic.label),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
onValueChanged: (topic) {
|
||||||
|
if (topic != null) _tabs.index = topic.index;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: TabBar(
|
||||||
|
controller: _tabs,
|
||||||
|
isScrollable: true,
|
||||||
|
tabAlignment: TabAlignment.start,
|
||||||
|
tabs: [
|
||||||
|
for (final topic in SettingsTopic.values) Tab(text: topic.label),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final body = SafeArea(
|
||||||
|
bottom: false,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Semantics(container: true, label: 'Settings categories', child: tabs),
|
||||||
|
Expanded(
|
||||||
|
child: IndexedStack(
|
||||||
|
index: _selected.index,
|
||||||
|
children: [
|
||||||
|
for (final topic in SettingsTopic.values)
|
||||||
|
if (_visited.contains(topic))
|
||||||
|
TickerMode(
|
||||||
|
enabled: topic == _selected,
|
||||||
|
child: KeyedSubtree(
|
||||||
|
key: ValueKey('settings-topic-${topic.name}'),
|
||||||
|
child: Builder(builder: widget.pages[topic]!),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
const SizedBox.shrink(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return usesCupertinoControls(context)
|
||||||
|
? ColoredBox(
|
||||||
|
color: settingsCupertinoBackground.resolveFrom(context),
|
||||||
|
child: body,
|
||||||
|
)
|
||||||
|
: body;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
part of 'settings_screen.dart';
|
||||||
|
|
||||||
|
extension _SettingsTopicPages on _SettingsScreenState {
|
||||||
|
Map<SettingsTopic, WidgetBuilder> _topicPages() {
|
||||||
|
final servers = widget.servers;
|
||||||
|
return {
|
||||||
|
SettingsTopic.appearance: (_) => SettingsPageBody(
|
||||||
|
children: [
|
||||||
|
SettingsAnimationSection(
|
||||||
|
controller:
|
||||||
|
widget.animationSpeed ?? AnimationSpeedController.instance,
|
||||||
|
),
|
||||||
|
SettingsFontSection(
|
||||||
|
controller: widget.fonts ?? AppFontController.instance,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SettingsTopic.connection: (_) => SettingsPageBody(
|
||||||
|
children: [
|
||||||
|
if (servers != null) ...[
|
||||||
|
SavedServersSection(connections: servers),
|
||||||
|
ManagedConnectionSection(
|
||||||
|
client: widget.client,
|
||||||
|
controller: _controller,
|
||||||
|
),
|
||||||
|
] else
|
||||||
|
SettingsConnectionSection(
|
||||||
|
controller: _controller,
|
||||||
|
serverUrlField: _serverUrlField,
|
||||||
|
),
|
||||||
|
if (widget.showSignIn)
|
||||||
|
_single(
|
||||||
|
'Sign in',
|
||||||
|
SettingsSignInSection(
|
||||||
|
endpoint: _endpoint,
|
||||||
|
onChanged: _reconnectAfterSignIn,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SettingsWorkspaceSection(
|
||||||
|
controller: _controller,
|
||||||
|
workspaceField: _workspaceField,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SettingsTopic.notifications: (_) => SettingsPageBody(
|
||||||
|
children: [
|
||||||
|
if (widget.notifications case final notifications?)
|
||||||
|
SettingsNotificationsSection(controller: notifications),
|
||||||
|
if (widget.deliveryService case final service? when service.supported)
|
||||||
|
SettingsDeviceDeliverySection(
|
||||||
|
bridge: service,
|
||||||
|
controller: widget.deliveryServiceController,
|
||||||
|
requestNotificationPermission: widget.notifications == null
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
await widget.notifications!.requestPermission();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
SettingsNtfySection(
|
||||||
|
gateway: widget.client,
|
||||||
|
connected:
|
||||||
|
widget.client.state.kind == transport.ConnectionKind.connected,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SettingsTopic.tools: (_) => SettingsPageBody(
|
||||||
|
children: [
|
||||||
|
_single(
|
||||||
|
'Data management',
|
||||||
|
SettingsStorageSection(gateway: widget.client),
|
||||||
|
),
|
||||||
|
_single('Server', SettingsHealthSection(gateway: widget.client)),
|
||||||
|
if (widget.onOpenSchedules != null || widget.onOpenTemplates != null)
|
||||||
|
SettingsGroup(
|
||||||
|
title: 'Library',
|
||||||
|
leadingRows: true,
|
||||||
|
children: [
|
||||||
|
if (widget.onOpenSchedules case final open?)
|
||||||
|
SettingsSchedulesSection(onOpen: open),
|
||||||
|
if (widget.onOpenTemplates case final open?)
|
||||||
|
SettingsTemplatesSection(onOpen: open),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SettingsTopic.updates: (_) => SettingsPageBody(
|
||||||
|
children: [
|
||||||
|
if (widget.showAndroidDownload)
|
||||||
|
_single('Android app', const SettingsAndroidDownloadSection()),
|
||||||
|
if (widget.showSignIn && appUpdatesSupported)
|
||||||
|
_single('App updates', SettingsUpdatesSection(endpoint: _endpoint)),
|
||||||
|
if (!widget.showAndroidDownload &&
|
||||||
|
!(widget.showSignIn && appUpdatesSupported))
|
||||||
|
_single(
|
||||||
|
'App updates',
|
||||||
|
const Text(
|
||||||
|
'This installation is updated by its server administrator.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A group holding one free-form block (a form, a status with buttons).
|
||||||
|
Widget _single(String title, Widget child) => SettingsGroup(
|
||||||
|
title: title,
|
||||||
|
children: <Widget>[SettingsGroupItem(child: child)],
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Settings topic tabs
|
||||||
|
|
||||||
|
Settings opens on Appearance (animations and fonts), with Connection,
|
||||||
|
Notifications, Tools (storage, health, library), and Updates alongside it.
|
||||||
|
Material uses native horizontally scrollable tabs. Cupertino uses its native
|
||||||
|
sliding segmented control inside a horizontal scroll view, so long labels and
|
||||||
|
large accessibility text remain reachable on narrow screens.
|
||||||
|
|
||||||
|
Category navigation stays below the shell/navigation bar; each page scrolls
|
||||||
|
beneath the category selector and retains its own position. Pages mount on
|
||||||
|
first visit and remain mounted, preserving unsaved fields. Hidden pages have
|
||||||
|
TickerMode disabled. Notification settings are not requested until the topic
|
||||||
|
is first opened. The shared connection/controller still lives at screen scope.
|
||||||
|
Cupertino's grouped background fills the entire page, including the top inset.
|
||||||
|
|
||||||
|
Checks: 144 settings and Settings-route application tests pass, including four
|
||||||
|
new lazy/state/scroll/large-text category tests. Existing tests explicitly open
|
||||||
|
Connection or Notifications before asserting their controls. Analyzer clean.
|
||||||
|
Integrated preview and full-app browser captures are owned by the parent lane;
|
||||||
|
this lane did not capture or deploy independently.
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import '../features/settings/settings_topic_test_helper.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
@@ -87,6 +88,8 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(provider.value.uri.path, '/settings');
|
expect(provider.value.uri.path, '/settings');
|
||||||
expect(find.byType(SettingsScreen), findsOneWidget);
|
expect(find.byType(SettingsScreen), findsOneWidget);
|
||||||
|
expect(find.text('Quick switch animation'), findsOneWidget);
|
||||||
|
await selectSettingsTopic(tester, 'Connection');
|
||||||
expect(find.text('Server URL'), findsOneWidget);
|
expect(find.text('Server URL'), findsOneWidget);
|
||||||
// A page of Pipelines: Back in its bar, Pipelines still selected.
|
// A page of Pipelines: Back in its bar, Pipelines still selected.
|
||||||
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
|
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import '../features/settings/settings_topic_test_helper.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
@@ -60,9 +61,11 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(provider.value.uri.path, '/settings');
|
expect(provider.value.uri.path, '/settings');
|
||||||
|
expect(find.text('Quick switch animation'), findsOneWidget);
|
||||||
|
await selectSettingsTopic(tester, 'Connection');
|
||||||
expect(find.text('Server URL'), findsOneWidget);
|
expect(find.text('Server URL'), findsOneWidget);
|
||||||
if (cupertino) {
|
if (cupertino) {
|
||||||
final title = tester.widget<Text>(find.text('Connection'));
|
final title = tester.widget<Text>(find.text('Connection').last);
|
||||||
expect(
|
expect(
|
||||||
title.style!.color!.computeLuminance(),
|
title.style!.color!.computeLuminance(),
|
||||||
greaterThan(0.5),
|
greaterThan(0.5),
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import 'package:pipelines_app/features/settings/settings_trust_warning.dart';
|
|||||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||||
|
|
||||||
import 'fake_channel.dart';
|
import 'fake_channel.dart';
|
||||||
|
import 'settings_topic_test_helper.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('groups start at the bar inset and stop at the reading width', (
|
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));
|
expect(rect.width, closeTo(settingsContentMaxWidth, 0.01));
|
||||||
}
|
}
|
||||||
// A header's text lines up with its rows' text.
|
// 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(
|
expect(
|
||||||
header.left,
|
header.left,
|
||||||
closeTo(settingsPageSidePadding + settingsRowInset, 0.01),
|
closeTo(settingsPageSidePadding + settingsRowInset, 0.01),
|
||||||
@@ -65,23 +66,31 @@ void main() {
|
|||||||
}
|
}
|
||||||
// The trust warning is the Connection group's footer, not a card.
|
// The trust warning is the Connection group's footer, not a card.
|
||||||
expect(find.byType(SettingsTrustWarning), findsOneWidget);
|
expect(find.byType(SettingsTrustWarning), findsOneWidget);
|
||||||
final title = tester.widget<Text>(find.text('Connection'));
|
final title = tester.widget<Text>(find.text('Connection').last);
|
||||||
final theme = Theme.of(tester.element(find.text('Connection')));
|
final theme = Theme.of(tester.element(find.text('Connection').last));
|
||||||
expect(title.style?.color, theme.colorScheme.primary);
|
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,
|
tester,
|
||||||
) async {
|
) async {
|
||||||
const barHeight = 72.0;
|
const barHeight = 72.0;
|
||||||
await _pump(tester, topPadding: barHeight);
|
await _pump(tester, topPadding: barHeight);
|
||||||
|
|
||||||
final first = tester.getRect(find.byType(SettingsGroup).first);
|
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(
|
expect(
|
||||||
tester.getRect(find.byKey(const ValueKey('settings.scroll'))).top,
|
first.top,
|
||||||
0,
|
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);
|
addTearDown(notifications.dispose);
|
||||||
await _pump(tester, notifications: notifications);
|
await _pump(tester, notifications: notifications);
|
||||||
|
|
||||||
expect(find.text('Notifications'), findsOneWidget);
|
await selectSettingsTopic(tester, 'Notifications');
|
||||||
expect(find.text('Connection'), findsOneWidget);
|
expect(find.text('Notifications'), findsNWidgets(2));
|
||||||
|
expect(find.text('Connection').last, findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Cupertino keeps the compact secondary field label', (
|
testWidgets('Cupertino keeps the compact secondary field label', (
|
||||||
@@ -226,4 +236,5 @@ Future<void> _pump(
|
|||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.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 'package:pipelines_app/features/settings/settings_store.dart';
|
||||||
|
|
||||||
import 'fake_channel.dart';
|
import 'fake_channel.dart';
|
||||||
|
import 'settings_topic_test_helper.dart';
|
||||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -30,7 +31,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(find.text('Settings'), findsOneWidget);
|
expect(find.text('Settings'), findsOneWidget);
|
||||||
expect(find.text('Connection'), findsOneWidget);
|
expect(find.text('Connection').last, findsOneWidget);
|
||||||
expect(find.text('Workspace'), findsOneWidget);
|
expect(find.text('Workspace'), findsOneWidget);
|
||||||
expect(find.text('Not connected'), findsOneWidget);
|
expect(find.text('Not connected'), findsOneWidget);
|
||||||
expect(find.text('Saved workspace: /srv/pipelines'), findsOneWidget);
|
expect(find.text('Saved workspace: /srv/pipelines'), findsOneWidget);
|
||||||
@@ -163,7 +164,9 @@ void main() {
|
|||||||
findsOneWidget,
|
findsOneWidget,
|
||||||
);
|
);
|
||||||
expect(find.text('Connect'), findsNothing);
|
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);
|
_answerNtfySettings(factory.last);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
@@ -205,6 +208,7 @@ void main() {
|
|||||||
expect(find.text(serverDetailsPending), findsNothing);
|
expect(find.text(serverDetailsPending), findsNothing);
|
||||||
expect(find.text('Server build unavailable'), findsOneWidget);
|
expect(find.text('Server build unavailable'), findsOneWidget);
|
||||||
expect(find.text('Server time unavailable'), findsOneWidget);
|
expect(find.text('Server time unavailable'), findsOneWidget);
|
||||||
|
await selectSettingsTopic(tester, 'Notifications');
|
||||||
_answerNtfySettings(factory.last);
|
_answerNtfySettings(factory.last);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
});
|
});
|
||||||
@@ -284,7 +288,12 @@ void main() {
|
|||||||
await tester.scrollUntilVisible(
|
await tester.scrollUntilVisible(
|
||||||
find.byKey(SettingsKeys.saveWorkspace),
|
find.byKey(SettingsKeys.saveWorkspace),
|
||||||
200,
|
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(find.byKey(SettingsKeys.saveWorkspace), findsOneWidget);
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
@@ -383,6 +392,7 @@ Future<void> _pump(
|
|||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
await selectSettingsTopic(tester, 'Connection');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
@@ -402,6 +412,7 @@ Future<void> _pump(
|
|||||||
);
|
);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
await selectSettingsTopic(tester, 'Connection');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Answers the Settings screen's queued ntfy-settings load on [channel].
|
/// 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,
|
(widget) => widget is ColoredBox && widget.color.toARGB32() == grouped,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
expect(page, findsOneWidget);
|
expect(page, findsWidgets);
|
||||||
expect(tester.getTopLeft(page).dy, 0);
|
expect(tester.getTopLeft(page.last).dy, 0);
|
||||||
// The groups start below the bar and scroll behind it.
|
// The groups start below the bar and persistent category selector.
|
||||||
final bar = tester.getRect(find.byType(SegmentedBar));
|
final bar = tester.getRect(find.byType(SegmentedBar));
|
||||||
expect(
|
expect(
|
||||||
tester.getTopLeft(find.byType(SettingsGroup).first).dy,
|
tester.getTopLeft(find.byType(SettingsGroup).first).dy,
|
||||||
@@ -90,7 +90,7 @@ void main() {
|
|||||||
tester
|
tester
|
||||||
.getTopLeft(find.byKey(const ValueKey<String>('settings.scroll')))
|
.getTopLeft(find.byKey(const ValueKey<String>('settings.scroll')))
|
||||||
.dy,
|
.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));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user