Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: dart test (#1920)

Nathan.fooo3f0d3d802ac1
diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart
index a486ae2e1f..a0be622128 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_view/board/application/board_bloc.dart
@@ -20,18 +20,18 @@ import 'group_controller.dart';
part 'board_bloc.freezed.dart';
class BoardBloc extends Bloc<BoardEvent, BoardState> {
- final BoardDataController _gridDataController;
+ final BoardDataController _boardDataController;
late final AppFlowyBoardController boardController;
final GroupBackendService _groupBackendSvc;
final LinkedHashMap<String, GroupController> groupControllers =
LinkedHashMap();
- FieldController get fieldController => _gridDataController.fieldController;
- String get viewId => _gridDataController.viewId;
+ FieldController get fieldController => _boardDataController.fieldController;
+ String get viewId => _boardDataController.viewId;
BoardBloc({required ViewPB view})
: _groupBackendSvc = GroupBackendService(viewId: view.id),
- _gridDataController = BoardDataController(view: view),
+ _boardDataController = BoardDataController(view: view),
super(BoardState.initial(view.id)) {
boardController = AppFlowyBoardController(
onMoveGroup: (
@@ -72,7 +72,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
},
createBottomRow: (groupId) async {
final startRowId = groupControllers[groupId]?.lastRow()?.id;
- final result = await _gridDataController.createBoardCard(
+ final result = await _boardDataController.createBoardCard(
groupId,
startRowId: startRowId,
);
@@ -82,7 +82,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
);
},
createHeaderRow: (String groupId) async {
- final result = await _gridDataController.createBoardCard(groupId);
+ final result = await _boardDataController.createBoardCard(groupId);
result.fold(
(_) {},
(err) => Log.error(err),
@@ -178,7 +178,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
@override
Future<void> close() async {
- await _gridDataController.dispose();
+ await _boardDataController.dispose();
for (final controller in groupControllers.values) {
controller.dispose();
}
@@ -204,11 +204,11 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
}
RowCache? getRowCache(String blockId) {
- return _gridDataController.rowCache;
+ return _boardDataController.rowCache;
}
void _startListening() {
- _gridDataController.addListener(
+ _boardDataController.addListener(
onDatabaseChanged: (grid) {
if (!isClosed) {
add(BoardEvent.didReceiveGridUpdate(grid));
@@ -264,7 +264,7 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
}
Future<void> _openGrid(Emitter<BoardState> emit) async {
- final result = await _gridDataController.openGrid();
+ final result = await _boardDataController.openGrid();
result.fold(
(grid) => emit(
state.copyWith(loadingState: GridLoadingState.finish(left(unit))),
diff --git a/frontend/appflowy_flutter/test/bloc_test/board_test/group_by_multi_select_field_test.dart b/frontend/appflowy_flutter/test/bloc_test/board_test/group_by_multi_select_field_test.dart
index 50dffc62e1..af8a06d06d 100644
--- a/frontend/appflowy_flutter/test/bloc_test/board_test/group_by_multi_select_field_test.dart
+++ b/frontend/appflowy_flutter/test/bloc_test/board_test/group_by_multi_select_field_test.dart
@@ -1,6 +1,6 @@
import 'package:appflowy/plugins/database_view/application/cell/cell_controller_builder.dart';
import 'package:appflowy/plugins/database_view/application/setting/group_bloc.dart';
-// import 'package:appflowy/plugins/database_view/board/application/board_bloc.dart';
+import 'package:appflowy/plugins/database_view/board/application/board_bloc.dart';
import 'package:appflowy/plugins/database_view/grid/application/cell/select_option_editor_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-database/field_entities.pb.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -37,15 +37,15 @@ void main() {
await boardResponseFuture();
//assert only have the 'No status' group
- // final boardBloc = BoardBloc(view: context.gridView)
- // ..add(const BoardEvent.initial());
- // await boardResponseFuture();
- // assert(boardBloc.groupControllers.values.length == 1,
- // "Expected 1, but receive ${boardBloc.groupControllers.values.length}");
- // final expectedGroupName = "No ${multiSelectField.name}";
- // assert(
- // boardBloc.groupControllers.values.first.group.desc == expectedGroupName,
- // "Expected $expectedGroupName, but receive ${boardBloc.groupControllers.values.first.group.desc}");
+ final boardBloc = BoardBloc(view: context.gridView)
+ ..add(const BoardEvent.initial());
+ await boardResponseFuture();
+ assert(boardBloc.groupControllers.values.length == 1,
+ "Expected 1, but receive ${boardBloc.groupControllers.values.length}");
+ final expectedGroupName = "No ${multiSelectField.name}";
+ assert(
+ boardBloc.groupControllers.values.first.group.desc == expectedGroupName,
+ "Expected $expectedGroupName, but receive ${boardBloc.groupControllers.values.first.group.desc}");
});
test('group by multi select with no options test', () async {
@@ -84,16 +84,16 @@ void main() {
await boardResponseFuture();
// assert there are only three group
- // final boardBloc = BoardBloc(view: context.gridView)
- // ..add(const BoardEvent.initial());
- // await boardResponseFuture();
- // assert(boardBloc.groupControllers.values.length == 3,
- // "Expected 3, but receive ${boardBloc.groupControllers.values.length}");
-
- // final groups =
- // boardBloc.groupControllers.values.map((e) => e.group).toList();
- // assert(groups[0].desc == "No ${multiSelectField.name}");
- // assert(groups[1].desc == "B");
- // assert(groups[2].desc == "A");
+ final boardBloc = BoardBloc(view: context.gridView)
+ ..add(const BoardEvent.initial());
+ await boardResponseFuture();
+ assert(boardBloc.groupControllers.values.length == 3,
+ "Expected 3, but receive ${boardBloc.groupControllers.values.length}");
+
+ final groups =
+ boardBloc.groupControllers.values.map((e) => e.group).toList();
+ assert(groups[0].desc == "No ${multiSelectField.name}");
+ assert(groups[1].desc == "B");
+ assert(groups[2].desc == "A");
});
}
diff --git a/frontend/appflowy_flutter/test/bloc_test/grid_test/filter/create_filter_test.dart b/frontend/appflowy_flutter/test/bloc_test/grid_test/filter/create_filter_test.dart
index 5273f1e8f2..4b66bec059 100644
--- a/frontend/appflowy_flutter/test/bloc_test/grid_test/filter/create_filter_test.dart
+++ b/frontend/appflowy_flutter/test/bloc_test/grid_test/filter/create_filter_test.dart
@@ -44,7 +44,7 @@ void main() {
);
await gridResponseFuture();
- assert(context.fieldController.filterInfos.isEmpty);
+ expect(context.fieldController.filterInfos.length, 0);
});
test('filter rows with condition: text is empty', () async {
@@ -64,7 +64,7 @@ void main() {
content: "");
await gridResponseFuture();
- assert(gridBloc.state.rowInfos.length == 3);
+ expect(gridBloc.state.rowInfos.length, 3);
});
test('filter rows with condition: text is empty(After edit the row)',
diff --git a/frontend/rust-lib/flowy-database/src/manager.rs b/frontend/rust-lib/flowy-database/src/manager.rs
index db0d894efe..44f6a761cd 100644
--- a/frontend/rust-lib/flowy-database/src/manager.rs
+++ b/frontend/rust-lib/flowy-database/src/manager.rs
@@ -203,28 +203,45 @@ impl DatabaseManager {
database_id: &str,
view_id: &str,
) -> FlowyResult<Arc<DatabaseEditor>> {
- if let Some(database_editor) = self.editors_by_database_id.read().await.get(database_id) {
- let user_id = self.database_user.user_id()?;
- let (view_pad, view_rev_manager) =
- make_database_view_revision_pad(view_id, self.database_user.clone()).await?;
-
- let view_editor = DatabaseViewEditor::from_pad(
+ let user = self.database_user.clone();
+ let create_view_editor = |database_editor: Arc<DatabaseEditor>| async move {
+ let user_id = user.user_id()?;
+ let (view_pad, view_rev_manager) = make_database_view_revision_pad(view_id, user).await?;
+ return DatabaseViewEditor::from_pad(
&user_id,
database_editor.database_view_data.clone(),
database_editor.cell_data_cache.clone(),
view_rev_manager,
view_pad,
)
- .await?;
- database_editor.open_view_editor(view_editor).await;
- return Ok(database_editor.clone());
- }
- // Lock the database_editors
- let mut editors_by_database_id = self.editors_by_database_id.write().await;
- let db_pool = self.database_user.db_pool()?;
- let editor = self.make_database_rev_editor(view_id, db_pool).await?;
- editors_by_database_id.insert(database_id.to_string(), editor.clone());
- Ok(editor)
+ .await;
+ };
+
+ let database_editor = self
+ .editors_by_database_id
+ .read()
+ .await
+ .get(database_id)
+ .cloned();
+
+ return match database_editor {
+ None => {
+ let mut editors_by_database_id = self.editors_by_database_id.write().await;
+ let db_pool = self.database_user.db_pool()?;
+ let database_editor = self.make_database_rev_editor(view_id, db_pool).await?;
+ editors_by_database_id.insert(database_id.to_string(), database_editor.clone());
+ Ok(database_editor)
+ },
+ Some(database_editor) => {
+ let is_open = database_editor.is_view_open(view_id).await;
+ if !is_open {
+ let database_view_editor = create_view_editor(database_editor.clone()).await?;
+ database_editor.open_view_editor(database_view_editor).await;
+ }
+
+ Ok(database_editor)
+ },
+ };
}
#[tracing::instrument(level = "trace", skip(self, pool), err)]
diff --git a/frontend/rust-lib/flowy-database/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database/src/services/database/database_editor.rs
index 701ff72a98..c2740556e9 100644
--- a/frontend/rust-lib/flowy-database/src/services/database/database_editor.rs
+++ b/frontend/rust-lib/flowy-database/src/services/database/database_editor.rs
@@ -131,6 +131,9 @@ impl DatabaseEditor {
self.database_views.number_of_views().await
}
+ pub async fn is_view_open(&self, view_id: &str) -> bool {
+ self.database_views.is_view_exist(view_id).await
+ }
/// Save the type-option data to disk and send a `DatabaseNotification::DidUpdateField` notification
/// to dart side.
///
diff --git a/frontend/rust-lib/flowy-database/src/services/database_view/editor_manager.rs b/frontend/rust-lib/flowy-database/src/services/database_view/editor_manager.rs
index cd04461efa..c8cf5f5453 100644
--- a/frontend/rust-lib/flowy-database/src/services/database_view/editor_manager.rs
+++ b/frontend/rust-lib/flowy-database/src/services/database_view/editor_manager.rs
@@ -61,12 +61,8 @@ impl DatabaseViews {
}
pub async fn close(&self, view_id: &str) {
- if let Ok(mut view_editors) = self.view_editors.try_write() {
- if let Some(view_editor) = view_editors.remove(view_id) {
- view_editor.close().await;
- }
- } else {
- tracing::error!("Try to get the lock of view_editors failed");
+ if let Some(view_editor) = self.view_editors.write().await.remove(view_id) {
+ view_editor.close().await;
}
}
@@ -74,6 +70,10 @@ impl DatabaseViews {
self.view_editors.read().await.values().len()
}
+ pub async fn is_view_exist(&self, view_id: &str) -> bool {
+ self.view_editors.read().await.get(view_id).is_some()
+ }
+
pub async fn subscribe_view_changed(
&self,
view_id: &str,
diff --git a/frontend/scripts/makefile/tests.toml b/frontend/scripts/makefile/tests.toml
index 146ee481b0..3f85eaa75e 100644
--- a/frontend/scripts/makefile/tests.toml
+++ b/frontend/scripts/makefile/tests.toml
@@ -1,23 +1,23 @@
[tasks.dart_unit_test]
script = '''
-cargo make --profile test-macos dart_unit_test_impl
+cargo make --profile test-macos run_dart_unit_test
'''
script_runner = "@shell"
[tasks.dart_unit_test.windows]
script = '''
-cargo make --profile test-windows dart_unit_test_impl
+cargo make --profile test-windows run_dart_unit_test
'''
script_runner = "@shell"
[tasks.dart_unit_test.linux]
script = '''
-cargo make --profile test-linux dart_unit_test_impl
+cargo make --profile test-linux run_dart_unit_test
'''
script_runner = "@shell"
-[tasks.dart_unit_test_impl]
+[tasks.run_dart_unit_test]
env = { RUST_LOG = "info" }
dependencies = ["build_test_backend"]
description = "Run flutter unit tests"