From 170bbb6db02c84c8d4383c5ec57c4054cd3c6659 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Wed, 26 Oct 2022 11:09:51 +0800 Subject: [PATCH] test: add home bloc test (#1371) --- .../app_bloc_test.dart | 0 .../bloc_test/home_test/home_bloc_test.dart | 74 +++++++++++++++++++ .../menu_bloc_test.dart | 0 .../trash_bloc_test.dart | 0 .../view_bloc_test.dart | 0 .../flowy-user/src/handlers/user_handler.rs | 2 +- 6 files changed, 75 insertions(+), 1 deletion(-) rename frontend/app_flowy/test/bloc_test/{menu_test => home_test}/app_bloc_test.dart (100%) create mode 100644 frontend/app_flowy/test/bloc_test/home_test/home_bloc_test.dart rename frontend/app_flowy/test/bloc_test/{menu_test => home_test}/menu_bloc_test.dart (100%) rename frontend/app_flowy/test/bloc_test/{menu_test => home_test}/trash_bloc_test.dart (100%) rename frontend/app_flowy/test/bloc_test/{menu_test => home_test}/view_bloc_test.dart (100%) diff --git a/frontend/app_flowy/test/bloc_test/menu_test/app_bloc_test.dart b/frontend/app_flowy/test/bloc_test/home_test/app_bloc_test.dart similarity index 100% rename from frontend/app_flowy/test/bloc_test/menu_test/app_bloc_test.dart rename to frontend/app_flowy/test/bloc_test/home_test/app_bloc_test.dart diff --git a/frontend/app_flowy/test/bloc_test/home_test/home_bloc_test.dart b/frontend/app_flowy/test/bloc_test/home_test/home_bloc_test.dart new file mode 100644 index 0000000000..69ab062922 --- /dev/null +++ b/frontend/app_flowy/test/bloc_test/home_test/home_bloc_test.dart @@ -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( + "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( + "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( + "open the document", + build: () => DocumentBloc(view: latestCreatedView) + ..add(const DocumentEvent.initial()), + wait: blocResponseDuration(), + ); + + test('description', () async { + assert(homeBloc.state.workspaceSetting.latestView.id == + latestCreatedView.id); + }); + }); +} diff --git a/frontend/app_flowy/test/bloc_test/menu_test/menu_bloc_test.dart b/frontend/app_flowy/test/bloc_test/home_test/menu_bloc_test.dart similarity index 100% rename from frontend/app_flowy/test/bloc_test/menu_test/menu_bloc_test.dart rename to frontend/app_flowy/test/bloc_test/home_test/menu_bloc_test.dart diff --git a/frontend/app_flowy/test/bloc_test/menu_test/trash_bloc_test.dart b/frontend/app_flowy/test/bloc_test/home_test/trash_bloc_test.dart similarity index 100% rename from frontend/app_flowy/test/bloc_test/menu_test/trash_bloc_test.dart rename to frontend/app_flowy/test/bloc_test/home_test/trash_bloc_test.dart diff --git a/frontend/app_flowy/test/bloc_test/menu_test/view_bloc_test.dart b/frontend/app_flowy/test/bloc_test/home_test/view_bloc_test.dart similarity index 100% rename from frontend/app_flowy/test/bloc_test/menu_test/view_bloc_test.dart rename to frontend/app_flowy/test/bloc_test/home_test/view_bloc_test.dart diff --git a/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs b/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs index 8a10dd89e2..12b869903e 100644 --- a/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs +++ b/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs @@ -54,7 +54,7 @@ pub async fn set_appearance_setting(data: Data) -> Result< Ok(()) } -#[tracing::instrument(err)] +#[tracing::instrument(level = "debug", err)] pub async fn get_appearance_setting() -> DataResult { match KV::get_str(APPEARANCE_SETTING_CACHE_KEY) { None => data_result(AppearanceSettingsPB::default()),