|
@@ -1,5 +1,7 @@
|
|
|
use crate::grid::grid_editor::GridEditorTest;
|
|
|
-use flowy_grid::entities::{GroupPB, MoveRowParams, RowPB};
|
|
|
+use flowy_grid::entities::{CreateRowParams, FieldType, GridLayout, GroupPB, MoveRowParams, RowPB};
|
|
|
+use flowy_grid::services::cell::insert_select_option_cell;
|
|
|
+use flowy_grid_data_model::revision::RowChangeset;
|
|
|
|
|
|
pub enum GroupScript {
|
|
|
AssertGroup {
|
|
@@ -7,7 +9,7 @@ pub enum GroupScript {
|
|
|
row_count: usize,
|
|
|
},
|
|
|
AssertGroupCount(usize),
|
|
|
- AssertGroupRow {
|
|
|
+ AssertRow {
|
|
|
group_index: usize,
|
|
|
row_index: usize,
|
|
|
row: RowPB,
|
|
@@ -18,6 +20,18 @@ pub enum GroupScript {
|
|
|
to_group_index: usize,
|
|
|
to_row_index: usize,
|
|
|
},
|
|
|
+ CreateRow {
|
|
|
+ group_index: usize,
|
|
|
+ },
|
|
|
+ DeleteRow {
|
|
|
+ group_index: usize,
|
|
|
+ row_index: usize,
|
|
|
+ },
|
|
|
+ UpdateRow {
|
|
|
+ from_group_index: usize,
|
|
|
+ row_index: usize,
|
|
|
+ to_group_index: usize,
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
pub struct GridGroupTest {
|
|
@@ -62,7 +76,7 @@ impl GridGroupTest {
|
|
|
|
|
|
self.editor.move_row(params).await.unwrap();
|
|
|
}
|
|
|
- GroupScript::AssertGroupRow {
|
|
|
+ GroupScript::AssertRow {
|
|
|
group_index,
|
|
|
row_index,
|
|
|
row,
|
|
@@ -73,6 +87,44 @@ impl GridGroupTest {
|
|
|
|
|
|
assert_eq!(row.id, compare_row.id);
|
|
|
}
|
|
|
+ GroupScript::CreateRow { group_index } => {
|
|
|
+ //
|
|
|
+ let group = self.group_at_index(group_index).await;
|
|
|
+ let params = CreateRowParams {
|
|
|
+ grid_id: self.editor.grid_id.clone(),
|
|
|
+ start_row_id: None,
|
|
|
+ group_id: Some(group.group_id.clone()),
|
|
|
+ layout: GridLayout::Board,
|
|
|
+ };
|
|
|
+ let _ = self.editor.create_row(params).await.unwrap();
|
|
|
+ }
|
|
|
+ GroupScript::DeleteRow { group_index, row_index } => {
|
|
|
+ let row = self.row_at_index(group_index, row_index).await;
|
|
|
+ self.editor.delete_row(&row.id).await.unwrap();
|
|
|
+ }
|
|
|
+ GroupScript::UpdateRow {
|
|
|
+ from_group_index,
|
|
|
+ row_index,
|
|
|
+ to_group_index,
|
|
|
+ } => {
|
|
|
+ let from_group = self.group_at_index(from_group_index).await;
|
|
|
+ let to_group = self.group_at_index(to_group_index).await;
|
|
|
+ let field_id = from_group.field_id;
|
|
|
+ let field_rev = self.editor.get_field_rev(&field_id).await.unwrap();
|
|
|
+ let field_type: FieldType = field_rev.ty.into();
|
|
|
+ let cell_rev = match field_type {
|
|
|
+ FieldType::SingleSelect => insert_select_option_cell(to_group.group_id.clone(), &field_rev),
|
|
|
+ FieldType::MultiSelect => insert_select_option_cell(to_group.group_id.clone(), &field_rev),
|
|
|
+ _ => {
|
|
|
+ panic!("Unsupported group field type");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ let row_id = self.row_at_index(from_group_index, row_index).await.id;
|
|
|
+ let mut row_changeset = RowChangeset::new(row_id);
|
|
|
+ row_changeset.cell_by_field_id.insert(field_id, cell_rev);
|
|
|
+ self.editor.update_row(row_changeset).await.unwrap();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -80,6 +132,11 @@ impl GridGroupTest {
|
|
|
let groups = self.editor.load_groups().await.unwrap().items;
|
|
|
groups.get(index).unwrap().clone()
|
|
|
}
|
|
|
+
|
|
|
+ pub async fn row_at_index(&self, group_index: usize, row_index: usize) -> RowPB {
|
|
|
+ let groups = self.group_at_index(group_index).await;
|
|
|
+ groups.rows.get(row_index).unwrap().clone()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
impl std::ops::Deref for GridGroupTest {
|