mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: reload group when group by new field
This commit is contained in:
@ -195,6 +195,8 @@ fn make_test_grid() -> BuildGridContext {
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(0))
|
||||
}
|
||||
FieldType::MultiSelect => row_builder
|
||||
.insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
|
||||
FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
@ -209,6 +211,8 @@ fn make_test_grid() -> BuildGridContext {
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(0))
|
||||
}
|
||||
FieldType::MultiSelect => row_builder
|
||||
.insert_multi_select_cell(|mut options| vec![options.remove(0), options.remove(0)]),
|
||||
FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
@ -223,6 +227,9 @@ fn make_test_grid() -> BuildGridContext {
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(1))
|
||||
}
|
||||
FieldType::MultiSelect => {
|
||||
row_builder.insert_multi_select_cell(|mut options| vec![options.remove(0)])
|
||||
}
|
||||
FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
|
@ -1,13 +1,13 @@
|
||||
use crate::grid::grid_editor::GridEditorTest;
|
||||
use flowy_grid::entities::{
|
||||
CreateRowParams, FieldChangesetParams, FieldType, GridLayout, GroupPB, MoveGroupParams, MoveGroupRowParams, RowPB,
|
||||
CreateRowParams, FieldType, GridLayout, GroupPB, MoveGroupParams, MoveGroupRowParams, RowPB,
|
||||
};
|
||||
use flowy_grid::services::cell::{delete_select_option_cell, insert_select_option_cell};
|
||||
use flowy_grid::services::field::{select_option_operation, SelectOptionOperation};
|
||||
use flowy_grid::services::field::{
|
||||
edit_single_select_type_option, SelectOptionOperation, SelectOptionPB, SingleSelectTypeOptionPB,
|
||||
};
|
||||
use flowy_grid_data_model::revision::{FieldRevision, RowChangeset};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::time::interval;
|
||||
|
||||
pub enum GroupScript {
|
||||
AssertGroupRowCount {
|
||||
@ -46,10 +46,10 @@ pub enum GroupScript {
|
||||
from_group_index: usize,
|
||||
to_group_index: usize,
|
||||
},
|
||||
UpdateField {
|
||||
changeset: FieldChangesetParams,
|
||||
UpdateSingleSelectOption {
|
||||
inserted_options: Vec<SelectOptionPB>,
|
||||
},
|
||||
GroupField {
|
||||
GroupByField {
|
||||
field_id: String,
|
||||
},
|
||||
}
|
||||
@ -179,12 +179,15 @@ impl GridGroupTest {
|
||||
assert_eq!(group.group_id, group_pb.group_id);
|
||||
assert_eq!(group.desc, group_pb.desc);
|
||||
}
|
||||
GroupScript::UpdateField { changeset } => {
|
||||
self.editor.update_field(changeset).await.unwrap();
|
||||
let mut interval = interval(Duration::from_millis(130));
|
||||
interval.tick().await;
|
||||
GroupScript::UpdateSingleSelectOption { inserted_options } => {
|
||||
self.edit_single_select_type_option(|type_option| {
|
||||
for inserted_option in inserted_options {
|
||||
type_option.insert_option(inserted_option);
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
GroupScript::GroupField { field_id } => {
|
||||
GroupScript::GroupByField { field_id } => {
|
||||
self.editor.group_field(&field_id).await.unwrap();
|
||||
}
|
||||
}
|
||||
@ -200,6 +203,7 @@ impl GridGroupTest {
|
||||
groups.rows.get(row_index).unwrap().clone()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn get_multi_select_field(&self) -> Arc<FieldRevision> {
|
||||
let field = self
|
||||
.inner
|
||||
@ -211,7 +215,7 @@ impl GridGroupTest {
|
||||
})
|
||||
.unwrap()
|
||||
.clone();
|
||||
return field;
|
||||
field
|
||||
}
|
||||
|
||||
pub async fn get_single_select_field(&self) -> Arc<FieldRevision> {
|
||||
@ -226,14 +230,11 @@ impl GridGroupTest {
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub async fn edit_single_select_type_option(&self, f: impl FnOnce(Box<dyn SelectOptionOperation>)) {
|
||||
pub async fn edit_single_select_type_option(&self, action: impl FnOnce(&mut SingleSelectTypeOptionPB)) {
|
||||
let single_select = self.get_single_select_field().await;
|
||||
let mut field_rev = self.editor.get_field_rev(&single_select.id).await.unwrap();
|
||||
let mut_field_rev = Arc::make_mut(&mut field_rev);
|
||||
let mut type_option = select_option_operation(mut_field_rev)?;
|
||||
f(type_option);
|
||||
mut_field_rev.insert_type_option(&*type_option);
|
||||
let _ = self.editor.replace_field(field_rev).await?;
|
||||
edit_single_select_type_option(&single_select.id, self.editor.clone(), action)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::grid::group_test::script::GridGroupTest;
|
||||
use crate::grid::group_test::script::GroupScript::*;
|
||||
use flowy_grid::entities::FieldChangesetParams;
|
||||
|
||||
use flowy_grid::services::field::SelectOptionPB;
|
||||
|
||||
#[tokio::test]
|
||||
async fn group_init_test() {
|
||||
@ -370,32 +371,41 @@ async fn group_move_group_test() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn group_update_field_test() {
|
||||
async fn group_insert_single_select_option_test() {
|
||||
let mut test = GridGroupTest::new().await;
|
||||
let group = test.group_at_index(0).await;
|
||||
let changeset = FieldChangesetParams {
|
||||
field_id: group.field_id.clone(),
|
||||
grid_id: test.grid_id.clone(),
|
||||
name: Some("ABC".to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// group.desc = "ABC".to_string();
|
||||
let new_option_name = "New option";
|
||||
let scripts = vec![
|
||||
UpdateField { changeset },
|
||||
AssertGroup {
|
||||
group_index: 0,
|
||||
expected_group: group,
|
||||
AssertGroupCount(4),
|
||||
UpdateSingleSelectOption {
|
||||
inserted_options: vec![SelectOptionPB::new(new_option_name)],
|
||||
},
|
||||
AssertGroupCount(5),
|
||||
];
|
||||
test.run_scripts(scripts).await;
|
||||
|
||||
// the group at index 4 is the default_group, so the new insert group will be the
|
||||
// index 3.
|
||||
let group_3 = test.group_at_index(3).await;
|
||||
assert_eq!(group_3.desc, new_option_name);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn group_group_by_other_field() {
|
||||
let mut test = GridGroupTest::new().await;
|
||||
let multi_select_field = test.get_multi_select_field().await;
|
||||
let scripts = vec![
|
||||
GroupByField {
|
||||
field_id: multi_select_field.id.clone(),
|
||||
},
|
||||
AssertGroupRowCount {
|
||||
group_index: 0,
|
||||
row_count: 3,
|
||||
},
|
||||
AssertGroupRowCount {
|
||||
group_index: 1,
|
||||
row_count: 2,
|
||||
},
|
||||
AssertGroupCount(4),
|
||||
];
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
// #[tokio::test]
|
||||
// async fn group_multi_select_field_test() {
|
||||
// let mut test = GridGroupTest::new().await;
|
||||
// let multi_select_field = test.get_multi_select_field().await;
|
||||
//
|
||||
// let scripts = vec![];
|
||||
// test.run_scripts(scripts).await;
|
||||
// }
|
||||
|
Reference in New Issue
Block a user