From fe91c8fe8b2837322d4e12e3aeebc5348db1124e Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Tue, 17 Aug 2021 21:40:41 +0800 Subject: [PATCH] More test cases --- test/use_case/ls_test.dart | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 test/use_case/ls_test.dart diff --git a/test/use_case/ls_test.dart b/test/use_case/ls_test.dart new file mode 100644 index 00000000..014e0181 --- /dev/null +++ b/test/use_case/ls_test.dart @@ -0,0 +1,90 @@ +import 'package:nc_photos/account.dart'; +import 'package:nc_photos/entity/file.dart'; +import 'package:nc_photos/use_case/ls.dart'; +import 'package:path/path.dart' as path; +import 'package:test/test.dart'; + +import '../mock_type.dart'; + +void main() { + final _buildAccount = + () => Account("http", "example.com", "admin", "pass", [""]); + + group("Ls", () { + test("normal", () async { + expect( + await Ls(_MockFileRepo())( + _buildAccount(), + File( + path: "remote.php/dav/files/admin", + )), + [ + File( + path: "remote.php/dav/files/admin/test1.jpg", + ), + File( + path: "remote.php/dav/files/admin/test2.jpg", + ), + File( + path: "remote.php/dav/files/admin/d1", + isCollection: true, + ), + ]); + }); + + test("shouldExcludeRootDir == false", () async { + expect( + await Ls(_MockFileRepo())( + _buildAccount(), + File( + path: "remote.php/dav/files/admin", + ), + shouldExcludeRootDir: false), + [ + File( + path: "remote.php/dav/files/admin", + isCollection: true, + ), + File( + path: "remote.php/dav/files/admin/test1.jpg", + ), + File( + path: "remote.php/dav/files/admin/test2.jpg", + ), + File( + path: "remote.php/dav/files/admin/d1", + isCollection: true, + ), + ]); + }); + }); +} + +class _MockFileRepo extends MockFileRepo { + @override + list(Account account, File root) async { + return [ + File( + path: "remote.php/dav/files/admin", + isCollection: true, + ), + File( + path: "remote.php/dav/files/admin/test1.jpg", + ), + File( + path: "remote.php/dav/files/admin/test2.jpg", + ), + File( + path: "remote.php/dav/files/admin/d1", + isCollection: true, + ), + File( + path: "remote.php/dav/files/admin/d1/test3.jpg", + ), + ] + .where((element) => + element.path == root.path || + path.dirname(element.path) == root.path) + .toList(); + } +}