mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: cell data transform logic (#5039)
* refactor: cell data transform logic * chore: remove redundant select option event * chore: adapt tests to changes
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use collab_database::fields::{Field, TypeOptionData};
|
||||
|
||||
use flowy_database2::entities::{CreateFieldParams, FieldChangesetParams, FieldType};
|
||||
use flowy_database2::services::cell::stringify_cell_data;
|
||||
use flowy_database2::services::cell::stringify_cell;
|
||||
|
||||
use crate::database::database_editor::DatabaseEditorTest;
|
||||
|
||||
@ -31,7 +31,6 @@ pub enum FieldScript {
|
||||
AssertCellContent {
|
||||
field_id: String,
|
||||
row_index: usize,
|
||||
from_field_type: FieldType,
|
||||
expected_content: String,
|
||||
},
|
||||
}
|
||||
@ -118,17 +117,15 @@ impl DatabaseFieldTest {
|
||||
FieldScript::AssertCellContent {
|
||||
field_id,
|
||||
row_index,
|
||||
from_field_type,
|
||||
expected_content,
|
||||
} => {
|
||||
let field = self.editor.get_field(&field_id).unwrap();
|
||||
let field_type = FieldType::from(field.field_type);
|
||||
|
||||
let rows = self.editor.get_rows(&self.view_id()).await.unwrap();
|
||||
let row_detail = rows.get(row_index).unwrap();
|
||||
|
||||
let cell = row_detail.row.cells.get(&field_id).unwrap().clone();
|
||||
let content = stringify_cell_data(&cell, &from_field_type, &field_type, &field);
|
||||
let content = stringify_cell(&cell, &field);
|
||||
assert_eq!(content, expected_content);
|
||||
},
|
||||
}
|
||||
|
@ -155,8 +155,6 @@ async fn grid_switch_from_checkbox_to_select_option_test() {
|
||||
field_id: checkbox_field.id.clone(),
|
||||
// the mock data of the checkbox with row_index one is "true"
|
||||
row_index: 1,
|
||||
// the from_field_type represents as the current field type
|
||||
from_field_type: FieldType::Checkbox,
|
||||
// The content of the checkbox should transform to the corresponding option name.
|
||||
expected_content: CHECK.to_string(),
|
||||
},
|
||||
@ -190,7 +188,6 @@ async fn grid_switch_from_multi_select_to_text_test() {
|
||||
let script_assert_field = vec![AssertCellContent {
|
||||
field_id: field_rev.id.clone(),
|
||||
row_index: 0,
|
||||
from_field_type: FieldType::MultiSelect,
|
||||
expected_content: format!(
|
||||
"{},{}",
|
||||
multi_select_type_option.first().unwrap().name,
|
||||
@ -218,13 +215,11 @@ async fn grid_switch_from_checkbox_to_text_test() {
|
||||
AssertCellContent {
|
||||
field_id: field_rev.id.clone(),
|
||||
row_index: 1,
|
||||
from_field_type: FieldType::Checkbox,
|
||||
expected_content: "Yes".to_string(),
|
||||
},
|
||||
AssertCellContent {
|
||||
field_id: field_rev.id.clone(),
|
||||
row_index: 2,
|
||||
from_field_type: FieldType::Checkbox,
|
||||
expected_content: "No".to_string(),
|
||||
},
|
||||
];
|
||||
@ -246,13 +241,11 @@ async fn grid_switch_from_date_to_text_test() {
|
||||
AssertCellContent {
|
||||
field_id: field.id.clone(),
|
||||
row_index: 2,
|
||||
from_field_type: FieldType::DateTime,
|
||||
expected_content: "2022/03/14".to_string(),
|
||||
},
|
||||
AssertCellContent {
|
||||
field_id: field.id.clone(),
|
||||
row_index: 3,
|
||||
from_field_type: FieldType::DateTime,
|
||||
expected_content: "2022/11/17".to_string(),
|
||||
},
|
||||
];
|
||||
@ -275,13 +268,11 @@ async fn grid_switch_from_number_to_text_test() {
|
||||
AssertCellContent {
|
||||
field_id: field.id.clone(),
|
||||
row_index: 0,
|
||||
from_field_type: FieldType::Number,
|
||||
expected_content: "$1".to_string(),
|
||||
},
|
||||
AssertCellContent {
|
||||
field_id: field.id.clone(),
|
||||
row_index: 4,
|
||||
from_field_type: FieldType::Number,
|
||||
expected_content: "".to_string(),
|
||||
},
|
||||
];
|
||||
@ -303,7 +294,6 @@ async fn grid_switch_from_checklist_to_text_test() {
|
||||
AssertCellContent {
|
||||
field_id: field_rev.id.clone(),
|
||||
row_index: 0,
|
||||
from_field_type: FieldType::Checklist,
|
||||
expected_content: "First thing".to_string(),
|
||||
},
|
||||
];
|
||||
|
@ -48,7 +48,7 @@ async fn according_to_text_contains_filter_test() {
|
||||
AssertCellContent {
|
||||
field_id: text_field.id,
|
||||
row_index: test.row_details.len() - 1,
|
||||
from_field_type: FieldType::RichText,
|
||||
|
||||
expected_content: "sample".to_string(),
|
||||
},
|
||||
];
|
||||
@ -195,7 +195,7 @@ async fn according_to_checkbox_is_checked_filter_test() {
|
||||
AssertCellContent {
|
||||
field_id: checkbox_field.id,
|
||||
row_index: 3,
|
||||
from_field_type: FieldType::Checkbox,
|
||||
|
||||
expected_content: "Yes".to_string(),
|
||||
},
|
||||
];
|
||||
@ -242,7 +242,7 @@ async fn according_to_date_time_is_filter_test() {
|
||||
AssertCellContent {
|
||||
field_id: datetime_field.id,
|
||||
row_index: 0,
|
||||
from_field_type: FieldType::DateTime,
|
||||
|
||||
expected_content: "2024/03/15".to_string(),
|
||||
},
|
||||
];
|
||||
@ -331,7 +331,7 @@ async fn according_to_select_option_is_filter_test() {
|
||||
AssertCellContent {
|
||||
field_id: multi_select_field.id,
|
||||
row_index: 1,
|
||||
from_field_type: FieldType::MultiSelect,
|
||||
|
||||
expected_content: stringified_expected,
|
||||
},
|
||||
];
|
||||
@ -380,7 +380,7 @@ async fn according_to_select_option_contains_filter_test() {
|
||||
AssertCellContent {
|
||||
field_id: multi_select_field.id,
|
||||
row_index: 5,
|
||||
from_field_type: FieldType::MultiSelect,
|
||||
|
||||
expected_content: stringified_expected,
|
||||
},
|
||||
];
|
||||
@ -424,7 +424,7 @@ async fn according_to_select_option_is_not_empty_filter_test() {
|
||||
AssertCellContent {
|
||||
field_id: multi_select_field.id,
|
||||
row_index: 5,
|
||||
from_field_type: FieldType::MultiSelect,
|
||||
|
||||
expected_content: stringified_expected,
|
||||
},
|
||||
];
|
||||
|
@ -35,7 +35,7 @@ async fn row_data_payload_with_empty_hashmap_test() {
|
||||
AssertCellContent {
|
||||
field_id: text_field.id,
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::RichText,
|
||||
|
||||
expected_content: "".to_string(),
|
||||
},
|
||||
];
|
||||
@ -70,7 +70,7 @@ async fn row_data_payload_with_unknown_field_id_test() {
|
||||
AssertCellContent {
|
||||
field_id: text_field.id.clone(),
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::RichText,
|
||||
|
||||
expected_content: "".to_string(),
|
||||
},
|
||||
AssertCellExistence {
|
||||
@ -107,7 +107,7 @@ async fn row_data_payload_with_empty_string_text_data_test() {
|
||||
AssertCellContent {
|
||||
field_id: text_field.id,
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::RichText,
|
||||
|
||||
expected_content: cell_data.to_string(),
|
||||
},
|
||||
];
|
||||
@ -139,7 +139,7 @@ async fn row_data_payload_with_text_data_test() {
|
||||
AssertCellContent {
|
||||
field_id: text_field.id.clone(),
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::RichText,
|
||||
|
||||
expected_content: cell_data.to_string(),
|
||||
},
|
||||
];
|
||||
@ -180,7 +180,7 @@ async fn row_data_payload_with_multi_text_data_test() {
|
||||
AssertCellContent {
|
||||
field_id: text_field.id,
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::RichText,
|
||||
|
||||
expected_content: text_cell_data.to_string(),
|
||||
},
|
||||
AssertCellExistence {
|
||||
@ -191,7 +191,7 @@ async fn row_data_payload_with_multi_text_data_test() {
|
||||
AssertCellContent {
|
||||
field_id: number_field.id,
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::RichText,
|
||||
|
||||
expected_content: "$1,234".to_string(),
|
||||
},
|
||||
AssertCellExistence {
|
||||
@ -202,7 +202,7 @@ async fn row_data_payload_with_multi_text_data_test() {
|
||||
AssertCellContent {
|
||||
field_id: url_field.id,
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::RichText,
|
||||
|
||||
expected_content: url_cell_data.to_string(),
|
||||
},
|
||||
];
|
||||
@ -234,7 +234,7 @@ async fn row_data_payload_with_date_time_test() {
|
||||
AssertCellContent {
|
||||
field_id: date_field.id.clone(),
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::RichText,
|
||||
|
||||
expected_content: "2024/03/15".to_string(),
|
||||
},
|
||||
];
|
||||
@ -296,7 +296,7 @@ async fn row_data_payload_with_checkbox_test() {
|
||||
AssertCellContent {
|
||||
field_id: checkbox_field.id.clone(),
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::Checkbox,
|
||||
|
||||
expected_content: cell_data.to_string(),
|
||||
},
|
||||
];
|
||||
@ -340,7 +340,7 @@ async fn row_data_payload_with_select_option_test() {
|
||||
AssertCellContent {
|
||||
field_id: multi_select_field.id.clone(),
|
||||
row_index: test.row_details.len(),
|
||||
from_field_type: FieldType::MultiSelect,
|
||||
|
||||
expected_content: stringified_cell_data,
|
||||
},
|
||||
];
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::time::Duration;
|
||||
|
||||
use flowy_database2::entities::{CreateRowPayloadPB, FieldType, FilterDataPB, InsertFilterPB};
|
||||
use flowy_database2::services::cell::stringify_cell_data;
|
||||
use flowy_database2::entities::{CreateRowPayloadPB, FilterDataPB, InsertFilterPB};
|
||||
use flowy_database2::services::cell::stringify_cell;
|
||||
use flowy_database2::services::field::{SelectOptionIds, SELECTION_IDS_SEPARATOR};
|
||||
|
||||
use crate::database::database_editor::DatabaseEditorTest;
|
||||
@ -24,7 +24,6 @@ pub enum PreFillRowCellTestScript {
|
||||
AssertCellContent {
|
||||
field_id: String,
|
||||
row_index: usize,
|
||||
from_field_type: FieldType,
|
||||
expected_content: String,
|
||||
},
|
||||
AssertSelectOptionCellStrict {
|
||||
@ -105,11 +104,9 @@ impl DatabasePreFillRowCellTest {
|
||||
PreFillRowCellTestScript::AssertCellContent {
|
||||
field_id,
|
||||
row_index,
|
||||
from_field_type,
|
||||
expected_content,
|
||||
} => {
|
||||
let field = self.editor.get_field(&field_id).unwrap();
|
||||
let field_type = FieldType::from(field.field_type);
|
||||
|
||||
let rows = self.editor.get_rows(&self.view_id).await.unwrap();
|
||||
let row_detail = rows.get(row_index).unwrap();
|
||||
@ -120,7 +117,7 @@ impl DatabasePreFillRowCellTest {
|
||||
.get(&field_id)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
let content = stringify_cell_data(&cell, &from_field_type, &field_type, &field);
|
||||
let content = stringify_cell(&cell, &field);
|
||||
assert_eq!(content, expected_content);
|
||||
},
|
||||
PreFillRowCellTestScript::AssertSelectOptionCellStrict {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use flowy_database2::entities::FieldType;
|
||||
use flowy_database2::services::cell::stringify_cell_data;
|
||||
use flowy_database2::services::cell::stringify_cell;
|
||||
use flowy_database2::services::field::CHECK;
|
||||
use flowy_database2::services::share::csv::CSVFormat;
|
||||
|
||||
@ -67,7 +67,7 @@ async fn export_and_then_import_meta_csv_test() {
|
||||
for (index, row_detail) in rows.iter().enumerate() {
|
||||
if let Some(cell) = row_detail.row.cells.get(&field.id) {
|
||||
let field_type = FieldType::from(field.field_type);
|
||||
let s = stringify_cell_data(cell, &field_type, &field_type, &field);
|
||||
let s = stringify_cell(cell, &field);
|
||||
match &field_type {
|
||||
FieldType::RichText => {
|
||||
if index == 0 {
|
||||
@ -141,7 +141,7 @@ async fn history_database_import_test() {
|
||||
for (index, row_detail) in rows.iter().enumerate() {
|
||||
if let Some(cell) = row_detail.row.cells.get(&field.id) {
|
||||
let field_type = FieldType::from(field.field_type);
|
||||
let s = stringify_cell_data(cell, &field_type, &field_type, &field);
|
||||
let s = stringify_cell(cell, &field);
|
||||
match &field_type {
|
||||
FieldType::RichText => {
|
||||
if index == 0 {
|
||||
|
@ -8,9 +8,9 @@ use futures::stream::StreamExt;
|
||||
use tokio::sync::broadcast::Receiver;
|
||||
|
||||
use flowy_database2::entities::{
|
||||
CreateRowPayloadPB, DeleteSortPayloadPB, FieldType, ReorderSortPayloadPB, UpdateSortPayloadPB,
|
||||
CreateRowPayloadPB, DeleteSortPayloadPB, ReorderSortPayloadPB, UpdateSortPayloadPB,
|
||||
};
|
||||
use flowy_database2::services::cell::stringify_cell_data;
|
||||
use flowy_database2::services::cell::stringify_cell;
|
||||
use flowy_database2::services::database_view::DatabaseViewChanged;
|
||||
use flowy_database2::services::sort::SortCondition;
|
||||
|
||||
@ -119,10 +119,9 @@ impl DatabaseSortTest {
|
||||
let mut cells = vec![];
|
||||
let rows = self.editor.get_rows(&self.view_id).await.unwrap();
|
||||
let field = self.editor.get_field(&field_id).unwrap();
|
||||
let field_type = FieldType::from(field.field_type);
|
||||
for row_detail in rows {
|
||||
if let Some(cell) = row_detail.row.cells.get(&field_id) {
|
||||
let content = stringify_cell_data(cell, &field_type, &field_type, &field);
|
||||
let content = stringify_cell(cell, &field);
|
||||
cells.push(content);
|
||||
} else {
|
||||
cells.push("".to_string());
|
||||
|
Reference in New Issue
Block a user