import 'dart:convert'; import 'package:flutter/material.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 'package:pipelines_app/features/terminal/terminal_panel.dart'; import 'package:pipelines_app/features/terminal/terminal_tab_chip.dart'; import 'terminal_app.dart'; import 'terminal_fixtures.dart'; /// The bottom panel's default height (40 % of the window, at least 16 rows) /// and the tab strip's tabs: long titles ellipsised with the whole title in /// the tooltip, the selected tab marked, close buttons of touch size. void main() { late TerminalGateway mac; late TerminalHub hub; late TerminalLayout layout; setUp(() { mac = TerminalGateway() ..add('term_a', cwd: '/Users/op/src', text: r'$ ') ..add( 'term_b', cwd: '/Users/op/a/rather/deep/folder/with/a/long/name/that/goes/on', text: r'$ ', ); layout = TerminalLayout(store: MemoryLayoutStore())..visible = true; hub = TerminalHub( TestMachines([machine('mac', mac, name: 'Mac')]), layout: layout, ); }); tearDown(() async { hub.dispose(); await mac.close(); }); test('the default height is 40 % of the window, at least 16 rows', () { expect(terminalPanelDefaultHeight(1000, 17), 400); expect(terminalPanelDefaultHeight(600, 17), 16 * 17 + terminalPanelChrome); // A short window still leaves the app its share. expect( terminalPanelHeight(null, 400, rowHeight: 17), 400 - terminalPanelAppMin, ); expect(terminalPanelHeight(500, 1000, rowHeight: 17), 500); }); test('a layout saved with the old fixed default reads as never resized; ' 'a dragged height is restored', () async { final store = MemoryLayoutStore(); await store.save(jsonEncode({'panel_height': 300})); final legacy = TerminalLayout(store: store); await legacy.restore(); expect(legacy.panelHeight, isNull); await store.save(jsonEncode({'panel_height': 412.5})); final dragged = TerminalLayout(store: store); await dragged.restore(); expect(dragged.panelHeight, 412.5); }); for (final size in const [Size(1280, 900), Size(1920, 1080)]) { testWidgets('at ${size.width.round()}x${size.height.round()} the panel ' 'opens at 40 % of the window and shows at least 16 rows', ( tester, ) async { await pumpTerminalApp(tester, hub: hub, layout: layout, size: size); await tester.pumpAndSettle(); final panel = tester.getSize(panelFinder).height; expect(panel, greaterThanOrEqualTo(size.height * 0.4 - 1)); // The emulator lays out its rows after the debounced resize. await tester.pump(const Duration(milliseconds: 300)); expect( hub.selected!.session.terminal.viewHeight, greaterThanOrEqualTo(16), ); }); } testWidgets('a long tab title ends in an ellipsis and its tooltip has it ' 'whole; the selected tab is marked; close buttons are at least 40 px', ( tester, ) async { await pumpTerminalApp(tester, hub: hub, layout: layout); await tester.pumpAndSettle(); final chips = find.byType(TerminalTabChip); expect(chips, findsNWidgets(2)); final long = tester.widget(chips.last); final title = find.descendant(of: chips.last, matching: find.byType(Text)); expect( tester.getSize(title.first).width, lessThanOrEqualTo(terminalTabTitleMaxWidth), ); expect(tester.widget(title.first).overflow, TextOverflow.ellipsis); expect(long.tooltip, contains(long.title)); expect(long.tooltip, contains('Mac: /Users/op/a/rather/deep')); expect(tester.widget(chips.first).selected, isTrue); expect(long.selected, isFalse); final selectedText = tester.widget( find.descendant(of: chips.first, matching: find.byType(Text)).first, ); expect(selectedText.style?.fontWeight, FontWeight.w700); for (final close in tester .elementList(find.byTooltip('Close terminal')) .map((element) => element.renderObject! as RenderBox)) { expect(close.size.width, greaterThanOrEqualTo(40)); expect(close.size.height, greaterThanOrEqualTo(40)); } // Selecting by the title. await tester.tap(title.first); await tester.pumpAndSettle(); expect(hub.selected!.info.id, 'term_b'); }); testWidgets( 'on a touch platform the close buttons are 48 px', (tester) async { await pumpTerminalApp(tester, hub: hub, layout: layout); await tester.pumpAndSettle(); final close = tester.getSize( find.widgetWithIcon(IconButton, Icons.close).first, ); expect(close.width, greaterThanOrEqualTo(48)); expect(close.height, greaterThanOrEqualTo(48)); }, variant: TargetPlatformVariant.only(TargetPlatform.android), ); }