mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Feat/view map database (#1885)
* refactor: rename structs * chore: read database id from view * chore: fix open database error because of create a database view for database id * chore: fix tests * chore: rename datbase id to view id in flutter * refactor: move grid and board to database view folder * refactor: rename functions * refactor: move calender to datbase view folder * refactor: rename app_flowy to appflowy_flutter * chore: reanming * chore: fix freeze gen * chore: remove todos * refactor: view process events * chore: add link database test * chore: just open view if there is opened database
This commit is contained in:
@ -0,0 +1,2 @@
|
||||
mod script;
|
||||
mod test;
|
@ -0,0 +1,70 @@
|
||||
use crate::database::database_editor::DatabaseEditorTest;
|
||||
use flowy_database::entities::CellChangesetPB;
|
||||
|
||||
pub enum CellScript {
|
||||
UpdateCell {
|
||||
changeset: CellChangesetPB,
|
||||
is_err: bool,
|
||||
},
|
||||
}
|
||||
|
||||
pub struct DatabaseCellTest {
|
||||
inner: DatabaseEditorTest,
|
||||
}
|
||||
|
||||
impl DatabaseCellTest {
|
||||
pub async fn new() -> Self {
|
||||
let inner = DatabaseEditorTest::new_grid().await;
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
pub async fn run_scripts(&mut self, scripts: Vec<CellScript>) {
|
||||
for script in scripts {
|
||||
self.run_script(script).await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run_script(&mut self, script: CellScript) {
|
||||
// let grid_manager = self.sdk.grid_manager.clone();
|
||||
// let pool = self.sdk.user_session.db_pool().unwrap();
|
||||
// let rev_manager = self.editor.rev_manager();
|
||||
// let _cache = rev_manager.revision_cache().await;
|
||||
|
||||
match script {
|
||||
CellScript::UpdateCell { changeset, is_err } => {
|
||||
let result = self
|
||||
.editor
|
||||
.update_cell_with_changeset(
|
||||
&changeset.row_id,
|
||||
&changeset.field_id,
|
||||
changeset.type_cell_data,
|
||||
)
|
||||
.await;
|
||||
if is_err {
|
||||
assert!(result.is_err())
|
||||
} else {
|
||||
result.unwrap();
|
||||
}
|
||||
}, // CellScript::AssertGridRevisionPad => {
|
||||
// sleep(Duration::from_millis(2 * REVISION_WRITE_INTERVAL_IN_MILLIS)).await;
|
||||
// let mut grid_rev_manager = grid_manager.make_grid_rev_manager(&self.grid_id, pool.clone()).unwrap();
|
||||
// let grid_pad = grid_rev_manager.load::<GridPadBuilder>(None).await.unwrap();
|
||||
// println!("{}", grid_pad.delta_str());
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for DatabaseCellTest {
|
||||
type Target = DatabaseEditorTest;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DerefMut for DatabaseCellTest {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
use crate::database::cell_test::script::CellScript::*;
|
||||
use crate::database::cell_test::script::DatabaseCellTest;
|
||||
use crate::database::field_test::util::make_date_cell_string;
|
||||
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,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn grid_cell_update() {
|
||||
let mut test = DatabaseCellTest::new().await;
|
||||
let field_revs = &test.field_revs;
|
||||
let row_revs = &test.row_revs;
|
||||
let grid_blocks = &test.block_meta_revs;
|
||||
|
||||
// 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 {
|
||||
let field_type: FieldType = field_rev.ty.into();
|
||||
let data = match field_type {
|
||||
FieldType::RichText => "".to_string(),
|
||||
FieldType::Number => "123".to_string(),
|
||||
FieldType::DateTime => make_date_cell_string("123"),
|
||||
FieldType::SingleSelect => {
|
||||
let type_option = SingleSelectTypeOptionPB::from(field_rev);
|
||||
SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id)
|
||||
.to_cell_changeset_str()
|
||||
},
|
||||
FieldType::MultiSelect => {
|
||||
let type_option = MultiSelectTypeOptionPB::from(field_rev);
|
||||
SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id)
|
||||
.to_cell_changeset_str()
|
||||
},
|
||||
FieldType::Checklist => {
|
||||
let type_option = ChecklistTypeOptionPB::from(field_rev);
|
||||
SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id)
|
||||
.to_cell_changeset_str()
|
||||
},
|
||||
FieldType::Checkbox => "1".to_string(),
|
||||
FieldType::URL => "1".to_string(),
|
||||
};
|
||||
|
||||
scripts.push(UpdateCell {
|
||||
changeset: CellChangesetPB {
|
||||
view_id: block_id.to_string(),
|
||||
row_id: row_rev.id.clone(),
|
||||
field_id: field_rev.id.clone(),
|
||||
type_cell_data: data,
|
||||
},
|
||||
is_err: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn text_cell_date_test() {
|
||||
let test = DatabaseCellTest::new().await;
|
||||
let text_field = test.get_first_field_rev(FieldType::RichText);
|
||||
let cells = test
|
||||
.editor
|
||||
.get_cells_for_field(&test.view_id, &text_field.id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
for (i, cell) in cells.into_iter().enumerate() {
|
||||
let text = cell.into_text_field_cell_data().unwrap();
|
||||
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() {
|
||||
let test = DatabaseCellTest::new().await;
|
||||
let url_field = test.get_first_field_rev(FieldType::URL);
|
||||
let cells = test
|
||||
.editor
|
||||
.get_cells_for_field(&test.view_id, &url_field.id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
for (i, cell) in cells.into_iter().enumerate() {
|
||||
let url_cell_data = cell.into_url_field_cell_data().unwrap();
|
||||
if i == 0 {
|
||||
assert_eq!(url_cell_data.url.as_str(), "https://www.appflowy.io/");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user