Files
pipelines/app/test/features/settings/settings_layout_test.dart
T
alan 3136e5bb7e Redesign Settings as grouped searchable page
Replace the tabbed Settings flow with a single grouped page that searches and lazily loads server-backed sections. Preserve existing settings behavior while adding inline loading and retry states and updating coverage for the new navigation model.
2026-11-12 02:54:07 +00:00

191 lines
6.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/servers/server_catalog.dart';
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart'
as transport;
import 'package:pipelines_app/features/attention/notify/notification_controller.dart';
import 'package:pipelines_app/features/attention/notify/notification_store.dart';
import 'package:pipelines_app/features/settings/saved_server_row.dart';
import 'package:pipelines_app/features/settings/saved_servers_section.dart';
import 'package:pipelines_app/features/settings/server_connections.dart';
import 'package:pipelines_app/features/settings/settings_group.dart';
import 'package:pipelines_app/features/settings/settings_layout.dart';
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_trust_warning.dart';
import 'fake_channel.dart';
import 'settings_section_test_helper.dart';
void main() {
testWidgets('groups are centred at the reading width beside the index', (
tester,
) async {
await _pump(tester, size: const Size(1200, 1600));
// The list area is the window less the jump index and the side insets.
const area = 1200 - settingsIndexWidth - 2 * settingsPageSidePadding;
final expectedLeft =
settingsPageSidePadding + (area - settingsContentMaxWidth) / 2;
final groups = find.byType(SettingsGroup);
expect(groups, findsWidgets);
for (final group in groups.evaluate()) {
final rect = tester.getRect(find.byWidget(group.widget));
expect(rect.left, closeTo(expectedLeft, 0.01));
expect(rect.width, closeTo(settingsContentMaxWidth, 0.01));
}
// A header's text lines up with its rows' text.
final groupLeft = tester.getRect(find.byType(SettingsGroup).first).left;
final header = tester.getRect(find.text('Connection').first);
expect(header.left, closeTo(groupLeft + settingsRowInset, 0.01));
});
testWidgets('on a narrow window the groups fill the inset width', (
tester,
) async {
await _pump(tester, size: const Size(390, 844));
final group = tester.getRect(find.byType(SettingsGroup).first);
expect(group.left, closeTo(settingsPageSidePadding, 0.01));
expect(group.width, closeTo(390 - 2 * settingsPageSidePadding, 0.01));
});
testWidgets('Material groups are flat surfaces, not elevated cards', (
tester,
) async {
await _pump(tester);
expect(find.byType(Card), findsNothing);
final surfaces = tester.widgetList<Material>(
find.descendant(
of: find.byType(SettingsGroup),
matching: find.byType(Material),
),
);
final scheme = Theme.of(
tester.element(find.byType(SettingsGroup).first),
).colorScheme;
final groupSurfaces = surfaces.where(
(material) => material.color == scheme.surfaceContainer,
);
expect(groupSurfaces, isNotEmpty);
for (final material in groupSurfaces) {
expect(material.elevation, 0);
}
// 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').first);
final theme = Theme.of(tester.element(find.text('Connection').first));
expect(title.style?.color, theme.colorScheme.primary);
});
testWidgets('content starts below the bar, with the search field pinned', (
tester,
) async {
const barHeight = 72.0;
await _pump(tester, topPadding: barHeight);
// The search field sits under the bar and stays above the scrolling list.
final search = tester.getRect(
find.byKey(const ValueKey('settings.search')),
);
expect(search.top, closeTo(barHeight + settingsPageTopPadding, 0.01));
final list = tester.getRect(find.byKey(const ValueKey('settings.scroll')));
expect(list.top, greaterThan(search.bottom));
});
testWidgets('the notification tile is the section\'s only title', (
tester,
) async {
final notifications = NotificationController(
store: MemoryNotificationStore(),
);
addTearDown(notifications.dispose);
await _pump(tester, notifications: notifications);
await openSettingsSection(tester, 'Notifications');
expect(find.text('Notifications'), findsOneWidget);
expect(find.text('Connection'), findsOneWidget);
});
testWidgets('server rows show which server is selected', (tester) async {
final connections = ServerConnections(
store: MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [
SavedServer.validated(
id: 'Home',
name: 'Home',
endpoints: const ['wss://home.test/connect'],
),
SavedServer.validated(
id: 'Work',
name: 'Work',
endpoints: const ['wss://work.test/connect'],
),
],
selectedId: 'Home',
),
),
onSelected: (_) async {},
);
addTearDown(connections.dispose);
await connections.load();
final body = SingleChildScrollView(
child: SavedServersSection(connections: connections),
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
expect(find.byType(SavedServerRow), findsNWidgets(2));
expect(find.text('Pipelines and runs server'), findsOneWidget);
expect(
find.byWidgetPredicate(
(widget) => widget is Icon && widget.semanticLabel == 'Selected',
),
findsOneWidget,
);
expect(find.text('Address: wss://work.test/connect'), findsOneWidget);
expect(find.byKey(savedServerMenuKey('Home')), findsOneWidget);
expect(find.text('Add server'), findsOneWidget);
// Tapping another server's row uses it.
await tester.tap(find.text('Work'));
await tester.pumpAndSettle();
expect(connections.catalog.active?.id, 'Work');
});
}
Future<void> _pump(
WidgetTester tester, {
NotificationController? notifications,
Size size = const Size(800, 1600),
double topPadding = 0,
}) async {
await tester.binding.setSurfaceSize(size);
addTearDown(() => tester.binding.setSurfaceSize(null));
final factory = FakeChannelFactory();
final client = transport.PipelinesClient(channelFactory: factory.call);
addTearDown(client.dispose);
final screen = SettingsScreen(
client: client,
store: MemorySettingsStore(),
notifications: notifications,
embedded: true,
);
Widget padded(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(padding: EdgeInsets.only(top: topPadding)),
child: child!,
);
await tester.pumpWidget(
MaterialApp(
builder: padded,
home: Scaffold(body: screen),
),
);
await tester.pump();
await tester.pump();
await openSettingsSection(tester, 'Connection');
}