mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: dart test (#1920)
This commit is contained in:
parent
0f3c6d6a04
commit
3f0d3d802a
@ -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))),
|
||||
|
@ -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 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 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");
|
||||
});
|
||||
}
|
||||
|
@ -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)',
|
||||
|
@ -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)]
|
||||
|
@ -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.
|
||||
///
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user