Files
pipelines/app/test/features/settings/settings_search_page_test.dart
T
alan 0e5a06ae88 Fix the 11 failing application tests: two product fixes, stale fixtures
Product:
- Settings jump index scrolls instead of overflowing a short wide window
  (overflowed by 48 px at 1200x800 once Open in chat added a section).
- Chat: a route to the retained workspace's active pane shows it in the
  same frame again; ec3c1e4c deferred it a frame behind a post-frame callback.

Tests updated to intended behaviour:
- first-run walkthrough (30ba70ad): seed a device that has seen it and was
  offered it for the fixture server;
- Output section open by default (22af093e);
- chat page Back closes its own route explicitly (19b1d132);
- open-chat sync (c48a1559): answer chat_open_workspace statefully;
- keyed session list (0a51add9) no longer re-reads chat_sessions on open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 01:58:57 +00:00

266 lines
7.9 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/settings_search_page.dart';
import 'package:pipelines_app/features/settings/settings_section.dart';
import 'package:pipelines_app/features/settings/settings_server_load.dart';
import 'package:pipelines_app/features/settings/settings_server_view.dart';
/// Fills the page so a section placed after it starts far below the viewport.
List<SettingsSection> _filler(int count) => [
for (var i = 0; i < count; i++)
SettingsSection(
id: 'filler-$i',
title: 'Filler $i',
builder: (_) => const SizedBox(height: 400, child: Text('filler body')),
),
];
Future<void> _pump(
WidgetTester tester,
List<SettingsSection> sections, {
Size size = const Size(800, 600),
}) async {
await tester.binding.setSurfaceSize(size);
addTearDown(() => tester.binding.setSurfaceSize(null));
await tester.pumpWidget(
MaterialApp(
home: Scaffold(body: SettingsSearchPage(sections: sections)),
),
);
await tester.pump();
await tester.pump();
}
void main() {
testWidgets('local settings render while a server section has not answered', (
tester,
) async {
var fetches = 0;
final reply = Completer<int>();
final load = ServerLoad<int>(() {
fetches++;
return reply.future;
});
addTearDown(load.dispose);
await _pump(tester, [
..._filler(6),
SettingsSection(
id: 'server',
title: 'Phone notifications',
lazy: true,
builder: (_) => ServerSettingsView<int>(
load: load,
builder: (_, value) => Text('Server $value'),
),
),
]);
// The local sections are built and the server section is only a skeleton:
// no request runs until the list reaches it.
expect(find.text('filler body'), findsWidgets);
expect(find.text('Phone notifications'), findsOneWidget);
expect(fetches, 0);
expect(tester.takeException(), isNull);
await tester.ensureVisible(find.text('Phone notifications'));
await tester.pump();
await tester.pump();
expect(fetches, 1);
// The reply is still pending, and the page keeps working.
expect(find.bySemanticsLabel('Loading'), findsOneWidget);
expect(find.text('filler body'), findsWidgets);
reply.complete(3);
await tester.pump();
expect(find.text('Server 3'), findsOneWidget);
});
testWidgets('search filters sections by title and keywords', (tester) async {
await _pump(tester, [
SettingsSection(
id: 'animations',
title: 'Animations',
keywords: 'motion speed',
builder: _titled('Animations'),
),
SettingsSection(
id: 'terminal',
title: 'Terminal',
keywords: 'layout split',
builder: _titled('Terminal'),
),
]);
expect(find.text('Animations'), findsOneWidget);
expect(find.text('Terminal'), findsOneWidget);
await tester.enterText(
find.byKey(const ValueKey('settings.search')),
'motion',
);
await tester.pump();
expect(find.text('Animations'), findsOneWidget);
expect(find.text('Terminal'), findsNothing);
// Every word must match: "motion layout" matches neither section.
await tester.enterText(
find.byKey(const ValueKey('settings.search')),
'motion layout',
);
await tester.pump();
expect(find.text('Animations'), findsNothing);
expect(find.text('Terminal'), findsNothing);
expect(find.textContaining('No settings match'), findsOneWidget);
await tester.tap(find.byTooltip('Clear search'));
await tester.pump();
expect(find.text('Animations'), findsOneWidget);
expect(find.text('Terminal'), findsOneWidget);
});
testWidgets('a search that matches a server section loads it at once', (
tester,
) async {
var fetches = 0;
final load = ServerLoad<int>(() async {
fetches++;
return 9;
});
addTearDown(load.dispose);
await _pump(tester, [
..._filler(6),
SettingsSection(
id: 'server',
title: 'Phone notifications',
keywords: 'ntfy push',
lazy: true,
builder: (_) => ServerSettingsView<int>(
load: load,
builder: (_, value) => Text('Server $value'),
),
),
]);
expect(fetches, 0);
await tester.enterText(
find.byKey(const ValueKey('settings.search')),
'ntfy',
);
await tester.pump();
await tester.pump();
await tester.pump();
expect(fetches, 1);
expect(find.text('Server 9'), findsOneWidget);
expect(find.text('filler body'), findsNothing);
});
testWidgets(
'a failing server section shows its own Retry; others are unaffected',
(tester) async {
var attempts = 0;
final load = ServerLoad<String>(() async {
attempts++;
if (attempts == 1) throw StateError('server unreachable');
return 'Stored';
});
addTearDown(load.dispose);
await _pump(tester, [
SettingsSection(
id: 'local',
title: 'Animations',
builder: (_) =>
const Column(children: [Text('Animations'), Text('Local value')]),
),
SettingsSection(
id: 'server',
title: 'Sign-in security',
lazy: true,
builder: (_) => ServerSettingsView<String>(
load: load,
retryKey: const Key('server-retry'),
builder: (_, value) => Text('Security $value'),
),
),
]);
await tester.pump();
expect(find.textContaining('server unreachable'), findsOneWidget);
expect(find.byKey(const Key('server-retry')), findsOneWidget);
expect(find.text('Local value'), findsOneWidget);
expect(find.text('Animations'), findsOneWidget);
await tester.tap(find.byKey(const Key('server-retry')));
await tester.pump();
await tester.pump();
expect(attempts, 2);
expect(find.text('Security Stored'), findsOneWidget);
expect(find.byKey(const Key('server-retry')), findsNothing);
expect(find.text('Local value'), findsOneWidget);
},
);
testWidgets('wide layouts list every visible section in the jump index', (
tester,
) async {
final sections = [
SettingsSection(
id: 'animations',
title: 'Animations',
builder: _titled('Animations'),
),
SettingsSection(
id: 'terminal',
title: 'Terminal',
builder: _titled('Terminal'),
),
];
await _pump(tester, sections, size: const Size(1200, 800));
expect(
find.byKey(const ValueKey('settings.index.animations')),
findsOneWidget,
);
expect(
find.byKey(const ValueKey('settings.index.terminal')),
findsOneWidget,
);
await tester.tap(find.byKey(const ValueKey('settings.index.terminal')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(tester.takeException(), isNull);
});
testWidgets('a short wide window scrolls the jump index to its last link', (
tester,
) async {
// More links than a 600 px tall index fits: it must scroll, not overflow.
await _pump(tester, _filler(30), size: const Size(1200, 600));
expect(tester.takeException(), isNull);
final last = find.byKey(const ValueKey('settings.index.filler-29'));
await tester.ensureVisible(last);
await tester.pumpAndSettle();
await tester.tap(last);
await tester.pumpAndSettle();
expect(find.text('Filler 29'), findsWidgets);
expect(tester.takeException(), isNull);
});
testWidgets('a narrow layout has no jump index', (tester) async {
await _pump(tester, [
SettingsSection(
id: 'animations',
title: 'Animations',
builder: _titled('Animations'),
),
], size: const Size(390, 844));
expect(
find.byKey(const ValueKey('settings.index.animations')),
findsNothing,
);
});
}
WidgetBuilder _titled(String title) =>
(_) => Text(title);