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 'terminal_app.dart'; import 'terminal_fixtures.dart'; const _dot = ValueKey('terminal-tab-bell'); 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/docs', 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(); }); /// Lets a pushed frame arrive and draw. Future drain(WidgetTester tester) async { for (var i = 0; i < 3; i++) { await tester.pump(const Duration(milliseconds: 1)); } } Future open(WidgetTester tester) async { await pumpTerminalApp(tester, hub: hub, layout: layout); await tester.pumpAndSettle(); expect(hub.tabs, hasLength(2)); expect(hub.selected!.info.id, 'term_a'); } testWidgets('a bell in a tab that is not shown dots it until it is ' 'selected; the shown tab only flashes', (tester) async { final semantics = tester.ensureSemantics(); await open(tester); mac.write('term_b', '\x07'); await drain(tester); expect(find.byKey(_dot), findsOneWidget); expect(find.bySemanticsLabel(RegExp(r'\bBell\b')), findsOneWidget); semantics.dispose(); // The shown terminal flashes instead. mac.write('term_a', '\x07'); await drain(tester); expect(find.byKey(const ValueKey('terminal-bell-flash')), findsOneWidget); expect(find.byKey(_dot), findsOneWidget); await tester.tap(find.text('docs')); await tester.pumpAndSettle(); expect(find.byKey(_dot), findsNothing); // Hidden, every tab dots; turned off, none does. layout.hide(); await tester.pumpAndSettle(); mac.write('term_b', '\x07'); await drain(tester); expect(hub.tabs.last.bellUnseen, isTrue); layout.show(); await tester.pumpAndSettle(); expect(hub.tabs.last.bellUnseen, isFalse); layout.setBell(false); mac.write('term_a', '\x07'); await tester.pumpAndSettle(); expect(hub.tabs.first.bellUnseen, isFalse); }); testWidgets('a folder reported with OSC 7 names an untitled tab and its ' 'tooltip; a shell title still wins', (tester) async { await open(tester); mac.write('term_a', '\x1b]7;file://mac/Users/op/src/app\x07'); await drain(tester); expect(find.text('app'), findsOneWidget); expect(hub.tabs.first.cwd, '/Users/op/src/app'); expect(find.byTooltip('app\nMac: /Users/op/src/app'), findsOneWidget); mac.write('term_a', '\x1b]0;vim notes\x07'); await drain(tester); expect(find.text('vim notes'), findsOneWidget); expect(find.text('app'), findsNothing); }); }