import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/terminal/terminal_hub.dart'; import 'package:pipelines_app/features/terminal/terminal_layout.dart'; import 'terminal_app.dart'; import 'terminal_fixtures.dart'; void main() { late TerminalGateway mac; late TerminalHub hub; late TerminalLayout layout; setUp(() { mac = TerminalGateway()..add('term_a', cwd: '/Users/op/src'); hub = TerminalHub(TestMachines([machine('mac', mac, name: 'Mac')])); layout = TerminalLayout(store: MemoryLayoutStore()); }); tearDown(() async { hub.dispose(); await mac.close(); }); const shown = 800 - terminalPanelDefaultHeight; double appBottom(WidgetTester tester) => tester.getRect(find.byType(Scaffold).first).bottom; double panelOpacity(WidgetTester tester) => tester .widget( find .ancestor(of: panelFinder, matching: find.byType(FadeTransition)) .first, ) .opacity .value; ScaleTransition floatScale(WidgetTester tester) => tester.widget( find .descendant( of: floatLayer, matching: find.byType(ScaleTransition, skipOffstage: false), skipOffstage: false, ) .first, ); testWidgets('the panel slides up from the bottom edge as the app above ' 'shrinks, and slides away still mounted', (tester) async { await pumpTerminalApp(tester, hub: hub, layout: layout); await tester.tap(find.byKey(appField)); await tester.pump(); await altT(tester, settle: false); await tester.pump(const Duration(milliseconds: 100)); expect(panelFinder, findsOneWidget); // Midway: the app has given up part of the panel's height, and the // panel (at its full height) is partly below the window's edge. expect(appBottom(tester), inExclusiveRange(shown, 800)); expect(tester.getRect(panelFinder).top, closeTo(appBottom(tester), 1)); expect(tester.getSize(panelFinder).height, terminalPanelDefaultHeight); expect(panelOpacity(tester), inExclusiveRange(0.4, 1)); await tester.pumpAndSettle(); expect(appBottom(tester), shown); expect(panelOpacity(tester), 1); await altT(tester, settle: false); // The keyboard is back in the field at once; the panel leaves after. expect(appFieldFocused(tester), isTrue); await tester.pump(const Duration(milliseconds: 100)); expect(panelFinder, findsOneWidget); expect(appBottom(tester), inExclusiveRange(shown, 800)); await tester.pumpAndSettle(); expect(panelFinder, findsNothing); expect(appBottom(tester), 800); expect(appFieldFocused(tester), isTrue); }); testWidgets('the floating window grows and fades in from its place, and ' 'shrinks away', (tester) async { layout.setMode(TerminalMode.float); await pumpTerminalApp(tester, hub: hub, layout: layout); await altT(tester, settle: false); // The window is built, then its motion starts. await tester.pump(); await tester.pump(const Duration(milliseconds: 100)); final scale = floatScale(tester).scale.value; expect(scale, inExclusiveRange(0.92, 1)); // The app underneath never moves for a window. expect(appBottom(tester), 800); await tester.pumpAndSettle(); expect(floatScale(tester).scale.value, 1); await altT(tester, settle: false); await tester.pump(const Duration(milliseconds: 100)); // Hiding: no longer shown, still painted while it shrinks away. expect(floatFinder, findsNothing); expect(floatScale(tester).scale.value, inExclusiveRange(0.92, 1)); await tester.pumpAndSettle(); expect(floatFinder, findsNothing); }); testWidgets('the motion follows the animation speed setting', (tester) async { // AnimationSpeedController plays animations at half speed this way. timeDilation = 2; await pumpTerminalApp(tester, hub: hub, layout: layout); await altT(tester, settle: false); await tester.pump(const Duration(milliseconds: 300)); expect(appBottom(tester), inExclusiveRange(shown, 800)); await tester.pumpAndSettle(); expect(appBottom(tester), shown); timeDilation = 1; }); testWidgets('with reduced motion the terminal shows and hides at once', ( tester, ) async { await pumpTerminalApp(tester, hub: hub, layout: layout, reduceMotion: true); await altT(tester, settle: false); await tester.pump(); expect(appBottom(tester), shown); expect(panelOpacity(tester), 1); await altT(tester, settle: false); await tester.pump(); expect(panelFinder, findsNothing); expect(appBottom(tester), 800); layout.setMode(TerminalMode.float); await altT(tester, settle: false); await tester.pump(); expect(floatScale(tester).scale.value, 1); // The emulator's size reaches the server after its debounce. await tester.pump(const Duration(milliseconds: 300)); }); }