halkyon/packages/halkyon_ui/test/widget/scroll_hiding_fab_test.dart
Tizian 「ティツィアーン」 80fa7b9628
Halkyon's shared packages
A pub workspace of the Dart packages Halkyon's apps share: halkyon_ui,
Halkyon's look (the theme, fonts, layout and shared widgets, with texts
in English and German), halkyon_core's low-level primitives and
halkyon_interop's cross-app contracts. Dart 3.13 with LeanCode's lints,
configured once at the root; apps take a package by git, pinned to a
signed commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-18 21:50:15 +02:00

58 lines
1.7 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_ui/halkyon_ui.dart';
import 'package:material_ui/material_ui.dart';
void main() {
/// A list of [lines] with a button that hides while reading onwards.
Future<void> show(WidgetTester tester, {int lines = 100}) async {
tester.view.physicalSize = const Size(400, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
home: ScrollHidingFab(
builder: (context, fab) => Scaffold(
floatingActionButton: fab,
body: ListView(
children: [
for (var i = 0; i < lines; i++)
SizedBox(height: 48, child: Text('Line $i')),
],
),
),
fab: FloatingActionButton(
tooltip: 'New studyset',
onPressed: () {},
child: const Icon(Icons.add),
),
),
),
);
}
Finder fab() => find.byTooltip('New studyset').hitTestable();
testWidgets('hides while scrolling down and returns when scrolling up', (
tester,
) async {
await show(tester);
expect(fab(), findsOneWidget);
await tester.drag(find.byType(ListView), const Offset(0, -300));
await tester.pumpAndSettle();
expect(fab(), findsNothing);
await tester.drag(find.byType(ListView), const Offset(0, 100));
await tester.pumpAndSettle();
expect(fab(), findsOneWidget);
});
testWidgets('stays when the list fits without scrolling', (tester) async {
await show(tester, lines: 3);
await tester.drag(find.byType(ListView), const Offset(0, -300));
await tester.pumpAndSettle();
expect(fab(), findsOneWidget);
});
}