feat: improve desktop path selection and USB connection recovery
This commit is contained in:
1 parent
5aa575f182
commit
6490665af8
28 files changed
+846
-51
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:ads_manager/ui/manager_model.dart';
|
||||
import 'package:ads_manager/ui/manager_view.dart';
|
||||
|
||||
void main() {
|
||||
for (final cancelled in [false, true]) {
|
||||
testWidgets('file picker saves immediately; cancelled=$cancelled', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1280, 1800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final folder = Directory.systemTemp.createTempSync('ads-path-test');
|
||||
final model = ManagerModel();
|
||||
model.repository.storage = folder;
|
||||
try {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SettingsView(
|
||||
model: model,
|
||||
chooseFile: (current, executable) async {
|
||||
expect(executable, true);
|
||||
return cancelled ? null : 'C:/SDK/adb.exe';
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final buttons = find.byTooltip('选择文件并保存');
|
||||
expect(buttons, findsNWidgets(5));
|
||||
await tester.ensureVisible(buttons.at(2));
|
||||
await tester.runAsync(() async {
|
||||
await tester.tap(buttons.at(2));
|
||||
for (
|
||||
var i = 0;
|
||||
i < 100 && !cancelled && model.notice != '文件位置已保存';
|
||||
i++
|
||||
) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
}
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
final file = File('${folder.path}/settings.json');
|
||||
if (cancelled) {
|
||||
expect(file.existsSync(), false);
|
||||
} else {
|
||||
expect(model.repository.settings.adb, 'C:/SDK/adb.exe');
|
||||
final saved =
|
||||
jsonDecode(file.readAsStringSync()) as Map<String, dynamic>;
|
||||
expect(saved['adb'], 'C:/SDK/adb.exe');
|
||||
expect(saved.containsKey('token'), false);
|
||||
}
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
model.dispose();
|
||||
} finally {
|
||||
folder.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user