import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/util/file_picker/file_picker_service.dart'; import 'package:file_picker/file_picker.dart' as fp; class MockFilePicker implements FilePickerService { MockFilePicker({ this.mockPath = '', this.mockPaths = const [], }); final String mockPath; final List mockPaths; @override Future getDirectoryPath({String? title}) { return Future.value(mockPath); } @override Future saveFile({ String? dialogTitle, String? fileName, String? initialDirectory, fp.FileType type = fp.FileType.any, List? allowedExtensions, bool lockParentWindow = false, }) { return Future.value(mockPath); } @override Future pickFiles({ String? dialogTitle, String? initialDirectory, fp.FileType type = fp.FileType.any, List? allowedExtensions, Function(fp.FilePickerStatus p1)? onFileLoading, bool allowCompression = true, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, }) { final platformFiles = mockPaths .map((e) => fp.PlatformFile(path: e, name: '', size: 0)) .toList(); return Future.value( FilePickerResult( platformFiles, ), ); } } Future mockGetDirectoryPath( String path, ) async { getIt.unregister(); getIt.registerFactory( () => MockFilePicker( mockPath: path, ), ); return; } Future mockSaveFilePath( String path, ) async { getIt.unregister(); getIt.registerFactory( () => MockFilePicker( mockPath: path, ), ); return path; } Future> mockPickFilePaths({ required List paths, }) async { // late final Directory dir; // if (customPath != null) { // dir = Directory(customPath); // } else { // dir = await TestFolder.testLocation(applicationDataPath, name); // } // final paths = fileNames.map((e) => p.join(dir.path, e)).toList(); getIt.unregister(); getIt.registerFactory( () => MockFilePicker( mockPaths: paths, ), ); return paths; }