import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/shell/list_detail.dart'; import 'package:pipelines_app/shell/list_pane_divider.dart'; final _body = find.byKey(const ValueKey('list-detail-body')); Widget _panes({required bool hidden, bool reduceMotion = false}) => MaterialApp( home: Builder( builder: (context) => MediaQuery( data: MediaQuery.of(context).copyWith(disableAnimations: reduceMotion), child: Scaffold( body: ListDetailPanes( listHidden: hidden, list: const Focus( autofocus: true, child: Text('The list', key: Key('list-text')), ), detail: const SizedBox.expand(), ), ), ), ), ); void _size(WidgetTester tester) { tester.view.physicalSize = const Size(1200, 800); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); } void main() { testWidgets('a hidden list slides to zero width and comes back as it was', ( tester, ) async { _size(tester); await tester.pumpWidget(_panes(hidden: false)); await tester.pumpAndSettle(); final shown = tester.getRect(_body).left; expect(shown, greaterThan(200)); expect(find.byType(ListPaneDivider), findsOneWidget); await tester.pumpWidget(_panes(hidden: true)); await tester.pump(const Duration(milliseconds: 60)); final sliding = tester.getRect(_body).left; expect(sliding, inExclusiveRange(0, shown), reason: 'animates'); // The handle is not offered while the list slides or is hidden. expect(find.byType(ListPaneDivider), findsNothing); await tester.pumpAndSettle(); expect(tester.getRect(_body).left, 0); expect(tester.getRect(_body).width, 1200); // Nothing in the hidden list keeps the keyboard. final listFocus = Focus.of( tester.element(find.byKey(const Key('list-text'))), ); expect(listFocus.hasFocus, isFalse); await tester.pumpWidget(_panes(hidden: false)); await tester.pumpAndSettle(); expect(tester.getRect(_body).left, shown); expect(find.byType(ListPaneDivider), findsOneWidget); }); testWidgets('with reduced motion the list hides at once', (tester) async { _size(tester); await tester.pumpWidget(_panes(hidden: false, reduceMotion: true)); await tester.pumpAndSettle(); await tester.pumpWidget(_panes(hidden: true, reduceMotion: true)); await tester.pump(); await tester.pump(); expect(tester.getRect(_body).left, 0); }); }