Fix: flutter test (#2421)

* fix: tauri compile

* ci: update

* fix: flutter test
This commit is contained in:
Nathan.fooo 2023-05-02 17:10:35 +08:00 committed by GitHub
parent f5b23e5fc1
commit 93d787a9ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 145 additions and 170 deletions

View File

@ -70,7 +70,7 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:
title: field.name, title: field.name,
fieldType: field.field_type, fieldType: field.field_type,
fieldOptions: { fieldOptions: {
numberFormat: typeOption.format, NumberFormatPB: typeOption.format,
}, },
}; };
} }
@ -82,8 +82,8 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:
title: field.name, title: field.name,
fieldType: field.field_type, fieldType: field.field_type,
fieldOptions: { fieldOptions: {
dateFormat: typeOption.date_format, DateFormatPB: typeOption.date_format,
timeFormat: typeOption.time_format, TimeFormatPB: typeOption.time_format,
includeTime: typeOption.include_time, includeTime: typeOption.include_time,
}, },
}; };

View File

@ -1315,54 +1315,6 @@ dependencies = [
"ws-model", "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]] [[package]]
name = "flowy-database2" name = "flowy-database2"
version = "0.1.0" version = "0.1.0"

View File

@ -16,7 +16,7 @@ members = [
"flowy-error", "flowy-error",
"flowy-revision", "flowy-revision",
"flowy-revision-persistence", "flowy-revision-persistence",
"flowy-database", # "flowy-database",
"flowy-database2", "flowy-database2",
"flowy-task", "flowy-task",
"flowy-client-sync", "flowy-client-sync",

View File

@ -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_folder={}", level));
filters.push(format!("flowy_folder2={}", level)); filters.push(format!("flowy_folder2={}", level));
filters.push(format!("collab_folder={}", 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_database={}", level));
filters.push(format!("collab={}", level)); filters.push(format!("collab={}", level));
filters.push(format!("flowy_user={}", level)); filters.push(format!("flowy_user={}", level));

View File

@ -241,9 +241,6 @@ pub enum DatabaseEvent {
#[event(input = "MoveGroupRowPayloadPB")] #[event(input = "MoveGroupRowPayloadPB")]
MoveGroupRow = 112, MoveGroupRow = 112,
#[event(input = "MoveGroupRowPayloadPB")]
GroupByField = 113,
/// Returns all the databases /// Returns all the databases
#[event(output = "RepeatedDatabaseDescriptionPB")] #[event(output = "RepeatedDatabaseDescriptionPB")]
GetDatabases = 114, GetDatabases = 114,

View File

@ -99,13 +99,15 @@ impl DatabaseEditor {
} }
pub async fn insert_group(&self, params: InsertGroupParams) -> FlowyResult<()> { pub async fn insert_group(&self, params: InsertGroupParams) -> FlowyResult<()> {
if let Some(field) = self.database.lock().fields.get_field(&params.field_id) { {
let group_setting = default_group_setting(&field); let database = self.database.lock();
self let field = database.fields.get_field(&params.field_id);
.database if let Some(field) = field {
.lock() let group_setting = default_group_setting(&field);
.insert_group_setting(&params.view_id, group_setting); database.insert_group_setting(&params.view_id, group_setting);
}
} }
let view_editor = self.database_views.get_view_editor(&params.view_id).await?; let view_editor = self.database_views.get_view_editor(&params.view_id).await?;
view_editor.v_initialize_new_group(params).await?; view_editor.v_initialize_new_group(params).await?;
Ok(()) Ok(())
@ -122,6 +124,7 @@ impl DatabaseEditor {
Ok(()) Ok(())
} }
#[tracing::instrument(level = "trace", skip_all, err)]
pub async fn create_or_update_filter(&self, params: AlterFilterParams) -> FlowyResult<()> { pub async fn create_or_update_filter(&self, params: AlterFilterParams) -> FlowyResult<()> {
let view_editor = self.database_views.get_view_editor(&params.view_id).await?; let view_editor = self.database_views.get_view_editor(&params.view_id).await?;
view_editor.v_insert_filter(params).await?; view_editor.v_insert_filter(params).await?;
@ -198,7 +201,6 @@ impl DatabaseEditor {
} }
pub async fn delete_field(&self, field_id: &str) -> FlowyResult<()> { pub async fn delete_field(&self, field_id: &str) -> FlowyResult<()> {
self.database.lock().delete_field(field_id);
let database_id = { let database_id = {
let database = self.database.lock(); let database = self.database.lock();
database.delete_field(field_id); database.delete_field(field_id);
@ -432,8 +434,13 @@ impl DatabaseEditor {
} }
pub async fn get_cell(&self, field_id: &str, row_id: RowId) -> CellPB { pub async fn get_cell(&self, field_id: &str, row_id: RowId) -> CellPB {
let field = self.database.lock().fields.get_field(field_id); let (field, cell) = {
let cell = self.database.lock().get_cell(field_id, &row_id); 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) { match (field, cell) {
(Some(field), Some(cell)) => { (Some(field), Some(cell)) => {
let field_type = FieldType::from(field.field_type); let field_type = FieldType::from(field.field_type);
@ -483,10 +490,7 @@ impl DatabaseEditor {
field_id: &str, field_id: &str,
new_cell: Cell, new_cell: Cell,
) -> Option<()> { ) -> Option<()> {
let old_row = { let old_row = { self.database.lock().get_row(&row_id) };
let database = self.database.lock();
database.get_row(&row_id)
};
self.database.lock().update_row(&row_id, |row_update| { self.database.lock().update_row(&row_id, |row_update| {
row_update.update_cells(|cell_update| { row_update.update_cells(|cell_update| {
cell_update.insert(field_id, new_cell); cell_update.insert(field_id, new_cell);

View File

@ -597,7 +597,7 @@ impl DatabaseViewEditor {
pub async fn v_did_update_field_type_option( pub async fn v_did_update_field_type_option(
&self, &self,
field_id: &str, field_id: &str,
_old_field: &Field, old_field: &Field,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
if let Some(field) = self.delegate.get_field(field_id).await { if let Some(field) = self.delegate.get_field(field_id).await {
self self
@ -607,25 +607,25 @@ impl DatabaseViewEditor {
.did_update_view_field_type_option(&field) .did_update_view_field_type_option(&field)
.await; .await;
// let filter = self if let Some(filter) = self
// .delegate .delegate
// .get_filter_by_field_id(&self.view_id, field_id); .get_filter_by_field_id(&self.view_id, field_id)
// {
// let old = old_field.map(|old_field| FilterType::from(filter)); let mut old = FilterType::from(&filter);
// let new = FilterType::from(field.as_ref()); old.field_type = FieldType::from(old_field.field_type);
// let filter_type = UpdatedFilterType::new(old, new); let new = FilterType::from(&filter);
// let filter_changeset = FilterChangeset::from_update(filter_type); let filter_type = UpdatedFilterType::new(Some(old), new);
// let filter_controller = self.filter_controller.clone(); let filter_changeset = FilterChangeset::from_update(filter_type);
// let _ = tokio::spawn(async move { let filter_controller = self.filter_controller.clone();
// if let Some(notification) = filter_controller let _ = tokio::spawn(async move {
// .did_receive_changes(filter_changeset) if let Some(notification) = filter_controller
// .await .did_receive_changes(filter_changeset)
// { .await
// send_notification(&notification.view_id, DatabaseNotification::DidUpdateFilter) {
// .payload(notification) notify_did_update_filter(notification).await;
// .send(); }
// } });
// }); }
} }
Ok(()) Ok(())
} }

View File

@ -131,6 +131,7 @@ impl std::convert::From<&FilterPB> for FilterType {
} }
} }
} }
// #[derive(Hash, Eq, PartialEq, Debug, Clone)] // #[derive(Hash, Eq, PartialEq, Debug, Clone)]
// pub struct InsertedFilterType { // pub struct InsertedFilterType {
// pub field_id: String, // pub field_id: String,

View File

@ -51,7 +51,7 @@ async fn grid_cell_update() {
scripts.push(UpdateCell { scripts.push(UpdateCell {
changeset: CellChangesetPB { changeset: CellChangesetPB {
view_id: test.view_id.clone(), view_id: test.view_id.clone(),
row_id: row.id.into(), row_id: row.id.clone().into(),
field_id: field.id.clone(), field_id: field.id.clone(),
cell_changeset, cell_changeset,
}, },

View File

@ -118,13 +118,13 @@ async fn grid_filter_single_select_is_test2() {
}, },
AssertNumberOfVisibleRows { expected: 2 }, AssertNumberOfVisibleRows { expected: 2 },
UpdateSingleSelectCell { UpdateSingleSelectCell {
row_id: rows[1].id, row_id: rows[1].id.clone(),
option_id: option.id.clone(), option_id: option.id.clone(),
changed: None, changed: None,
}, },
AssertNumberOfVisibleRows { expected: 3 }, AssertNumberOfVisibleRows { expected: 3 },
UpdateSingleSelectCell { UpdateSingleSelectCell {
row_id: rows[1].id, row_id: rows[1].id.clone(),
option_id: "".to_string(), option_id: "".to_string(),
changed: Some(FilterRowChanged { changed: Some(FilterRowChanged {
showing_num_of_rows: 0, showing_num_of_rows: 0,

View File

@ -99,7 +99,7 @@ async fn grid_filter_contain_text_test2() {
}), }),
}, },
UpdateTextCell { UpdateTextCell {
row_id: rows[1].id, row_id: rows[1].id.clone(),
text: "ABC".to_string(), text: "ABC".to_string(),
changed: Some(FilterRowChanged { changed: Some(FilterRowChanged {
showing_num_of_rows: 1, showing_num_of_rows: 1,
@ -232,7 +232,7 @@ async fn grid_filter_update_empty_text_cell_test() {
}, },
AssertFilterCount { count: 1 }, AssertFilterCount { count: 1 },
UpdateTextCell { UpdateTextCell {
row_id: rows[0].id, row_id: rows[0].id.clone(),
text: "".to_string(), text: "".to_string(),
changed: Some(FilterRowChanged { changed: Some(FilterRowChanged {
showing_num_of_rows: 1, showing_num_of_rows: 1,

View File

@ -45,7 +45,7 @@ async fn sort_change_notification_by_update_text_test() {
let rows = test.get_rows().await; let rows = test.get_rows().await;
let scripts = vec![ let scripts = vec![
UpdateTextCell { UpdateTextCell {
row_id: rows[2].id, row_id: rows[2].id.clone(),
text: "E".to_string(), text: "E".to_string(),
}, },
AssertSortChanged { AssertSortChanged {

View File

@ -189,76 +189,3 @@ script = [
] ]
script_runner = "@duckscript" 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"

View File

@ -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] [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'" description = "Run flutter test with single case in single file. Input: cargo make flutter_test 'path to the file' --name 'test case name'"
script = ''' script = '''
@ -28,7 +29,7 @@ script_runner = "@shell"
[tasks.run_dart_unit_test] [tasks.run_dart_unit_test]
env = { RUST_LOG = "info" } env = { RUST_LOG = "info" }
dependencies = ["build_test_backend"] dependencies = ["inner_build_test_backend"]
description = "Run flutter unit tests" description = "Run flutter unit tests"
script = ''' script = '''
cd appflowy_flutter cd appflowy_flutter
@ -222,3 +223,96 @@ run_task = { name = [
"get_lcov_report", "get_lcov_report",
"clean_profraw_files", "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"