mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
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:
parent
96b1c6a540
commit
c65d00e95c
@ -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);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
@ -12,7 +12,7 @@ void main() {
|
||||
gridTest = await AppFlowyGridTest.ensureInitialized();
|
||||
});
|
||||
|
||||
group('GridHeaderBloc', () {
|
||||
group('$GridHeaderBloc', () {
|
||||
late FieldActionSheetBloc actionSheetBloc;
|
||||
setUp(() async {
|
||||
await gridTest.createTestGrid();
|
||||
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user