2022-07-11 17:15:16 +08:00
|
|
|
use crate::grid::cell_test::script::CellScript::*;
|
2023-02-02 23:02:49 +08:00
|
|
|
use crate::grid::cell_test::script::DatabaseCellTest;
|
2022-07-11 17:15:16 +08:00
|
|
|
use crate::grid::field_test::util::make_date_cell_string;
|
2023-01-31 08:28:31 +08:00
|
|
|
use flowy_database::entities::{CellChangesetPB, FieldType};
|
|
|
|
use flowy_database::services::cell::ToCellChangesetString;
|
|
|
|
use flowy_database::services::field::selection_type_option::SelectOptionCellChangeset;
|
|
|
|
use flowy_database::services::field::{ChecklistTypeOptionPB, MultiSelectTypeOptionPB, SingleSelectTypeOptionPB};
|
2022-06-20 10:24:43 +08:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn grid_cell_update() {
|
2023-02-02 23:02:49 +08:00
|
|
|
let mut test = DatabaseCellTest::new().await;
|
2022-06-20 10:24:43 +08:00
|
|
|
let field_revs = &test.field_revs;
|
|
|
|
let row_revs = &test.row_revs;
|
2022-06-29 13:44:15 +08:00
|
|
|
let grid_blocks = &test.block_meta_revs;
|
2022-06-20 10:24:43 +08:00
|
|
|
|
|
|
|
// For the moment, We only have one block to store rows
|
|
|
|
let block_id = &grid_blocks.first().unwrap().block_id;
|
|
|
|
|
|
|
|
let mut scripts = vec![];
|
|
|
|
for (_, row_rev) in row_revs.iter().enumerate() {
|
|
|
|
for field_rev in field_revs {
|
2022-08-19 11:56:47 +08:00
|
|
|
let field_type: FieldType = field_rev.ty.into();
|
2022-07-01 20:32:11 +08:00
|
|
|
let data = match field_type {
|
2022-06-20 10:24:43 +08:00
|
|
|
FieldType::RichText => "".to_string(),
|
|
|
|
FieldType::Number => "123".to_string(),
|
|
|
|
FieldType::DateTime => make_date_cell_string("123"),
|
|
|
|
FieldType::SingleSelect => {
|
2022-07-17 13:38:53 +08:00
|
|
|
let type_option = SingleSelectTypeOptionPB::from(field_rev);
|
2022-12-26 20:28:18 +08:00
|
|
|
SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id)
|
|
|
|
.to_cell_changeset_str()
|
2022-06-20 10:24:43 +08:00
|
|
|
}
|
|
|
|
FieldType::MultiSelect => {
|
2022-08-11 13:04:45 +08:00
|
|
|
let type_option = MultiSelectTypeOptionPB::from(field_rev);
|
2022-12-26 20:28:18 +08:00
|
|
|
SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id)
|
|
|
|
.to_cell_changeset_str()
|
2022-06-20 10:24:43 +08:00
|
|
|
}
|
2022-11-29 22:40:49 +08:00
|
|
|
FieldType::Checklist => {
|
2022-11-29 14:17:43 +08:00
|
|
|
let type_option = ChecklistTypeOptionPB::from(field_rev);
|
2022-12-26 20:28:18 +08:00
|
|
|
SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id)
|
|
|
|
.to_cell_changeset_str()
|
2022-11-29 14:17:43 +08:00
|
|
|
}
|
2022-06-20 10:24:43 +08:00
|
|
|
FieldType::Checkbox => "1".to_string(),
|
|
|
|
FieldType::URL => "1".to_string(),
|
|
|
|
};
|
|
|
|
|
|
|
|
scripts.push(UpdateCell {
|
2022-07-17 14:13:12 +08:00
|
|
|
changeset: CellChangesetPB {
|
2023-01-31 08:28:31 +08:00
|
|
|
database_id: block_id.to_string(),
|
2022-06-20 10:24:43 +08:00
|
|
|
row_id: row_rev.id.clone(),
|
|
|
|
field_id: field_rev.id.clone(),
|
2022-12-21 11:00:08 +08:00
|
|
|
type_cell_data: data,
|
2022-06-20 10:24:43 +08:00
|
|
|
},
|
|
|
|
is_err: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test.run_scripts(scripts).await;
|
|
|
|
}
|
2023-01-05 21:27:21 +08:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn text_cell_date_test() {
|
2023-02-02 23:02:49 +08:00
|
|
|
let test = DatabaseCellTest::new().await;
|
2023-01-05 21:27:21 +08:00
|
|
|
let text_field = test.get_first_field_rev(FieldType::RichText);
|
2023-01-12 07:56:46 +08:00
|
|
|
let cells = test
|
|
|
|
.editor
|
|
|
|
.get_cells_for_field(&test.view_id, &text_field.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2023-01-05 21:27:21 +08:00
|
|
|
|
2023-01-19 13:26:55 +03:30
|
|
|
for (i, cell) in cells.into_iter().enumerate() {
|
|
|
|
let text = cell.into_text_field_cell_data().unwrap();
|
2023-01-05 21:27:21 +08:00
|
|
|
match i {
|
|
|
|
0 => assert_eq!(text.as_str(), "A"),
|
|
|
|
1 => assert_eq!(text.as_str(), ""),
|
|
|
|
2 => assert_eq!(text.as_str(), "C"),
|
|
|
|
3 => assert_eq!(text.as_str(), "DA"),
|
|
|
|
4 => assert_eq!(text.as_str(), "AE"),
|
|
|
|
5 => assert_eq!(text.as_str(), "AE"),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn url_cell_date_test() {
|
2023-02-02 23:02:49 +08:00
|
|
|
let test = DatabaseCellTest::new().await;
|
2023-01-05 21:27:21 +08:00
|
|
|
let url_field = test.get_first_field_rev(FieldType::URL);
|
2023-01-12 07:56:46 +08:00
|
|
|
let cells = test
|
|
|
|
.editor
|
|
|
|
.get_cells_for_field(&test.view_id, &url_field.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2023-01-05 21:27:21 +08:00
|
|
|
|
2023-01-19 13:26:55 +03:30
|
|
|
for (i, cell) in cells.into_iter().enumerate() {
|
|
|
|
let url_cell_data = cell.into_url_field_cell_data().unwrap();
|
2023-01-26 15:40:23 +08:00
|
|
|
if i == 0 {
|
|
|
|
assert_eq!(url_cell_data.url.as_str(), "https://www.appflowy.io/");
|
2023-01-05 21:27:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|