import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart'; import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/list_detail.dart'; /// On a wide split window a page an item opened in its pane (a run's stage /// page) closes when another item is selected, so the pane shows the newly /// selected item instead of the old item's page. void main() { testWidgets("selecting another item closes the previous item's page", ( tester, ) async { tester.view.physicalSize = const Size(1200, 800); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); final selected = ValueNotifier(1); addTearDown(selected.dispose); Widget detail(int id) => Builder( builder: (context) => Center( child: GestureDetector( key: const Key('open-page'), onTap: () => Navigator.of(context).push( PageRouteBuilder( pageBuilder: (_, _, _) => Text('page of item $id'), ), ), child: Text('item $id'), ), ), ); final shell = AdaptiveShell( destination: AppDestination.runs, destinationBodies: { AppDestination.runs: (_) => ValueListenableBuilder( valueListenable: selected, builder: (_, id, _) => ListDetailPanes( list: const Text('list'), detailIdentity: id, detail: detail(id), ), ), }, ); await tester.pumpWidget( MaterialApp( theme: ThemeData(platform: TargetPlatform.android), home: shell, ), ); await tester.pumpAndSettle(); await tester.tap(find.byKey(const Key('open-page'))); await tester.pumpAndSettle(); expect(find.text('page of item 1'), findsOneWidget); // The same item rebuilt keeps its page open. selected.value = 1; await tester.pumpAndSettle(); expect(find.text('page of item 1'), findsOneWidget); selected.value = 2; await tester.pumpAndSettle(); expect(find.text('page of item 1'), findsNothing); expect(find.text('item 2'), findsOneWidget); }); }