|
| 1 | +/* |
| 2 | + * This file is part of wger Workout Manager <https://github.com/wger-project>. |
| 3 | + * Copyright (c) 2026 - 2026 wger Team |
| 4 | + * |
| 5 | + * wger Workout Manager is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Affero General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Affero General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Affero General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +import 'package:flutter/material.dart'; |
| 20 | +import 'package:flutter_test/flutter_test.dart'; |
| 21 | +import 'package:wger/core/widgets/scroll_behavior.dart'; |
| 22 | + |
| 23 | +void main() { |
| 24 | + ScrollMetrics metrics({double? minExtent, double? maxExtent, double? pixels}) { |
| 25 | + return FixedScrollMetrics( |
| 26 | + minScrollExtent: minExtent, |
| 27 | + maxScrollExtent: maxExtent, |
| 28 | + pixels: pixels, |
| 29 | + viewportDimension: 100, |
| 30 | + axisDirection: AxisDirection.down, |
| 31 | + devicePixelRatio: 1, |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + group('LaidOutScrollPhysics', () { |
| 36 | + const physics = LaidOutScrollPhysics(); |
| 37 | + |
| 38 | + test('rejects user offsets before the viewport has content dimensions', () { |
| 39 | + expect(physics.shouldAcceptUserOffset(metrics()), isFalse); |
| 40 | + }); |
| 41 | + |
| 42 | + test('delegates to the parent once laid out', () { |
| 43 | + final chained = physics.applyTo(const ClampingScrollPhysics()); |
| 44 | + |
| 45 | + expect( |
| 46 | + chained.shouldAcceptUserOffset(metrics(minExtent: 0, maxExtent: 50, pixels: 0)), |
| 47 | + isTrue, |
| 48 | + ); |
| 49 | + expect( |
| 50 | + chained.shouldAcceptUserOffset(metrics(minExtent: 0, maxExtent: 0, pixels: 0)), |
| 51 | + isFalse, |
| 52 | + ); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + testWidgets('WgerScrollBehavior wraps the platform physics', (tester) async { |
| 57 | + late ScrollPhysics physics; |
| 58 | + await tester.pumpWidget( |
| 59 | + MaterialApp( |
| 60 | + scrollBehavior: const WgerScrollBehavior(), |
| 61 | + home: Builder( |
| 62 | + builder: (context) { |
| 63 | + physics = ScrollConfiguration.of(context).getScrollPhysics(context); |
| 64 | + return const SizedBox(); |
| 65 | + }, |
| 66 | + ), |
| 67 | + ), |
| 68 | + ); |
| 69 | + |
| 70 | + expect(physics, isA<LaidOutScrollPhysics>()); |
| 71 | + expect(physics.parent, isNotNull); |
| 72 | + }); |
| 73 | +} |
0 commit comments