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