Files
pipelines/app/test/ui/layout/sticky_section_test.dart
T

65 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/sticky_section.dart';
class _Host extends StatefulWidget {
const _Host();
@override
State<_Host> createState() => _HostState();
}
class _HostState extends State<_Host> {
bool open = true;
@override
Widget build(BuildContext context) => CustomScrollView(
slivers: [
StickySection(
title: 'Input',
open: open,
onToggle: () => setState(() => open = !open),
body: Column(children: [for (var i = 0; i < 80; i++) Text('line $i')]),
),
const SliverToBoxAdapter(child: SizedBox(height: 900)),
],
);
}
void main() {
testWidgets(
'the title stays pinned while its content scrolls and closes it',
(tester) async {
tester.view.physicalSize = const Size(390, 600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(const MaterialApp(home: Scaffold(body: _Host())));
await tester.drag(find.byType(CustomScrollView), const Offset(0, -800));
await tester.pumpAndSettle();
// Deep in the content, the title is still at the top.
expect(tester.getTopLeft(find.text('line 0')).dy, lessThan(0));
expect(tester.getTopLeft(find.text('Input')).dy, lessThan(40));
await tester.tap(find.text('Input'));
await tester.pumpAndSettle();
expect(find.text('line 40'), findsNothing);
},
);
testWidgets('a tap anywhere on the title strip toggles the section', (
tester,
) async {
tester.view.physicalSize = const Size(390, 600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(const MaterialApp(home: Scaffold(body: _Host())));
expect(find.text('line 0'), findsOneWidget);
// Empty space well right of the short title, left of the chevron.
final strip = tester.getRect(find.byType(StickySectionTitle));
await tester.tapAt(Offset(strip.center.dx + 60, strip.center.dy));
await tester.pumpAndSettle();
expect(find.text('line 0'), findsNothing);
});
}