chore: add field editor bloc test (#1342)

* chore: add field editor bloc test

* chore: update log

Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
Nathan.fooo 2022-10-23 16:56:33 +08:00 committed by GitHub
parent 96b1c6a540
commit c65d00e95c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 3 deletions

View File

@ -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);
},
);
});
}

View File

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

View File

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