mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-10 02:26:08 +00:00

* chore: create orphan view handler * feat: save icon url and cover url in view * feat: implement emoji picker UI * chore: config ui * chore: config ui again * chore: replace RowPB with RowMetaPB to exposing more row information * fix: compile error * feat: show emoji in row * chore: update * test: insert emoji test * test: add update emoji test * test: add remove emoji test * test: add create field tests * test: add create row and delete row integration tests * test: add create row from row menu * test: document in row detail page * test: delete, duplicate row in row detail page * test: check the row count displayed in grid page * test: rename existing field in grid page * test: update field type of exisiting field in grid page * test: delete field test * test: add duplicate field test * test: add hide field test * test: add edit text cell test * test: add insert text to text cell test * test: add edit number cell test * test: add edit multiple number cells * test: add edit checkbox cell test * feat: integrate editor into database row * test: add edit create time and last edit time cell test * test: add edit date cell by selecting a date test * chore: remove unused code * chore: update checklist bg color * test: add update database layout test --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
154 lines
4.1 KiB
Rust
154 lines
4.1 KiB
Rust
use collab_database::fields::{Field, TypeOptionData};
|
|
|
|
use flowy_database2::entities::{CreateFieldParams, FieldChangesetParams, FieldType};
|
|
use flowy_database2::services::cell::stringify_cell_data;
|
|
|
|
use crate::database::database_editor::DatabaseEditorTest;
|
|
|
|
pub enum FieldScript {
|
|
CreateField {
|
|
params: CreateFieldParams,
|
|
},
|
|
UpdateField {
|
|
changeset: FieldChangesetParams,
|
|
},
|
|
DeleteField {
|
|
field: Field,
|
|
},
|
|
SwitchToField {
|
|
field_id: String,
|
|
new_field_type: FieldType,
|
|
},
|
|
UpdateTypeOption {
|
|
field_id: String,
|
|
type_option: TypeOptionData,
|
|
},
|
|
AssertFieldCount(usize),
|
|
AssertFieldTypeOptionEqual {
|
|
field_index: usize,
|
|
expected_type_option_data: TypeOptionData,
|
|
},
|
|
AssertCellContent {
|
|
field_id: String,
|
|
row_index: usize,
|
|
from_field_type: FieldType,
|
|
expected_content: String,
|
|
},
|
|
}
|
|
|
|
pub struct DatabaseFieldTest {
|
|
inner: DatabaseEditorTest,
|
|
}
|
|
|
|
impl DatabaseFieldTest {
|
|
pub async fn new() -> Self {
|
|
let editor_test = DatabaseEditorTest::new_grid().await;
|
|
Self { inner: editor_test }
|
|
}
|
|
|
|
pub fn view_id(&self) -> String {
|
|
self.view_id.clone()
|
|
}
|
|
|
|
pub fn field_count(&self) -> usize {
|
|
self.field_count
|
|
}
|
|
|
|
pub async fn run_scripts(&mut self, scripts: Vec<FieldScript>) {
|
|
for script in scripts {
|
|
self.run_script(script).await;
|
|
}
|
|
}
|
|
|
|
pub async fn run_script(&mut self, script: FieldScript) {
|
|
match script {
|
|
FieldScript::CreateField { params } => {
|
|
self.field_count += 1;
|
|
self
|
|
.editor
|
|
.create_field_with_type_option(&self.view_id, ¶ms.field_type, params.type_option_data)
|
|
.await;
|
|
let fields = self.editor.get_fields(&self.view_id, None);
|
|
assert_eq!(self.field_count, fields.len());
|
|
},
|
|
FieldScript::UpdateField { changeset: change } => {
|
|
self.editor.update_field(change).await.unwrap();
|
|
},
|
|
FieldScript::DeleteField { field } => {
|
|
if self.editor.get_field(&field.id).is_some() {
|
|
self.field_count -= 1;
|
|
}
|
|
|
|
self.editor.delete_field(&field.id).await.unwrap();
|
|
let fields = self.editor.get_fields(&self.view_id, None);
|
|
assert_eq!(self.field_count, fields.len());
|
|
},
|
|
FieldScript::SwitchToField {
|
|
field_id,
|
|
new_field_type,
|
|
} => {
|
|
//
|
|
self
|
|
.editor
|
|
.switch_to_field_type(&field_id, &new_field_type)
|
|
.await
|
|
.unwrap();
|
|
},
|
|
FieldScript::UpdateTypeOption {
|
|
field_id,
|
|
type_option,
|
|
} => {
|
|
//
|
|
let old_field = self.editor.get_field(&field_id).unwrap();
|
|
self
|
|
.editor
|
|
.update_field_type_option(&self.view_id, &field_id, type_option, old_field)
|
|
.await
|
|
.unwrap();
|
|
},
|
|
FieldScript::AssertFieldCount(count) => {
|
|
assert_eq!(self.get_fields().len(), count);
|
|
},
|
|
FieldScript::AssertFieldTypeOptionEqual {
|
|
field_index,
|
|
expected_type_option_data,
|
|
} => {
|
|
let fields = self.get_fields();
|
|
let field = &fields[field_index];
|
|
let type_option_data = field.get_any_type_option(field.field_type).unwrap();
|
|
assert_eq!(type_option_data, expected_type_option_data);
|
|
},
|
|
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);
|
|
assert_eq!(content, expected_content);
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::ops::Deref for DatabaseFieldTest {
|
|
type Target = DatabaseEditorTest;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.inner
|
|
}
|
|
}
|
|
|
|
impl std::ops::DerefMut for DatabaseFieldTest {
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
&mut self.inner
|
|
}
|
|
}
|