mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
test: add home bloc test (#1371)
This commit is contained in:
parent
2eea57aefa
commit
170bbb6db0
@ -0,0 +1,74 @@
|
||||
import 'package:app_flowy/plugins/doc/application/doc_bloc.dart';
|
||||
import 'package:app_flowy/plugins/doc/document.dart';
|
||||
import 'package:app_flowy/workspace/application/app/app_bloc.dart';
|
||||
import 'package:app_flowy/workspace/application/home/home_bloc.dart';
|
||||
import 'package:bloc_test/bloc_test.dart';
|
||||
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../util.dart';
|
||||
|
||||
void main() {
|
||||
late AppFlowyUnitTest testContext;
|
||||
late WorkspaceSettingPB workspaceSetting;
|
||||
setUpAll(() async {
|
||||
testContext = await AppFlowyUnitTest.ensureInitialized();
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
workspaceSetting = await FolderEventReadCurrentWorkspace()
|
||||
.send()
|
||||
.then((result) => result.fold((l) => l, (r) => throw Exception()));
|
||||
await blocResponseFuture();
|
||||
});
|
||||
|
||||
group('$HomeBloc', () {
|
||||
blocTest<HomeBloc, HomeState>(
|
||||
"initial",
|
||||
build: () => HomeBloc(testContext.userProfile, workspaceSetting)
|
||||
..add(const HomeEvent.initial()),
|
||||
wait: blocResponseDuration(),
|
||||
verify: (bloc) {
|
||||
assert(bloc.state.workspaceSetting.hasLatestView());
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('$HomeBloc', () {
|
||||
late AppPB app;
|
||||
late ViewPB latestCreatedView;
|
||||
late HomeBloc homeBloc;
|
||||
setUpAll(() async {
|
||||
app = await testContext.createTestApp();
|
||||
homeBloc = HomeBloc(testContext.userProfile, workspaceSetting)
|
||||
..add(const HomeEvent.initial());
|
||||
});
|
||||
|
||||
blocTest<AppBloc, AppState>(
|
||||
"create a document view",
|
||||
build: () => AppBloc(app: app)..add(const AppEvent.initial()),
|
||||
act: (bloc) async {
|
||||
bloc.add(AppEvent.createView("New document", DocumentPluginBuilder()));
|
||||
},
|
||||
wait: blocResponseDuration(),
|
||||
verify: (bloc) {
|
||||
latestCreatedView = bloc.state.views.last;
|
||||
},
|
||||
);
|
||||
|
||||
blocTest<DocumentBloc, DocumentState>(
|
||||
"open the document",
|
||||
build: () => DocumentBloc(view: latestCreatedView)
|
||||
..add(const DocumentEvent.initial()),
|
||||
wait: blocResponseDuration(),
|
||||
);
|
||||
|
||||
test('description', () async {
|
||||
assert(homeBloc.state.workspaceSetting.latestView.id ==
|
||||
latestCreatedView.id);
|
||||
});
|
||||
});
|
||||
}
|
@ -54,7 +54,7 @@ pub async fn set_appearance_setting(data: Data<AppearanceSettingsPB>) -> Result<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(err)]
|
||||
#[tracing::instrument(level = "debug", err)]
|
||||
pub async fn get_appearance_setting() -> DataResult<AppearanceSettingsPB, FlowyError> {
|
||||
match KV::get_str(APPEARANCE_SETTING_CACHE_KEY) {
|
||||
None => data_result(AppearanceSettingsPB::default()),
|
||||
|
Loading…
Reference in New Issue
Block a user