89 lines
3.2 KiB
Dart
89 lines
3.2 KiB
Dart
// 专项验证:cd 跨目录 + resize 后内容不重复。
|
||
import 'package:flutter/foundation.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
import 'package:flutter_alacritty/flutter_alacritty.dart';
|
||
import 'package:integration_test/integration_test.dart';
|
||
|
||
import 'package:rtty_desktop/main.dart' as app;
|
||
|
||
void main() {
|
||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||
|
||
testWidgets('cd 跨目录 + resize 内容完整性', (WidgetTester tester) async {
|
||
await app.main();
|
||
await tester.pumpAndSettle();
|
||
await tester.tap(find.text('CONNECT'));
|
||
await tester.pump();
|
||
|
||
// 等待连接。
|
||
final deadline = DateTime.now().add(const Duration(seconds: 8));
|
||
while (DateTime.now().isBefore(deadline)) {
|
||
await tester.pump(const Duration(milliseconds: 200));
|
||
if (find.text('AWAITING CONNECTION').evaluate().isEmpty) break;
|
||
}
|
||
expect(find.text('AWAITING CONNECTION'), findsNothing);
|
||
|
||
final engine = tester
|
||
.state<TerminalViewState>(find.byType(TerminalView))
|
||
.widget
|
||
.engine;
|
||
engine.initializeEmpty(24, 80);
|
||
|
||
void send(String s) =>
|
||
engine.write(Uint8List.fromList(s.codeUnits));
|
||
|
||
String gridText() {
|
||
final g = engine.gridForView;
|
||
final sb = StringBuffer();
|
||
for (var r = 0; r < g.rows; r++) {
|
||
for (var c = 0; c < g.columns; c++) {
|
||
final cp = g.codepointAt(r, c);
|
||
sb.writeCharCode(cp == 0 ? 32 : cp);
|
||
}
|
||
sb.write('\n');
|
||
}
|
||
return sb.toString();
|
||
}
|
||
|
||
Future<bool> waitFor(bool Function(String) pred,
|
||
{int secs = 6}) async {
|
||
final end = DateTime.now().add(Duration(seconds: secs));
|
||
while (DateTime.now().isBefore(end)) {
|
||
await tester.pump(const Duration(milliseconds: 200));
|
||
if (pred(gridText())) return true;
|
||
}
|
||
return pred(gridText());
|
||
}
|
||
|
||
// ---- 1. cd 跨目录 ----
|
||
final target = r'C:\Users\NianJiu\rttytest\subdir';
|
||
send('cd $target\r\n');
|
||
final cdOk = await waitFor((t) => t.contains('rttytest\\subdir'));
|
||
debugPrint('cd 后 prompt 含目标目录: $cdOk');
|
||
if (!cdOk) debugPrint('--- grid ---\n${gridText()}');
|
||
expect(cdOk, isTrue, reason: 'cd 到绝对路径后 prompt 应显示新目录');
|
||
|
||
// ---- 2. resize 后内容不重复 ----
|
||
// 记录 resize 前的非空行。
|
||
send('dir\r\n');
|
||
final beforeOk = await waitFor((t) => t.contains('subdir') && t.contains('dir'));
|
||
debugPrint('dir 输出: $beforeOk');
|
||
|
||
// 连续 resize 数次(模拟窗口拖动),验证内容不产生重复/错乱。
|
||
for (final (c, r) in [(100, 30), (120, 35), (90, 28), (110, 32)]) {
|
||
engine.resize(columns: c, rows: r);
|
||
await tester.pump(const Duration(milliseconds: 150));
|
||
}
|
||
engine.resize(columns: 100, rows: 30);
|
||
await tester.pump(const Duration(milliseconds: 300));
|
||
|
||
// 重置引擎网格尺寸后,发送简单命令,验证仍能正常回显(无重复错乱)。
|
||
send('echo RESIZE_OK\r\n');
|
||
final ok = await waitFor((t) => t.contains('RESIZE_OK'));
|
||
debugPrint('resize 后命令回显: $ok');
|
||
expect(ok, isTrue, reason: 'resize 后命令应正常回显且无重复');
|
||
|
||
debugPrint('--- 最终 grid ---\n${gridText()}');
|
||
});
|
||
}
|