Browse Source

chore: add field editor bloc test (#1342)

* chore: add field editor bloc test

* chore: update log

Co-authored-by: nathan <[email protected]>
Nathan.fooo 2 years ago
parent
commit
c65d00e95c

+ 86 - 0
frontend/app_flowy/test/bloc_test/grid_test/field_edit_bloc_test.dart

@@ -0,0 +1,86 @@
+import 'package:app_flowy/plugins/grid/application/field/type_option/type_option_context.dart';
+import 'package:app_flowy/plugins/grid/application/prelude.dart';
+import 'package:bloc_test/bloc_test.dart';
+import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+import 'util.dart';
+
+void main() {
+  late AppFlowyGridTest gridTest;
+
+  setUpAll(() async {
+    gridTest = await AppFlowyGridTest.ensureInitialized();
+  });
+
+  group('$FieldEditorBloc', () {
+    late FieldEditorBloc editorBloc;
+
+    setUp(() async {
+      await gridTest.createTestGrid();
+      final fieldContext = gridTest.singleSelectFieldContext();
+      final loader = FieldTypeOptionLoader(
+        gridId: gridTest.gridView.id,
+        field: fieldContext.field,
+      );
+
+      editorBloc = FieldEditorBloc(
+        gridId: gridTest.gridView.id,
+        fieldName: fieldContext.name,
+        isGroupField: fieldContext.isGroupField,
+        loader: loader,
+      )..add(const FieldEditorEvent.initial());
+
+      await gridResponseFuture();
+    });
+
+    blocTest<FieldEditorBloc, FieldEditorState>(
+      "rename field",
+      build: () => editorBloc,
+      act: (bloc) async {
+        editorBloc.add(const FieldEditorEvent.updateName('Hello world'));
+      },
+      wait: gridResponseDuration(),
+      verify: (bloc) {
+        bloc.state.field.fold(
+          () => throw Exception("The field should not be none"),
+          (field) {
+            assert(field.name == 'Hello world');
+          },
+        );
+      },
+    );
+
+    blocTest<FieldEditorBloc, FieldEditorState>(
+      "switch to text field",
+      build: () => editorBloc,
+      act: (bloc) async {
+        editorBloc.dataController.switchToField(FieldType.RichText);
+      },
+      wait: gridResponseDuration(),
+      verify: (bloc) {
+        bloc.state.field.fold(
+          () => throw Exception("The field should not be none"),
+          (field) {
+            // The default length of the fields is 3. The length of the fields
+            // should not change after switching to other field type
+            assert(gridTest.fieldContexts.length == 3);
+            assert(field.fieldType == FieldType.RichText);
+          },
+        );
+      },
+    );
+
+    blocTest<FieldEditorBloc, FieldEditorState>(
+      "delete field",
+      build: () => editorBloc,
+      act: (bloc) async {
+        editorBloc.add(const FieldEditorEvent.deleteField());
+      },
+      wait: gridResponseDuration(),
+      verify: (bloc) {
+        assert(gridTest.fieldContexts.length == 2);
+      },
+    );
+  });
+}

+ 1 - 1
frontend/app_flowy/test/bloc_test/grid_test/grid_header_bloc_test.dart

@@ -12,7 +12,7 @@ void main() {
     gridTest = await AppFlowyGridTest.ensureInitialized();
   });
 
-  group('GridHeaderBloc', () {
+  group('$GridHeaderBloc', () {
     late FieldActionSheetBloc actionSheetBloc;
     setUp(() async {
       await gridTest.createTestGrid();

+ 2 - 2
frontend/rust-lib/flowy-document/src/services/migration.rs

@@ -30,7 +30,7 @@ impl DocumentMigration {
         let conn = &*pool.get()?;
         let disk_cache = SQLiteDocumentRevisionPersistence::new(&self.user_id, pool);
         let documents = DeltaRevisionSql::read_all_documents(&self.user_id, conn)?;
-        tracing::info!("[Document Migration]: try migrate {} documents", documents.len());
+        tracing::debug!("[Document Migration]: try migrate {} documents", documents.len());
         for revisions in documents {
             if revisions.is_empty() {
                 continue;
@@ -66,7 +66,7 @@ impl DocumentMigration {
         //
 
         KV::set_bool(&key, true);
-        tracing::info!("Run document v1 migration");
+        tracing::debug!("Run document v1 migration");
         Ok(())
     }
 }