Files
pipelines/app/test/features/settings/settings_layout_test.dart
T
alan 3ec580c2d9 Restyle Settings as flat grouped list sections (F9) and scroll it behind the bar (F1)
Servers become rows with a selection mark, addresses as subtitles and a
Use/Edit/Remove menu plus an Add server row; the connection is a status row
with address and Reconnect/Disconnect rows; Templates and Schedules are
chevron rows in a Library group. Material groups are flat surfaceContainer
surfaces with primary titleSmall headers (no Cards); Cupertino uses
inset-grouped sections on the grouped background, switches for the ntfy
choices. The trust warning is a footer, helper copy is shortened, Save
workspace is a legible tonal/plain button, and the column starts at the
bar's inset (max 720) instead of being centred. The page pads by the top
media padding instead of a top SafeArea.
2026-10-31 03:07:20 +00:00

226 lines
7.7 KiB
Dart

import 'package:flutter/cupertino.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 'package:pipelines_app/ui/theme/app_theme.dart';
import 'fake_channel.dart';
void main() {
testWidgets('groups start at the bar inset and stop at the reading width', (
tester,
) async {
await _pump(tester, size: const Size(1200, 1600));
final groups = find.byType(SettingsGroup);
expect(groups, findsWidgets);
for (final group in groups.evaluate()) {
final rect = tester.getRect(find.byWidget(group.widget));
// The column starts where the bar's title pill does, not centred.
expect(rect.left, closeTo(settingsPageSidePadding, 0.01));
expect(rect.width, closeTo(settingsContentMaxWidth, 0.01));
}
// A header's text lines up with its rows' text.
final header = tester.getRect(find.text('Connection'));
expect(
header.left,
closeTo(settingsPageSidePadding + settingsRowInset, 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'));
final theme = Theme.of(tester.element(find.text('Connection')));
expect(title.style?.color, theme.colorScheme.primary);
});
testWidgets('content starts below the bar and scrolls behind it', (
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,
);
});
testWidgets('Cupertino uses inset-grouped sections on the grouped page', (
tester,
) async {
await _pump(tester, platform: TargetPlatform.iOS);
expect(find.byType(Card), findsNothing);
expect(find.byType(CupertinoListSection), findsWidgets);
for (final section in tester.widgetList<CupertinoListSection>(
find.byType(CupertinoListSection),
)) {
expect(section.type, CupertinoListSectionType.insetGrouped);
}
final context = tester.element(find.byType(SettingsGroup).first);
expect(
find.byWidgetPredicate(
(widget) =>
widget is ColoredBox &&
widget.color == AppColors.groupedBackground.resolveFrom(context),
),
findsWidgets,
);
});
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);
expect(find.text('Notifications'), findsOneWidget);
expect(find.text('Connection'), findsOneWidget);
});
testWidgets('Cupertino keeps the compact secondary field label', (
tester,
) async {
await _pump(tester, platform: TargetPlatform.iOS);
final label = tester.widget<Text>(find.text('Server URL'));
final context = tester.element(find.text('Server URL'));
expect(
label.style?.color,
CupertinoColors.secondaryLabel.resolveFrom(context),
);
expect(find.byType(CupertinoTextField), findsNWidgets(2));
});
for (final cupertino in [false, true]) {
testWidgets('server rows show which server is selected ($cupertino)', (
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(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
expect(find.byType(SavedServerRow), findsNWidgets(2));
expect(find.text('Selected server'), findsOneWidget);
expect(
find.byWidgetPredicate(
(widget) => widget is Icon && widget.semanticLabel == 'Selected',
),
findsOneWidget,
);
expect(find.text('Preferred: 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, {
TargetPlatform platform = TargetPlatform.android,
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);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: platform),
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(padding: EdgeInsets.only(top: topPadding)),
child: child!,
),
home: Scaffold(
body: SettingsScreen(
client: client,
store: MemorySettingsStore(),
notifications: notifications,
embedded: true,
),
),
),
);
await tester.pump();
await tester.pump();
}