import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/application/app_terminals.dart'; import 'package:pipelines_app/application/detached/detached_route.dart'; import 'package:pipelines_app/application/detached/detached_terminal.dart'; import 'package:pipelines_app/application/detached/detached_window_body.dart'; import 'package:pipelines_app/features/terminal/terminal_hub.dart'; import 'package:pipelines_app/features/terminal/terminal_layout.dart'; import 'package:pipelines_app/features/terminal/terminal_tab_strip.dart'; import 'package:pipelines_app/shell/detached/detached_window_scope.dart'; import '../../application/detached/detached_fixtures.dart'; import 'terminal_fixtures.dart'; void main() { testWidgets('the options menu sends the terminal to a new window', ( tester, ) async { final mac = TerminalGateway()..add('t1', text: 'hello\r\n'); addTearDown(mac.close); final hub = TerminalHub(TestMachines([machine('mac', mac)]))..activate(); addTearDown(hub.dispose); await tester.runAsync(hub.listed); final layout = TerminalLayout(store: MemoryLayoutStore())..show(); final opener = FakeOpener(); await tester.pumpWidget( DetachedWindowScope( opener: opener, child: MaterialApp( home: Scaffold( body: TerminalTabStrip(hub: hub, layout: layout), ), ), ), ); await tester.tap(find.byTooltip('Terminal options')); await tester.pumpAndSettle(); await tester.tap(find.byKey(const ValueKey('terminal-new-window'))); await tester.pumpAndSettle(); expect(opener.terminals, ['mac/t1']); expect(layout.visible, isFalse, reason: 'it leaves the main window'); }); testWidgets('without platform windows the menu has no such choice', ( tester, ) async { final hub = TerminalHub(TestMachines([])); addTearDown(hub.dispose); await tester.pumpWidget( MaterialApp( home: Scaffold( body: TerminalTabStrip( hub: hub, layout: TerminalLayout(store: MemoryLayoutStore()), ), ), ), ); await tester.tap(find.byTooltip('Terminal options')); await tester.pumpAndSettle(); expect(find.byKey(const ValueKey('terminal-new-window')), findsNothing); expect(find.text('Floating window'), findsOneWidget); }); test('a layout that does not persist never saves', () async { final store = MemoryLayoutStore(); final layout = TerminalLayout(store: store)..persist = false; layout ..setFontSize(18) ..show(); await layout.save(); expect(store.saves, 0); expect(layout.fontSize, 18, reason: 'the window still follows it'); }); testWidgets('a detached terminal opens on its tab, without modes, and ' 'gives it back', (tester) async { final mac = TerminalGateway() ..add('t1', text: 'one\r\n') ..add('t2', text: 'two\r\n'); addTearDown(mac.close); final connection = ValueNotifier(0); final terminals = AppTerminals( pool: null, connection: connection, connected: () => true, gateway: mac, machineId: 'mac', machineName: () => 'Mac', layout: TerminalLayout(store: MemoryLayoutStore()), ); addTearDown(terminals.dispose); final back = <(DetachedKind, String)>[]; final titles = []; await tester.pumpWidget( MaterialApp( home: DetachedTerminal( terminals: terminals, tabKey: 'mac/t2', window: DetachedWindowControls( ready: ValueNotifier(true), sync: ValueNotifier(0), setTitle: titles.add, close: () {}, bringBackItem: (kind, id, _, _) => back.add((kind, id)), ), ), ), ); await tester.runAsync(terminals.hub.listed); await tester.pump(); expect(terminals.hub.selected?.key, 'mac/t2'); expect(titles.last, startsWith('Terminal')); // There is no panel or floating mode to choose in a window of its own. expect(find.byTooltip('Terminal options'), findsNothing); await tester.tap(find.byTooltip('Bring back to main window')); expect(back, [(DetachedKind.terminal, 'mac/t2')]); await tester.pumpWidget(const SizedBox()); }); }