nc-photos/app/test/bloc/ls_dir_test.dart

162 lines
4.7 KiB
Dart
Raw Permalink Normal View History

2021-08-16 21:05:00 +02:00
import 'package:bloc_test/bloc_test.dart';
import 'package:nc_photos/bloc/ls_dir.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:test/test.dart';
2021-08-17 15:38:21 +02:00
import '../mock_type.dart';
2021-11-23 08:45:10 +01:00
import '../test_util.dart' as util;
2021-08-17 15:38:21 +02:00
2021-08-16 21:05:00 +02:00
void main() {
2021-11-11 15:18:33 +01:00
_buildBloc() => LsDirBloc(_MockFileRepo());
2021-08-16 21:05:00 +02:00
2021-11-11 15:18:33 +01:00
group("LsDirBloc", () {
2021-08-16 21:05:00 +02:00
group("LsDirBlocQuery", () {
test("initial state", () {
final bloc = _buildBloc();
expect(bloc.state.account, null);
expect(bloc.state.root, File(path: ""));
expect(bloc.state.items, []);
});
blocTest(
"inital",
build: _buildBloc,
expect: () => [],
);
blocTest<LsDirBloc, LsDirBlocState>(
"query 1 subdir",
build: _buildBloc,
2021-11-23 08:45:10 +01:00
act: (bloc) => bloc.add(LsDirBlocQuery(
util.buildAccount(), File(path: "remote.php/dav/files/admin"))),
2021-08-16 21:05:00 +02:00
expect: () => [
2021-11-23 08:45:10 +01:00
LsDirBlocLoading(util.buildAccount(),
2021-11-12 22:13:02 +01:00
File(path: "remote.php/dav/files/admin"), []),
2021-11-23 08:45:10 +01:00
LsDirBlocSuccess(
util.buildAccount(), File(path: "remote.php/dav/files/admin"), [
2021-08-16 21:05:00 +02:00
LsDirBlocItem(
File(
path: "remote.php/dav/files/admin/d1",
isCollection: true,
),
false,
2021-08-16 21:05:00 +02:00
null,
),
]),
],
);
blocTest<LsDirBloc, LsDirBlocState>(
"query n subdir",
build: _buildBloc,
2021-11-23 08:45:10 +01:00
act: (bloc) => bloc.add(LsDirBlocQuery(
util.buildAccount(), File(path: "remote.php/dav/files/admin/d1"))),
2021-08-16 21:05:00 +02:00
expect: () => [
2021-11-23 08:45:10 +01:00
LsDirBlocLoading(util.buildAccount(),
2021-11-12 22:13:02 +01:00
File(path: "remote.php/dav/files/admin/d1"), []),
2021-11-23 08:45:10 +01:00
LsDirBlocSuccess(util.buildAccount(),
2021-11-12 22:13:02 +01:00
File(path: "remote.php/dav/files/admin/d1"), [
2021-08-16 21:05:00 +02:00
LsDirBlocItem(
File(
path: "remote.php/dav/files/admin/d1/d2-1",
isCollection: true,
),
false,
2021-08-16 21:05:00 +02:00
null,
),
LsDirBlocItem(
File(
path: "remote.php/dav/files/admin/d1/d2-2",
isCollection: true,
),
false,
2021-08-16 21:05:00 +02:00
null,
),
]),
],
);
blocTest<LsDirBloc, LsDirBlocState>(
"query 0 subdir",
build: _buildBloc,
2021-11-23 08:45:10 +01:00
act: (bloc) => bloc.add(LsDirBlocQuery(util.buildAccount(),
2021-11-12 22:13:02 +01:00
File(path: "remote.php/dav/files/admin/d1/d2-2"))),
2021-08-16 21:05:00 +02:00
expect: () => [
2021-11-23 08:45:10 +01:00
LsDirBlocLoading(util.buildAccount(),
2021-08-16 21:05:00 +02:00
File(path: "remote.php/dav/files/admin/d1/d2-2"), []),
2021-11-23 08:45:10 +01:00
LsDirBlocSuccess(util.buildAccount(),
2021-08-16 21:05:00 +02:00
File(path: "remote.php/dav/files/admin/d1/d2-2"), []),
],
);
blocTest<LsDirBloc, LsDirBlocState>(
"query depth 2",
build: _buildBloc,
act: (bloc) => bloc.add(LsDirBlocQuery(
2021-11-23 08:45:10 +01:00
util.buildAccount(), File(path: "remote.php/dav/files/admin"),
2021-08-16 21:05:00 +02:00
depth: 2)),
expect: () => [
2021-11-23 08:45:10 +01:00
LsDirBlocLoading(util.buildAccount(),
2021-11-12 22:13:02 +01:00
File(path: "remote.php/dav/files/admin"), []),
2021-11-23 08:45:10 +01:00
LsDirBlocSuccess(
util.buildAccount(), File(path: "remote.php/dav/files/admin"), [
2021-08-16 21:05:00 +02:00
LsDirBlocItem(
File(
path: "remote.php/dav/files/admin/d1",
isCollection: true,
),
false,
2021-08-16 21:05:00 +02:00
[
LsDirBlocItem(
File(
path: "remote.php/dav/files/admin/d1/d2-1",
isCollection: true,
),
false,
2021-08-16 21:05:00 +02:00
null,
),
LsDirBlocItem(
File(
path: "remote.php/dav/files/admin/d1/d2-2",
isCollection: true,
),
false,
2021-08-16 21:05:00 +02:00
null,
),
],
),
]),
],
);
});
});
}
class _MockFileRepo extends MockFileMemoryRepo {
_MockFileRepo()
: super([
File(
path: "remote.php/dav/files/admin/test1.jpg",
),
File(
path: "remote.php/dav/files/admin/d1",
isCollection: true,
),
File(
path: "remote.php/dav/files/admin/d1/test2.jpg",
),
File(
path: "remote.php/dav/files/admin/d1/d2-1",
isCollection: true,
),
File(
path: "remote.php/dav/files/admin/d1/d2-2",
isCollection: true,
),
File(
path: "remote.php/dav/files/admin/d1/d2-1/d3",
isCollection: true,
),
]);
2021-08-16 21:05:00 +02:00
}