Files
alan a7c41063fa Remove Cupertino branches from Settings
Keep the Material-only settings implementation and its focused tests while preserving public cupertino parameters for later cleanup. This removes unreachable platform-specific widgets and test variants without changing the Material path.
2026-11-11 05:05:57 +00:00

188 lines
6.4 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_topic_test_helper.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').last);
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').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 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 +
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,
);
});
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 selectSettingsTopic(tester, 'Notifications');
expect(find.text('Notifications'), findsNWidgets(2));
expect(find.text('Connection').last, 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 selectSettingsTopic(tester, 'Connection');
}