nc-photos/app/test/use_case/ls_test.dart

56 lines
1.4 KiB
Dart
Raw Normal View History

2021-08-17 15:40:41 +02:00
import 'package:nc_photos/entity/file.dart';
2022-01-01 18:29:51 +01:00
import 'package:nc_photos/entity/file_util.dart' as file_util;
2021-08-17 15:40:41 +02:00
import 'package:nc_photos/use_case/ls.dart';
import 'package:np_collection/np_collection.dart';
2021-08-17 15:40:41 +02:00
import 'package:test/test.dart';
import '../mock_type.dart';
2021-11-23 08:45:10 +01:00
import '../test_util.dart' as util;
2021-08-17 15:40:41 +02:00
void main() {
group("Ls", () {
2022-01-01 18:29:51 +01:00
test("root", _root);
test("sub dir", _subDir);
2021-08-17 15:40:41 +02:00
});
}
2022-01-01 18:29:51 +01:00
/// List the root dir
///
/// Expect: all files under root dir
Future<void> _root() async {
final account = util.buildAccount();
final files = (util.FilesBuilder()
..addDir("admin")
..addJpeg("admin/test1.jpg")
..addDir("admin/dir")
..addJpeg("admin/dir/test2.jpg"))
.build();
final fileRepo = MockFileMemoryRepo(files);
expect(
await Ls(fileRepo)(
account, File(path: file_util.unstripPath(account, "."))),
files.slice(1, 3),
2022-01-01 18:29:51 +01:00
);
}
/// List a sub dir
///
/// Expect: all files under the sub dir
Future<void> _subDir() async {
final account = util.buildAccount();
final files = (util.FilesBuilder()
..addDir("admin")
..addJpeg("admin/test1.jpg")
..addDir("admin/dir")
..addJpeg("admin/dir/test2.jpg"))
.build();
final fileRepo = MockFileMemoryRepo(files);
expect(
await Ls(fileRepo)(
account, File(path: file_util.unstripPath(account, "dir"))),
[files[3]],
);
2021-08-17 15:40:41 +02:00
}