Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness_mobile/auth/auth_session.dart';
import 'package:harness_mobile/core/config.dart';
import 'package:harness_mobile/phone/terminal_page.dart';
import 'package:harness_mobile/phone/voice_input_controller.dart';
import 'package:harness_mobile/state/app_state.dart';
import 'package:harness_mobile/terminal/terminal_session.dart';
import 'package:xterm/xterm.dart';
import 'voice_fakes.dart';
/// Reading back through the history while the agent keeps writing: output
/// never moves the screen being read, tmux's copy-mode position says where the
/// reader is, and one tap on it is back at the end.
void main() {
late AppNotifier notifier;
late TerminalSession session;
late VoiceInputController voice;
late ValueNotifier<String> language;
late List<Map<String, dynamic>> resizes;
setUp(() {
notifier = AppNotifier(
config: AppConfig.dev,
authSession: AuthSession(),
configStore: null,
);
resizes = [];
session = TerminalSession(
machineId: 'm',
agentId: 'a',
agentName: 'Agent',
engineId: 'claude',
send: (type, payload) async {
if (type == 'terminal_resize') resizes.add(payload);
return true;
},
sendBinary: (_) async => true,
);
session.status = TerminalSessionStatus.controlling;
session.streamId = 's';
for (var line = 0; line < 400; line++) {
session.terminal.write('output line $line\r\n');
}
notifier.adoptSessionForTest(session);
language = ValueNotifier('en');
voice = VoiceInputController(
transcriber: FakeTranscriber().call,
recorder: FakeVoiceRecorder(),
language: language,
);
});
tearDown(() {
voice.dispose();
language.dispose();
// Disposes the session too: it was adopted as a pane.
notifier.dispose();
});
Future<void> pumpPage(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: TerminalPage(
notifier: notifier,
machineId: 'm',
agentId: 'a',
voice: voice,
),
),
);
await tester.pump(const Duration(milliseconds: 100));
}
/// A chunk of output, the way the session writes it.
void output(String text) {
session.outputTicks.value++;
session.terminal.write(text);
}
Finder position() => find.textContaining(RegExp(r'^\[\d+/\d+\]$'));
testWidgets('at the end there is no position', (tester) async {
await pumpPage(tester);
output('more output\r\n');
await tester.pump();
expect(position(), findsNothing);
});
testWidgets('scrolled up, the position shows and counts; a tap goes back', (
tester,
) async {
await pumpPage(tester);
await tester.drag(find.byType(TerminalView), const Offset(0, 300));
await tester.pump(const Duration(milliseconds: 100));
expect(position(), findsOneWidget);
final before = (tester.widget(position()) as Text).data!;
output('newer output\r\n');
await tester.pump();
await tester.pump();
final after = (tester.widget(position()) as Text).data!;
expect(after, isNot(before), reason: 'new lines below count up');
await tester.tap(position());
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(position(), findsNothing);
// Following again: more output keeps it gone.
output('newest output\r\n');
await tester.pump();
await tester.pump();
expect(position(), findsNothing);
});
}
710fbeaaeThis file is pinned to the selected release. Download the original to open it in your design tool.