Browse Source

test: add home bloc test (#1371)

Nathan.fooo 2 years ago
parent
commit
170bbb6db0

+ 0 - 0
frontend/app_flowy/test/bloc_test/menu_test/app_bloc_test.dart → frontend/app_flowy/test/bloc_test/home_test/app_bloc_test.dart


+ 74 - 0
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<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);
+    });
+  });
+}

+ 0 - 0
frontend/app_flowy/test/bloc_test/menu_test/menu_bloc_test.dart → frontend/app_flowy/test/bloc_test/home_test/menu_bloc_test.dart


+ 0 - 0
frontend/app_flowy/test/bloc_test/menu_test/trash_bloc_test.dart → frontend/app_flowy/test/bloc_test/home_test/trash_bloc_test.dart


+ 0 - 0
frontend/app_flowy/test/bloc_test/menu_test/view_bloc_test.dart → frontend/app_flowy/test/bloc_test/home_test/view_bloc_test.dart


+ 1 - 1
frontend/rust-lib/flowy-user/src/handlers/user_handler.rs

@@ -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()),