This commit is contained in:
LZX committed 2026-09-12 20:36:21 +08:00
1 parent 54c3083c24
commit 87e03ce0d8
44 files changed
+3965 -307

No files matched your search

+182
View File
@@ -0,0 +1,182 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:archive/archive.dart';
import 'package:code_editor/models/distro_info.dart';
import 'package:code_editor/providers/distro_provider.dart';
import 'package:code_editor/services/distro_installer.dart';
import 'package:code_editor/services/distro_manager.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart' as p;
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late Directory tempDir;
late DistroManager manager;
setUp(() {
tempDir = Directory.systemTemp.createTempSync('distro_test_');
manager = DistroManager();
manager.customBaseDir = tempDir;
});
tearDown(() {
if (tempDir.existsSync()) {
tempDir.deleteSync(recursive: true);
}
});
group('DistroManager & DistroInfo Tests', () {
test('内置预设包含 Alpine, Debian, Ubuntu, Host', () {
final distros = manager.listDistros();
expect(distros.any((d) => d.id == 'alpine'), isTrue);
expect(distros.any((d) => d.id == 'debian'), isTrue);
expect(distros.any((d) => d.id == 'ubuntu'), isTrue);
expect(distros.any((d) => d.id == 'host'), isTrue);
final alpine = manager.getDistro('alpine');
expect(alpine, isNotNull);
expect(alpine!.packageManager, 'apk');
expect(alpine.defaultShell, '/bin/sh');
expect(alpine.assetPath, contains('alpine-minirootfs'));
});
test('支持动态扩展注册与注销自定义发行版', () {
const customDistro = DistroInfo(
id: 'archlinux',
name: 'Arch Linux',
version: 'Rolling',
description: '滚动更新的极客发行版',
packageManager: 'pacman',
defaultShell: '/bin/bash',
isBuiltin: false,
);
manager.registerDistro(customDistro);
expect(manager.getDistro('archlinux'), isNotNull);
expect(manager.getDistro('archlinux')!.name, 'Arch Linux');
manager.unregisterDistro('archlinux');
expect(manager.getDistro('archlinux'), isNull);
});
test('Host 本地环境默认视为已就绪', () async {
final isInstalled = await manager.isInstalled('host');
expect(isInstalled, isTrue);
});
test('未初始化的 Linux 容器返回 false', () async {
final isInstalled = await manager.isInstalled('alpine');
expect(isInstalled, isFalse);
});
});
group('DistroInstaller 解压与网络配置测试', () {
test('创建测试 tar.gz 并使用 DistroInstaller 解压与配置', () async {
// 构造小型测试 tar.gz 镜像
final archive = Archive();
archive.addFile(ArchiveFile('bin/sh', 11, 'echo "sh"'.codeUnits));
archive.addFile(ArchiveFile('etc/os-release', 18, 'NAME="Alpine Linux"'.codeUnits));
final tarData = TarEncoder().encode(archive);
final gzData = GZipEncoder().encode(tarData);
final targetDir = Directory(p.join(tempDir.path, 'alpine', 'rootfs'));
double lastProgress = 0.0;
String lastMessage = '';
await DistroInstaller.installFromBytes(
tarGzBytes: Uint8List.fromList(gzData!),
targetDir: targetDir,
onProgress: (prog, msg) {
lastProgress = prog;
lastMessage = msg;
},
);
expect(lastProgress, 1.0);
expect(lastMessage, '系统初始化就绪!');
// 验证文件解压成功
expect(File(p.join(targetDir.path, 'bin', 'sh')).existsSync(), isTrue);
expect(File(p.join(targetDir.path, 'etc', 'os-release')).existsSync(), isTrue);
// 验证自动配置的 resolv.conf (DNS) 与 hosts
final resolvFile = File(p.join(targetDir.path, 'etc', 'resolv.conf'));
expect(resolvFile.existsSync(), isTrue);
final resolvContent = resolvFile.readAsStringSync();
expect(resolvContent, contains('nameserver 1.1.1.1'));
expect(resolvContent, contains('nameserver 8.8.8.8'));
final hostsFile = File(p.join(targetDir.path, 'etc', 'hosts'));
expect(hostsFile.existsSync(), isTrue);
expect(hostsFile.readAsStringSync(), contains('127.0.0.1 localhost'));
// 验证 /workspace 挂载点目录被创建
expect(Directory(p.join(targetDir.path, 'workspace')).existsSync(), isTrue);
// 此时检测安装状态应为 true
final isInstalled = await manager.isInstalled('alpine');
expect(isInstalled, isTrue);
});
});
group('ProotCommandBuilder 启动配置构建测试', () {
test('构建 Host 本地启动配置', () async {
final config = await manager.buildLaunchConfig(
distroId: 'host',
workspacePath: tempDir.path,
customCommand: 'ls -la',
);
expect(config.executable, '/system/bin/sh');
expect(config.arguments, ['-c', 'ls -la']);
expect(config.workingDirectory, tempDir.path);
expect(config.environment['TERM'], 'xterm-256color');
});
test('构建 Alpine PRoot 容器隔离启动配置与挂载参数', () async {
final config = await manager.buildLaunchConfig(
distroId: 'alpine',
workspacePath: tempDir.path,
prootPath: '/data/data/com.example/files/proot',
);
expect(config.executable, '/data/data/com.example/files/proot');
expect(config.arguments, contains('-0'));
expect(config.arguments, contains('-r'));
expect(config.arguments, contains('-b'));
expect(config.arguments, contains('/dev'));
expect(config.arguments, contains('/proc'));
expect(config.arguments, contains('/sys'));
expect(config.arguments, contains('${tempDir.path}:/workspace'));
expect(config.arguments, contains('-w'));
expect(config.arguments, contains('/workspace'));
expect(config.arguments, contains('/bin/sh'));
expect(config.arguments, contains('-l'));
expect(config.environment['HOME'], '/root');
expect(config.environment['USER'], 'root');
expect(config.environment['TERM'], 'xterm-256color');
expect(config.environment['PATH'], isNotEmpty);
final cmdLine = config.toCommandLine();
expect(cmdLine, contains('/data/data/com.example/files/proot'));
expect(cmdLine, contains('-0'));
});
});
group('DistroProvider 状态测试', () {
test('初始状态与切换默认发行版', () async {
final provider = DistroProvider();
expect(provider.defaultDistroId, 'alpine');
provider.setDefaultDistro('host');
expect(provider.defaultDistroId, 'host');
await provider.checkAllStatuses();
expect(provider.getStatus('host'), DistroStatus.installed);
});
});
}
+287
View File
@@ -0,0 +1,287 @@
import 'package:code_editor/l10n/app_localizations.dart';
import 'package:code_editor/models/terminal_session.dart';
import 'package:code_editor/providers/distro_provider.dart';
import 'package:code_editor/providers/settings_provider.dart';
import 'package:code_editor/providers/terminal_provider.dart';
import 'package:code_editor/views/terminal_view.dart';
import 'package:code_editor/widgets/terminal_session_item_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
Widget createTestTerminalApp({required TerminalProvider terminalProvider}) {
return MultiProvider(
providers: [
ChangeNotifierProvider<TerminalProvider>.value(value: terminalProvider),
ChangeNotifierProvider<DistroProvider>(create: (_) => DistroProvider()),
],
child: MaterialApp(
locale: const Locale('zh'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const TerminalView(),
),
);
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
SharedPreferences.setMockInitialValues({});
});
group('Terminal Subsystem Tests', () {
testWidgets('Lazy loading creates first session upon first entry', (tester) async {
final provider = TerminalProvider();
expect(provider.sessions.isEmpty, isTrue);
await tester.pumpWidget(createTestTerminalApp(terminalProvider: provider));
await tester.pumpAndSettle();
expect(provider.sessions.length, equals(1));
expect(provider.activeIndex, equals(0));
expect(provider.activeSession?.name, equals('会话'));
// Check AppBar title and subtitle
expect(find.text('会话'), findsWidgets);
expect(find.text('终端'), findsOneWidget);
});
testWidgets('Right drawer can be opened and shows title "会话" with add button', (tester) async {
final provider = TerminalProvider();
await tester.pumpWidget(createTestTerminalApp(terminalProvider: provider));
await tester.pumpAndSettle();
// Click list button in AppBar to open endDrawer
final listBtn = find.byIcon(Icons.format_list_bulleted);
expect(listBtn, findsOneWidget);
await tester.tap(listBtn);
await tester.pumpAndSettle();
// Drawer is open
expect(find.byType(Drawer), findsOneWidget);
expect(find.byIcon(Icons.add), findsOneWidget);
// Verify item text format: (1) 会话
expect(find.text('(1) 会话'), findsOneWidget);
// Tap Add button in drawer: creates session but does NOT switch
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
expect(provider.sessions.length, equals(2));
expect(provider.activeIndex, equals(0)); // Did not switch!
expect(find.text('(2) 会话'), findsOneWidget);
});
testWidgets('Tapping session item switches active session and closes drawer', (tester) async {
final provider = TerminalProvider();
await tester.pumpWidget(createTestTerminalApp(terminalProvider: provider));
await tester.pumpAndSettle();
// Open drawer
await tester.tap(find.byIcon(Icons.format_list_bulleted));
await tester.pumpAndSettle();
// Add session 2
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
expect(provider.activeIndex, equals(0));
// Tap session 2 item
await tester.tap(find.text('(2) 会话'));
await tester.pumpAndSettle();
// Drawer should be closed and activeIndex is now 1
expect(find.byType(Drawer), findsNothing);
expect(provider.activeIndex, equals(1));
});
testWidgets('Long press on session item opens context menu with rename and delete', (tester) async {
final provider = TerminalProvider();
await tester.pumpWidget(createTestTerminalApp(terminalProvider: provider));
await tester.pumpAndSettle();
// Open drawer
await tester.tap(find.byIcon(Icons.format_list_bulleted));
await tester.pumpAndSettle();
// Long press on session item
final sessionItem = find.byType(TerminalSessionItemWidget);
expect(sessionItem, findsOneWidget);
await tester.longPress(sessionItem);
await tester.pumpAndSettle();
// Context menu options
expect(find.text('重命名'), findsOneWidget);
expect(find.text('删除'), findsOneWidget);
// Tap 重命名
await tester.tap(find.text('重命名'));
await tester.pumpAndSettle();
// Dialog opens
expect(find.byType(AlertDialog), findsOneWidget);
final dialogTextField = find.descendant(
of: find.byType(AlertDialog),
matching: find.byType(TextField),
);
await tester.enterText(dialogTextField, '调试终端');
await tester.tap(find.text('确定'));
await tester.pumpAndSettle();
expect(provider.activeSession?.name, equals('调试终端'));
});
testWidgets('Session persistence: returning to editor and re-entering preserves sessions and buffers', (tester) async {
final provider = TerminalProvider();
// Simulate root app with Navigator
await tester.pumpWidget(
MultiProvider(
providers: [
ChangeNotifierProvider<TerminalProvider>.value(value: provider),
],
child: MaterialApp(
locale: const Locale('zh'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Builder(
builder: (context) => Scaffold(
body: ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const TerminalView(),
),
);
},
child: const Text('进入终端'),
),
),
),
),
),
);
await tester.pumpAndSettle();
// Enter terminal
await tester.tap(find.text('进入终端'));
await tester.pumpAndSettle();
expect(find.byType(TerminalView), findsOneWidget);
expect(provider.sessions.length, equals(1));
// Append custom text to session buffer via provider
provider.appendOutput(provider.activeSession!, 'CUSTOM_SESSION_OUTPUT_LINE');
await tester.pumpAndSettle();
expect(find.text('CUSTOM_SESSION_OUTPUT_LINE'), findsOneWidget);
// Pop back to editor
await tester.tap(find.byIcon(Icons.arrow_back));
await tester.pumpAndSettle();
expect(find.byType(TerminalView), findsNothing);
expect(find.text('进入终端'), findsOneWidget);
// Provider still holds the session and buffer
expect(provider.sessions.length, equals(1));
expect(provider.sessions.first.outputLines.contains('CUSTOM_SESSION_OUTPUT_LINE'), isTrue);
// Re-enter terminal
await tester.tap(find.text('进入终端'));
await tester.pumpAndSettle();
// Verify the session output is still right there
expect(find.byType(TerminalView), findsOneWidget);
expect(find.text('CUSTOM_SESSION_OUTPUT_LINE'), findsOneWidget);
});
testWidgets('Deleting a session from context menu removes it and updates activeIndex', (tester) async {
final provider = TerminalProvider();
await tester.pumpWidget(createTestTerminalApp(terminalProvider: provider));
await tester.pumpAndSettle();
// Open drawer
await tester.tap(find.byIcon(Icons.format_list_bulleted));
await tester.pumpAndSettle();
// Add second session
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
expect(provider.sessions.length, equals(2));
// Long press second session
final items = find.byType(TerminalSessionItemWidget);
expect(items, findsNWidgets(2));
await tester.longPress(items.at(1));
await tester.pumpAndSettle();
// Tap 删除
await tester.tap(find.text('删除'));
await tester.pumpAndSettle();
// Confirm dialog opens
expect(find.byType(AlertDialog), findsOneWidget);
await tester.tap(find.text('删除').last);
await tester.pumpAndSettle();
// Session 2 is deleted
expect(provider.sessions.length, equals(1));
expect(find.text('(2) 会话'), findsNothing);
});
testWidgets('Dragging to reorder sessions updates session list order and labels', (tester) async {
final provider = TerminalProvider();
await tester.pumpWidget(createTestTerminalApp(terminalProvider: provider));
await tester.pumpAndSettle();
// Open drawer
await tester.tap(find.byIcon(Icons.format_list_bulleted));
await tester.pumpAndSettle();
// Add second session
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
provider.renameSession(provider.sessions[0].id, '第一项');
provider.renameSession(provider.sessions[1].id, '第二项');
await tester.pumpAndSettle();
expect(find.text('(1) 第一项'), findsOneWidget);
expect(find.text('(2) 第二项'), findsOneWidget);
// Drag first item's drag handle downwards past the second item
final firstDragHandle = find.byIcon(Icons.drag_handle).first;
await tester.drag(firstDragHandle, const Offset(0, 120));
await tester.pumpAndSettle();
expect(provider.sessions[0].name, equals('第二项'));
expect(provider.sessions[1].name, equals('第一项'));
expect(find.text('(1) 第二项'), findsOneWidget);
expect(find.text('(2) 第一项'), findsOneWidget);
});
test('SettingsProvider manages UI, Editor, and Terminal font choices correctly', () async {
final settings = SettingsProvider();
expect(settings.uiFont.id, equals('system_default'));
expect(settings.editorFont.id, equals('monospace'));
expect(settings.terminalFont.id, equals('monospace'));
await settings.setUiFontId('sans_serif');
expect(settings.uiFont.id, equals('sans_serif'));
expect(settings.uiFont.fontFamily, equals('sans-serif'));
await settings.setEditorFontId('jetbrains_mono');
expect(settings.editorFont.id, equals('jetbrains_mono'));
expect(settings.editorFont.fontFamily, equals('JetBrains Mono'));
await settings.setTerminalFontId('consolas');
expect(settings.terminalFont.id, equals('consolas'));
expect(settings.terminalFont.fontFamily, equals('Consolas'));
});
});
}
+108 -24
View File
@@ -1,3 +1,4 @@
import 'dart:io';
import 'package:re_editor/re_editor.dart';
import 'package:code_editor/models/editor_tab_item.dart';
import 'package:code_editor/models/file_item.dart';
@@ -23,6 +24,7 @@ import 'package:code_editor/views/settings_view.dart';
import 'package:code_editor/views/main_view.dart';
import 'package:code_editor/widgets/code_editor_app_bar.dart';
import 'package:code_editor/widgets/code_editor_drawer.dart';
import 'package:code_editor/utils/dialog_utils.dart';
import 'package:code_editor/services/file_watcher_service.dart';
import 'package:code_editor/utils/syntax_highlight_helper.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -252,14 +254,12 @@ void main() {
final appBar = tester.widget<AppBar>(appBarFinder);
expect(appBar.foregroundColor, isNotNull);
// Verify PopupMenuButton has position under
final popupBtnFinder = find.byType(PopupMenuButton<String>);
expect(popupBtnFinder, findsOneWidget);
final popupBtn = tester.widget<PopupMenuButton<String>>(popupBtnFinder);
expect(popupBtn.position, equals(PopupMenuPosition.under));
// Verify more menu button exists
final moreBtnFinder = find.byIcon(Icons.more_vert);
expect(moreBtnFinder, findsOneWidget);
// Tap menu button
await tester.tap(popupBtnFinder);
await tester.tap(moreBtnFinder);
await tester.pumpAndSettle();
expect(find.text('设置'), findsOneWidget);
@@ -284,6 +284,9 @@ void main() {
);
await tester.pumpAndSettle();
// Scroll until word wrap switch is visible
await tester.scrollUntilVisible(find.text('自动换行'), 200);
// Verify word wrap switch tile exists
expect(find.text('自动换行'), findsOneWidget);
final wordWrapTile = find.ancestor(
@@ -303,6 +306,23 @@ void main() {
await tester.pumpAndSettle();
expect(provider.wordWrap, isFalse);
// Verify indent size tile
expect(find.text('缩进大小'), findsOneWidget);
expect(find.text('2 个空格'), findsOneWidget);
// Tap indent size tile to open modal
await tester.tap(find.text('缩进大小'));
await tester.pumpAndSettle();
expect(find.text('选择缩进空格数'), findsOneWidget);
expect(find.text('4 个空格'), findsOneWidget);
// Select 4 spaces
await tester.tap(find.text('4 个空格'));
await tester.pumpAndSettle();
expect(provider.indentSize, equals(4));
// Verify language section
final langTile = find.text('应用语言');
await tester.scrollUntilVisible(langTile, 300);
@@ -548,7 +568,7 @@ void main() {
expect(find.text('/lib/views'), findsOneWidget);
// Open popup menu
await tester.tap(find.byType(PopupMenuButton<String>));
await tester.tap(find.byIcon(Icons.more_vert));
await tester.pumpAndSettle();
expect(find.text('保存所有'), findsOneWidget);
@@ -563,6 +583,48 @@ void main() {
expect(saveAllTriggered, isTrue);
});
testWidgets('DialogUtils.showToast adapts position above soft keyboard when viewInsets.bottom > 0', (WidgetTester tester) async {
addTearDown(tester.view.resetViewInsets);
late BuildContext targetContext;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Builder(
builder: (ctx) {
targetContext = ctx;
return const Text('Target');
},
),
),
),
);
// 1. 无软键盘时显示 Toast
DialogUtils.showSuccessToast(targetContext, '保存成功');
await tester.pump(const Duration(milliseconds: 50));
expect(find.text('保存成功'), findsOneWidget);
final initialCenter = tester.getCenter(find.text('保存成功'));
// 等待第一个 Toast 自动卸载
await tester.pump(const Duration(seconds: 3));
expect(find.text('保存成功'), findsNothing);
// 2. 模拟系统软键盘弹出时 (viewInsets.bottom: 260 逻辑像素)
tester.view.viewInsets = FakeViewPadding(bottom: 260 * tester.view.devicePixelRatio);
DialogUtils.showSuccessToast(targetContext, '有键盘');
await tester.pump(const Duration(milliseconds: 50));
final keyboardCenter = tester.getCenter(find.text('有键盘'));
// 键盘弹出后,Toast 中心点必须往上移(dy 变小)至少 200 像素以上,远离键盘遮挡区
expect(keyboardCenter.dy, lessThan(initialCenter.dy - 200));
// 等待 Toast 动画与定时器自动卸载
await tester.pump(const Duration(seconds: 3));
expect(find.text('有键盘'), findsNothing);
});
testWidgets('CodeEditorTabBar renders tabs and handles dirty close dialog', (WidgetTester tester) async {
final provider = TabProvider();
final tab1 = EditorTabItem(path: '/test/file1.dart', isModified: false);
@@ -616,12 +678,16 @@ void main() {
test('SettingsProvider manages settings correctly', () async {
final settings = SettingsProvider();
expect(settings.fontSize, equals(14.0));
expect(settings.indentSize, equals(2));
expect(settings.wordWrap, isTrue);
expect(settings.appThemeMode, equals(ThemeMode.system));
await settings.setFontSize(18.0);
expect(settings.fontSize, equals(18.0));
await settings.setIndentSize(4);
expect(settings.indentSize, equals(4));
await settings.setWordWrap(false);
expect(settings.wordWrap, isFalse);
@@ -969,12 +1035,18 @@ void main() {
});
testWidgets('Opening another file from file list when active file is modified does not prompt save dialog', (WidgetTester tester) async {
final tempDir = Directory.systemTemp.createTempSync('widget_test_tab_');
addTearDown(() {
if (tempDir.existsSync()) tempDir.deleteSync(recursive: true);
});
final tabProvider = TabProvider();
final projectProvider = ProjectProvider();
final settingsProvider = SettingsProvider();
final file1 = FileItem(path: p.normalize('/ws/file1.dart'), name: 'file1.dart', isDirectory: false);
final file2 = FileItem(path: p.normalize('/ws/file2.dart'), name: 'file2.dart', isDirectory: false);
final file1 = FileItem(path: p.join(tempDir.path, 'file1.dart'), name: 'file1.dart', isDirectory: false);
final file2 = FileItem(path: p.join(tempDir.path, 'file2.dart'), name: 'file2.dart', isDirectory: false);
File(file2.path).writeAsStringSync('int b = 2;');
// Initial state: open file1 and modify it
await tabProvider.openFile(file1.path, content: 'int a = 1;');
@@ -996,7 +1068,8 @@ void main() {
),
),
);
await tester.pumpAndSettle();
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
// Verify main view is rendered with modified file1
expect(find.text('file1.dart'), findsWidgets);
@@ -1004,27 +1077,32 @@ void main() {
// Open file2 via selectFile (simulating user clicking file2 in file tree/drawer)
await tabProvider.selectFile(file2);
await tester.pumpAndSettle();
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
// NO save prompt dialog should appear
expect(find.text('保存更改'), findsNothing);
expect(find.text('保存所有更改?'), findsNothing);
// Now file2 is active, file1 is still open and preserved in memory
expect(tabProvider.activeTab?.path, equals(p.normalize('/ws/file2.dart')));
expect(tabProvider.activeTab?.path, equals(p.normalize(file2.path)));
expect(tabProvider.openTabs.length, equals(2));
expect(tabProvider.openTabs[0].isModified, isTrue);
expect(tabProvider.openTabs[0].content, equals('int a = 2;'));
// Switch back to file1 via openFile (simulating clicking tab1)
await tabProvider.openFile(file1.path);
await tester.pumpAndSettle();
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
// NO save prompt dialog should appear on tab switch either
expect(find.text('保存更改'), findsNothing);
expect(find.text('保存所有更改?'), findsNothing);
expect(tabProvider.activeTab?.path, equals(p.normalize('/ws/file1.dart')));
expect(tabProvider.activeTab?.path, equals(p.normalize(file1.path)));
expect(tabProvider.activeTab?.isModified, isTrue);
// Unmount MainView so cursor blinking timer cancels cleanly
await tester.pumpWidget(const SizedBox());
});
testWidgets('Close all tabs from PopupMenu prompts for dirty tabs and closes tabs', (WidgetTester tester) async {
@@ -1050,28 +1128,34 @@ void main() {
),
),
);
await tester.pumpAndSettle();
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(tabProvider.openTabs.length, equals(1));
// Tap more menu
await tester.tap(find.byType(PopupMenuButton<String>));
await tester.pumpAndSettle();
await tester.tap(find.byIcon(Icons.more_vert));
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
// Tap '关闭所有标签'
await tester.tap(find.text('关闭所有标签'));
await tester.pumpAndSettle();
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
// Dirty prompt dialog should appear
expect(find.text('保存所有更改?'), findsOneWidget);
// Choose discard (不保存)
await tester.tap(find.text('不保存'));
await tester.pumpAndSettle();
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
// All tabs should be closed
expect(tabProvider.openTabs, isEmpty);
expect(tabProvider.activeTab, isNull);
await tester.pumpWidget(const SizedBox());
});
testWidgets('Deleting current project in ProjectHistoryWidget closes project first before confirming delete', (WidgetTester tester) async {
@@ -1386,7 +1470,7 @@ void main() {
// Scroll to virtual keyboard tiles
final configTile = find.text('编辑键盘配置');
await tester.drag(find.byType(ListView), const Offset(0, -200));
await tester.scrollUntilVisible(configTile, 200);
await tester.pumpAndSettle();
expect(configTile, findsOneWidget);
@@ -1407,11 +1491,11 @@ void main() {
// Edit controller with invalid json on line 3
editorController.text = '{\n "pages": [\n error_here\n ]\n}';
await tester.pumpAndSettle();
await tester.pump(const Duration(milliseconds: 100));
// Tap '保存'
await tester.tap(find.text('保存'));
await tester.pumpAndSettle();
await tester.pump(const Duration(milliseconds: 100));
// Dialog should still be open and display error message with line number
expect(find.text('小键盘配置 (JSON)'), findsOneWidget);
@@ -1420,7 +1504,7 @@ void main() {
// Tap '恢复默认'
await tester.tap(find.text('恢复默认'));
await tester.pumpAndSettle();
await tester.pump(const Duration(milliseconds: 100));
// Error message should clear
expect(find.byIcon(Icons.error_outline), findsNothing);
@@ -1428,7 +1512,7 @@ void main() {
// Tap '保存' with valid config -> dialog closes
await tester.tap(find.text('保存'));
await tester.pumpAndSettle();
await tester.pump(const Duration(milliseconds: 500));
expect(find.text('小键盘配置 (JSON)'), findsNothing);