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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
Fix: flutter test (#2421)
Nathan.fooo93d787a9aeb4
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/loadField.ts b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/loadField.tsindex 93546940b5..94f5455c67 100644--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/loadField.ts+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/loadField.ts@@ -70,7 +70,7 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:title: field.name,fieldType: field.field_type,fieldOptions: {- numberFormat: typeOption.format,+ NumberFormatPB: typeOption.format,},};}@@ -82,8 +82,8 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:title: field.name,fieldType: field.field_type,fieldOptions: {- dateFormat: typeOption.date_format,- timeFormat: typeOption.time_format,+ DateFormatPB: typeOption.date_format,+ TimeFormatPB: typeOption.time_format,includeTime: typeOption.include_time,},};diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lockindex 5932b46ef2..32e65f2162 100644--- a/frontend/rust-lib/Cargo.lock+++ b/frontend/rust-lib/Cargo.lock@@ -1315,54 +1315,6 @@ dependencies = ["ws-model",]-[[package]]-name = "flowy-database"-version = "0.1.0"-dependencies = [- "anyhow",- "async-stream",- "atomic_refcell",- "bytes",- "chrono",- "crossbeam-utils",- "dashmap",- "database-model",- "diesel",- "fancy-regex 0.10.0",- "flowy-client-sync",- "flowy-codegen",- "flowy-derive",- "flowy-error",- "flowy-notification",- "flowy-revision",- "flowy-revision-persistence",- "flowy-sqlite",- "flowy-task",- "flowy-test",- "futures",- "indexmap",- "lazy_static",- "lib-dispatch",- "lib-infra",- "lib-ot",- "nanoid",- "parking_lot 0.12.1",- "protobuf",- "rayon",- "regex",- "revision-model",- "rust_decimal",- "rusty-money",- "serde",- "serde_json",- "serde_repr",- "strum",- "strum_macros",- "tokio",- "tracing",- "url",-]-[[package]]name = "flowy-database2"version = "0.1.0"diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.tomlindex 948b121a5b..6810a48ecd 100644--- a/frontend/rust-lib/Cargo.toml+++ b/frontend/rust-lib/Cargo.toml@@ -16,7 +16,7 @@ members = ["flowy-error","flowy-revision","flowy-revision-persistence",- "flowy-database",+# "flowy-database","flowy-database2","flowy-task","flowy-client-sync",diff --git a/frontend/rust-lib/flowy-core/src/lib.rs b/frontend/rust-lib/flowy-core/src/lib.rsindex 54191ab542..f9ff14f445 100644--- a/frontend/rust-lib/flowy-core/src/lib.rs+++ b/frontend/rust-lib/flowy-core/src/lib.rs@@ -93,7 +93,7 @@ fn create_log_filter(level: String, with_crates: Vec<String>) -> String {filters.push(format!("flowy_folder={}", level));filters.push(format!("flowy_folder2={}", level));filters.push(format!("collab_folder={}", level));- filters.push(format!("collab_persistence={}", level));+ // filters.push(format!("collab_persistence={}", level));filters.push(format!("collab_database={}", level));filters.push(format!("collab={}", level));filters.push(format!("flowy_user={}", level));diff --git a/frontend/rust-lib/flowy-database2/src/event_map.rs b/frontend/rust-lib/flowy-database2/src/event_map.rsindex 72203be6f0..3f0261b664 100644--- a/frontend/rust-lib/flowy-database2/src/event_map.rs+++ b/frontend/rust-lib/flowy-database2/src/event_map.rs@@ -241,9 +241,6 @@ pub enum DatabaseEvent {#[event(input = "MoveGroupRowPayloadPB")]MoveGroupRow = 112,- #[event(input = "MoveGroupRowPayloadPB")]- GroupByField = 113,-/// Returns all the databases#[event(output = "RepeatedDatabaseDescriptionPB")]GetDatabases = 114,diff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rsindex 86b7c03063..08a00e278b 100644--- a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs@@ -99,13 +99,15 @@ impl DatabaseEditor {}pub async fn insert_group(&self, params: InsertGroupParams) -> FlowyResult<()> {- if let Some(field) = self.database.lock().fields.get_field(¶ms.field_id) {- let group_setting = default_group_setting(&field);- self- .database- .lock()- .insert_group_setting(¶ms.view_id, group_setting);+ {+ let database = self.database.lock();+ let field = database.fields.get_field(¶ms.field_id);+ if let Some(field) = field {+ let group_setting = default_group_setting(&field);+ database.insert_group_setting(¶ms.view_id, group_setting);+ }}+let view_editor = self.database_views.get_view_editor(¶ms.view_id).await?;view_editor.v_initialize_new_group(params).await?;Ok(())@@ -122,6 +124,7 @@ impl DatabaseEditor {Ok(())}+ #[tracing::instrument(level = "trace", skip_all, err)]pub async fn create_or_update_filter(&self, params: AlterFilterParams) -> FlowyResult<()> {let view_editor = self.database_views.get_view_editor(¶ms.view_id).await?;view_editor.v_insert_filter(params).await?;@@ -198,7 +201,6 @@ impl DatabaseEditor {}pub async fn delete_field(&self, field_id: &str) -> FlowyResult<()> {- self.database.lock().delete_field(field_id);let database_id = {let database = self.database.lock();database.delete_field(field_id);@@ -432,8 +434,13 @@ impl DatabaseEditor {}pub async fn get_cell(&self, field_id: &str, row_id: RowId) -> CellPB {- let field = self.database.lock().fields.get_field(field_id);- let cell = self.database.lock().get_cell(field_id, &row_id);+ let (field, cell) = {+ let database = self.database.lock();+ let field = database.fields.get_field(field_id);+ let cell = database.get_cell(field_id, &row_id);+ (field, cell)+ };+match (field, cell) {(Some(field), Some(cell)) => {let field_type = FieldType::from(field.field_type);@@ -483,10 +490,7 @@ impl DatabaseEditor {field_id: &str,new_cell: Cell,) -> Option<()> {- let old_row = {- let database = self.database.lock();- database.get_row(&row_id)- };+ let old_row = { self.database.lock().get_row(&row_id) };self.database.lock().update_row(&row_id, |row_update| {row_update.update_cells(|cell_update| {cell_update.insert(field_id, new_cell);diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rsindex 51ef077936..3213144425 100644--- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs+++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs@@ -597,7 +597,7 @@ impl DatabaseViewEditor {pub async fn v_did_update_field_type_option(&self,field_id: &str,- _old_field: &Field,+ old_field: &Field,) -> FlowyResult<()> {if let Some(field) = self.delegate.get_field(field_id).await {self@@ -607,25 +607,25 @@ impl DatabaseViewEditor {.did_update_view_field_type_option(&field).await;- // let filter = self- // .delegate- // .get_filter_by_field_id(&self.view_id, field_id);- //- // let old = old_field.map(|old_field| FilterType::from(filter));- // let new = FilterType::from(field.as_ref());- // let filter_type = UpdatedFilterType::new(old, new);- // let filter_changeset = FilterChangeset::from_update(filter_type);- // let filter_controller = self.filter_controller.clone();- // let _ = tokio::spawn(async move {- // if let Some(notification) = filter_controller- // .did_receive_changes(filter_changeset)- // .await- // {- // send_notification(¬ification.view_id, DatabaseNotification::DidUpdateFilter)- // .payload(notification)- // .send();- // }- // });+ if let Some(filter) = self+ .delegate+ .get_filter_by_field_id(&self.view_id, field_id)+ {+ let mut old = FilterType::from(&filter);+ old.field_type = FieldType::from(old_field.field_type);+ let new = FilterType::from(&filter);+ let filter_type = UpdatedFilterType::new(Some(old), new);+ let filter_changeset = FilterChangeset::from_update(filter_type);+ let filter_controller = self.filter_controller.clone();+ let _ = tokio::spawn(async move {+ if let Some(notification) = filter_controller+ .did_receive_changes(filter_changeset)+ .await+ {+ notify_did_update_filter(notification).await;+ }+ });+ }}Ok(())}diff --git a/frontend/rust-lib/flowy-database2/src/services/filter/entities.rs b/frontend/rust-lib/flowy-database2/src/services/filter/entities.rsindex c229952535..a5ec5ed8ea 100644--- a/frontend/rust-lib/flowy-database2/src/services/filter/entities.rs+++ b/frontend/rust-lib/flowy-database2/src/services/filter/entities.rs@@ -131,6 +131,7 @@ impl std::convert::From<&FilterPB> for FilterType {}}}+// #[derive(Hash, Eq, PartialEq, Debug, Clone)]// pub struct InsertedFilterType {// pub field_id: String,diff --git a/frontend/rust-lib/flowy-database2/tests/database/cell_test/test.rs b/frontend/rust-lib/flowy-database2/tests/database/cell_test/test.rsindex 3976d01883..f748b9905c 100644--- a/frontend/rust-lib/flowy-database2/tests/database/cell_test/test.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/cell_test/test.rs@@ -51,7 +51,7 @@ async fn grid_cell_update() {scripts.push(UpdateCell {changeset: CellChangesetPB {view_id: test.view_id.clone(),- row_id: row.id.into(),+ row_id: row.id.clone().into(),field_id: field.id.clone(),cell_changeset,},diff --git a/frontend/rust-lib/flowy-database2/tests/database/filter_test/select_option_filter_test.rs b/frontend/rust-lib/flowy-database2/tests/database/filter_test/select_option_filter_test.rsindex 6a920bad71..aeb9fcbe33 100644--- a/frontend/rust-lib/flowy-database2/tests/database/filter_test/select_option_filter_test.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/filter_test/select_option_filter_test.rs@@ -118,13 +118,13 @@ async fn grid_filter_single_select_is_test2() {},AssertNumberOfVisibleRows { expected: 2 },UpdateSingleSelectCell {- row_id: rows[1].id,+ row_id: rows[1].id.clone(),option_id: option.id.clone(),changed: None,},AssertNumberOfVisibleRows { expected: 3 },UpdateSingleSelectCell {- row_id: rows[1].id,+ row_id: rows[1].id.clone(),option_id: "".to_string(),changed: Some(FilterRowChanged {showing_num_of_rows: 0,diff --git a/frontend/rust-lib/flowy-database2/tests/database/filter_test/text_filter_test.rs b/frontend/rust-lib/flowy-database2/tests/database/filter_test/text_filter_test.rsindex eb16d3a5a5..1593e2e2e3 100644--- a/frontend/rust-lib/flowy-database2/tests/database/filter_test/text_filter_test.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/filter_test/text_filter_test.rs@@ -99,7 +99,7 @@ async fn grid_filter_contain_text_test2() {}),},UpdateTextCell {- row_id: rows[1].id,+ row_id: rows[1].id.clone(),text: "ABC".to_string(),changed: Some(FilterRowChanged {showing_num_of_rows: 1,@@ -232,7 +232,7 @@ async fn grid_filter_update_empty_text_cell_test() {},AssertFilterCount { count: 1 },UpdateTextCell {- row_id: rows[0].id,+ row_id: rows[0].id.clone(),text: "".to_string(),changed: Some(FilterRowChanged {showing_num_of_rows: 1,diff --git a/frontend/rust-lib/flowy-database2/tests/database/sort_test/single_sort_test.rs b/frontend/rust-lib/flowy-database2/tests/database/sort_test/single_sort_test.rsindex 6a751808d8..3ca2705db9 100644--- a/frontend/rust-lib/flowy-database2/tests/database/sort_test/single_sort_test.rs+++ b/frontend/rust-lib/flowy-database2/tests/database/sort_test/single_sort_test.rs@@ -45,7 +45,7 @@ async fn sort_change_notification_by_update_text_test() {let rows = test.get_rows().await;let scripts = vec![UpdateTextCell {- row_id: rows[2].id,+ row_id: rows[2].id.clone(),text: "E".to_string(),},AssertSortChanged {diff --git a/frontend/scripts/makefile/desktop.toml b/frontend/scripts/makefile/desktop.tomlindex a7b964d261..c4ccbdc20e 100644--- a/frontend/scripts/makefile/desktop.toml+++ b/frontend/scripts/makefile/desktop.toml@@ -189,76 +189,3 @@ script = []script_runner = "@duckscript"-[tasks.build_test_backend]-category = "Build"-dependencies = ["env_check"]-run_task = { name = [- "setup-test-crate-type",- "compile_test_backend",- "copy-to-sandbox-folder",- "restore-test-crate-type",-] }--[tasks.compile_test_backend]-mac_alias = "compile_test_backend_default"-windows_alias = "compile_test_backend_windows"-linux_alias = "compile_test_backend_default"--[tasks.compile_test_backend_default]-private = true-script = [- """- cd rust-lib/- rustup show- echo RUST_LOG=${RUST_LOG} cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"- RUST_LOG=${RUST_LOG} cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"- cd ../- """,-]-script_runner = "@shell"--[tasks.compile_test_backend_windows]-private = true-script = [- """- cd rust-lib/- rustup show- echo cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"- RUST_LOG=${RUST_LOG} cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"- cd ../- """,-]-script_runner = "@shell"--[tasks.copy-to-sandbox-folder]-mac_alias = "copy-to-sandbox-folder-default"-windows_alias = "copy-to-sandbox-folder-windows"-linux_alias = "copy-to-sandbox-folder-default"--[tasks.copy-to-sandbox-folder-windows]-private = true-script = [- """- # Copy the appflowy_backend lib to system temp directory for flutter unit test.- lib = set ${LIB_NAME}.${TEST_LIB_EXT}- dest = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/appflowy_flutter/.sandbox/${lib}- rm ${dest}- cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${TEST_COMPILE_TARGET}/${TEST_BUILD_FLAG}/${lib} \- ${dest}- """,-]-script_runner = "@duckscript"--[tasks.copy-to-sandbox-folder-default]-private = true-script = [- """- # Copy the appflowy_backend lib to system temp directory for flutter unit test.- lib = set lib${LIB_NAME}.${TEST_LIB_EXT}- dest = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/appflowy_flutter/.sandbox/${lib}- rm ${dest}- cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${TEST_COMPILE_TARGET}/${TEST_BUILD_FLAG}/${lib} \- ${dest}- """,-]-script_runner = "@duckscript"diff --git a/frontend/scripts/makefile/tests.toml b/frontend/scripts/makefile/tests.tomlindex d82b04d0a0..483869250f 100644--- a/frontend/scripts/makefile/tests.toml+++ b/frontend/scripts/makefile/tests.toml@@ -1,5 +1,6 @@-#RUST_LOG="debug" flutter test -j, --concurrency=1 'path to the file' --name 'test case name'+# If you want to test a single file with single case, you can try this command:+# RUST_LOG="debug" flutter test -j, --concurrency=1 'path to the file' --name 'test case name'[tasks.flutter_test]description = "Run flutter test with single case in single file. Input: cargo make flutter_test 'path to the file' --name 'test case name'"script = '''@@ -28,7 +29,7 @@ script_runner = "@shell"[tasks.run_dart_unit_test]env = { RUST_LOG = "info" }-dependencies = ["build_test_backend"]+dependencies = ["inner_build_test_backend"]description = "Run flutter unit tests"script = '''cd appflowy_flutter@@ -222,3 +223,96 @@ run_task = { name = ["get_lcov_report","clean_profraw_files",] }+++[tasks.build_test_backend]+script = '''+cargo make --profile test-macos-$(uname -m) inner_build_test_backend+'''+script_runner = "@shell"++[tasks.build_test_backend.windows]+script = '''+cargo make --profile test-windows inner_build_test_backend+'''+script_runner = "@shell"++[tasks.build_test_backend.linux]+script = '''+cargo make --profile test-linux inner_build_test_backend+'''+script_runner = "@shell"++[tasks.inner_build_test_backend]+category = "Build"+dependencies = ["env_check"]+run_task = { name = [+ "setup-test-crate-type",+ "compile_test_backend",+ "copy-to-sandbox-folder",+ "restore-test-crate-type",+] }++[tasks.compile_test_backend]+mac_alias = "compile_test_backend_default"+windows_alias = "compile_test_backend_windows"+linux_alias = "compile_test_backend_default"++[tasks.compile_test_backend_default]+private = true+script = [+ """+ cd rust-lib/+ rustup show+ echo RUST_LOG=${RUST_LOG} cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"+ RUST_LOG=${RUST_LOG} cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"+ cd ../+ """,+]+script_runner = "@shell"++[tasks.compile_test_backend_windows]+private = true+script = [+ """+ cd rust-lib/+ rustup show+ echo cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"+ RUST_LOG=${RUST_LOG} cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"+ cd ../+ """,+]+script_runner = "@shell"++[tasks.copy-to-sandbox-folder]+mac_alias = "copy-to-sandbox-folder-default"+windows_alias = "copy-to-sandbox-folder-windows"+linux_alias = "copy-to-sandbox-folder-default"++[tasks.copy-to-sandbox-folder-windows]+private = true+script = [+ """+ # Copy the appflowy_backend lib to system temp directory for flutter unit test.+ lib = set ${LIB_NAME}.${TEST_LIB_EXT}+ dest = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/appflowy_flutter/.sandbox/${lib}+ rm ${dest}+ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${TEST_COMPILE_TARGET}/${TEST_BUILD_FLAG}/${lib} \+ ${dest}+ """,+]+script_runner = "@duckscript"++[tasks.copy-to-sandbox-folder-default]+private = true+script = [+ """+ # Copy the appflowy_backend lib to system temp directory for flutter unit test.+ lib = set lib${LIB_NAME}.${TEST_LIB_EXT}+ dest = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/appflowy_flutter/.sandbox/${lib}+ rm ${dest}+ cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${TEST_COMPILE_TARGET}/${TEST_BUILD_FLAG}/${lib} \+ ${dest}+ """,+]+script_runner = "@duckscript"\ No newline at end of file