Inject repo to LsDirBloc

This commit is contained in:
Ming Ming 2021-11-11 22:18:33 +08:00
parent c05493ac5d
commit d1841556c2
3 changed files with 5 additions and 7 deletions

View file

@ -3,7 +3,6 @@ import 'package:equatable/equatable.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/use_case/ls.dart';
class LsDirBlocItem with EquatableMixin {
@ -146,9 +145,7 @@ class LsDirBlocFailure extends LsDirBlocState {
/// A bloc that return all directories under a dir recursively
class LsDirBloc extends Bloc<LsDirBlocEvent, LsDirBlocState> {
LsDirBloc({
this.fileRepo = const FileRepo(FileWebdavDataSource()),
}) : super(LsDirBlocInit());
LsDirBloc(this.fileRepo) : super(LsDirBlocInit());
@override
mapEventToState(LsDirBlocEvent event) async* {

View file

@ -7,6 +7,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/bloc/ls_dir.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file/data_source.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
@ -383,7 +384,7 @@ class DirPickerState extends State<DirPicker> {
_bloc.add(LsDirBlocQuery(widget.account, file, depth: 2));
}
final _bloc = LsDirBloc();
final _bloc = LsDirBloc(const FileRepo(FileWebdavDataSource()));
late LsDirBlocItem _root;
var _currentPath = "";

View file

@ -8,10 +8,10 @@ import 'package:test/test.dart';
import '../mock_type.dart';
void main() {
_buildBloc() => LsDirBloc(fileRepo: _MockFileRepo());
_buildBloc() => LsDirBloc(_MockFileRepo());
_buildAccount() => Account("http", "example.com", "admin", "pass", [""]);
group("ListDir", () {
group("LsDirBloc", () {
group("LsDirBlocQuery", () {
test("initial state", () {
final bloc = _buildBloc();