mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add 5 rows in test grid
This commit is contained in:
parent
d02acbae6e
commit
ab80e9b0ed
@ -1,3 +1,4 @@
|
||||
#![allow(clippy::module_inception)]
|
||||
mod checkbox_tests;
|
||||
mod checkbox_type_option;
|
||||
mod checkbox_type_option_entities;
|
||||
|
@ -1,3 +1,4 @@
|
||||
#![allow(clippy::module_inception)]
|
||||
mod date_tests;
|
||||
mod date_type_option;
|
||||
mod date_type_option_entities;
|
||||
|
@ -1,2 +1,3 @@
|
||||
#![allow(clippy::module_inception)]
|
||||
mod text_type_option;
|
||||
pub use text_type_option::*;
|
||||
|
@ -1,3 +1,4 @@
|
||||
#![allow(clippy::module_inception)]
|
||||
mod url_tests;
|
||||
mod url_type_option;
|
||||
mod url_type_option_entities;
|
||||
|
@ -270,14 +270,10 @@ impl GridRevisionEditor {
|
||||
|
||||
pub async fn create_row(&self, start_row_id: Option<String>) -> FlowyResult<RowInfo> {
|
||||
let field_revs = self.grid_pad.read().await.get_field_revs(None)?;
|
||||
let field_revs_ref = field_revs
|
||||
.iter()
|
||||
.map(|field_rev| field_rev.as_ref())
|
||||
.collect::<Vec<&FieldRevision>>();
|
||||
let block_id = self.block_id().await?;
|
||||
|
||||
// insert empty row below the row whose id is upper_row_id
|
||||
let row_rev = RowRevisionBuilder::new(&field_revs_ref).build(&block_id);
|
||||
let row_rev = RowRevisionBuilder::new(&field_revs).build(&block_id);
|
||||
let row_order = RowInfo::from(&row_rev);
|
||||
|
||||
// insert the row
|
||||
@ -556,7 +552,7 @@ impl GridRevisionEditor {
|
||||
drop(grid_pad);
|
||||
|
||||
Ok(BuildGridContext {
|
||||
field_revs: duplicated_fields,
|
||||
field_revs: duplicated_fields.into_iter().map(Arc::new).collect(),
|
||||
blocks: duplicated_blocks,
|
||||
blocks_meta_data,
|
||||
})
|
||||
|
@ -4,18 +4,19 @@ use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_grid_data_model::revision::{gen_row_id, CellRevision, FieldRevision, RowRevision, DEFAULT_ROW_HEIGHT};
|
||||
use indexmap::IndexMap;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct RowRevisionBuilder<'a> {
|
||||
field_rev_map: HashMap<&'a String, &'a FieldRevision>,
|
||||
field_rev_map: HashMap<&'a String, Arc<FieldRevision>>,
|
||||
payload: CreateRowRevisionPayload,
|
||||
}
|
||||
|
||||
impl<'a> RowRevisionBuilder<'a> {
|
||||
pub fn new(fields: &'a [&'a FieldRevision]) -> Self {
|
||||
pub fn new(fields: &'a [Arc<FieldRevision>]) -> Self {
|
||||
let field_rev_map = fields
|
||||
.iter()
|
||||
.map(|field| (&field.id, *field))
|
||||
.collect::<HashMap<&String, &'a FieldRevision>>();
|
||||
.map(|field| (&field.id, field.clone()))
|
||||
.collect::<HashMap<&String, Arc<FieldRevision>>>();
|
||||
|
||||
let payload = CreateRowRevisionPayload {
|
||||
row_id: gen_row_id(),
|
||||
|
@ -79,8 +79,8 @@ async fn grid_row_add_cells_test() {
|
||||
|options| options,
|
||||
&vec![GOOGLE, FACEBOOK, TWITTER].join(SELECTION_IDS_SEPARATOR),
|
||||
);
|
||||
|
||||
test.run_scripts(builder.build()).await;
|
||||
let scripts = builder.build();
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@ -89,7 +89,8 @@ async fn grid_row_insert_number_test() {
|
||||
for (val, expected) in &[("1647251762", "2022/03/14"), ("2022/03/14", ""), ("", "")] {
|
||||
let mut builder = CreateRowScriptBuilder::new(&test);
|
||||
builder.insert(FieldType::DateTime, val, expected);
|
||||
test.run_scripts(builder.build()).await;
|
||||
let scripts = builder.build();
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +106,8 @@ async fn grid_row_insert_date_test() {
|
||||
] {
|
||||
let mut builder = CreateRowScriptBuilder::new(&test);
|
||||
builder.insert(FieldType::Number, val, expected);
|
||||
test.run_scripts(builder.build()).await;
|
||||
let scripts = builder.build();
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
}
|
||||
#[tokio::test]
|
||||
@ -113,7 +115,8 @@ async fn grid_row_insert_single_select_test() {
|
||||
let mut test = GridRowTest::new().await;
|
||||
let mut builder = CreateRowScriptBuilder::new(&test);
|
||||
builder.insert_single_select_cell(|mut options| options.pop().unwrap(), PAUSED);
|
||||
test.run_scripts(builder.build()).await;
|
||||
let scripts = builder.build();
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@ -127,6 +130,6 @@ async fn grid_row_insert_multi_select_test() {
|
||||
},
|
||||
&vec![FACEBOOK, TWITTER].join(SELECTION_IDS_SEPARATOR),
|
||||
);
|
||||
|
||||
test.run_scripts(builder.build()).await;
|
||||
let scripts = builder.build();
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
@ -2,13 +2,9 @@ use crate::grid::block_test::script::RowScript::{AssertCell, CreateRow};
|
||||
use crate::grid::block_test::util::GridRowTestBuilder;
|
||||
use crate::grid::grid_editor::GridEditorTest;
|
||||
use flowy_grid::entities::{CellIdentifier, FieldType, RowInfo};
|
||||
use flowy_grid::services::field::{
|
||||
CheckboxCellDataParser, DateCellDataParser, MultiSelectTypeOption, NumberCellDataParser, NumberTypeOption,
|
||||
SelectOption, SelectOptionCellDataParser, SelectOptionIdsParser, SingleSelectTypeOption, TextCellDataParser,
|
||||
URLCellDataParser, SELECTION_IDS_SEPARATOR,
|
||||
};
|
||||
use flowy_grid::services::field::*;
|
||||
use flowy_grid_data_model::revision::{
|
||||
FieldRevision, GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision,
|
||||
GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@ -74,19 +70,7 @@ impl GridRowTest {
|
||||
}
|
||||
|
||||
pub fn row_builder(&self) -> GridRowTestBuilder {
|
||||
let field_revs_ref = self
|
||||
.field_revs
|
||||
.iter()
|
||||
.map(|field_rev| field_rev.as_ref())
|
||||
.collect::<Vec<&FieldRevision>>();
|
||||
GridRowTestBuilder::new(
|
||||
self.block_id(),
|
||||
&self
|
||||
.field_revs
|
||||
.iter()
|
||||
.map(|field_rev| field_rev.as_ref())
|
||||
.collect::<Vec<&FieldRevision>>(),
|
||||
)
|
||||
GridRowTestBuilder::new(self.block_id(), &self.field_revs)
|
||||
}
|
||||
|
||||
pub async fn run_script(&mut self, script: RowScript) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
use flowy_grid::entities::FieldType;
|
||||
use std::sync::Arc;
|
||||
|
||||
use flowy_grid::services::field::{
|
||||
DateCellChangeset, MultiSelectTypeOption, SelectOption, SingleSelectTypeOption, SELECTION_IDS_SEPARATOR,
|
||||
@ -10,12 +11,12 @@ use strum::EnumCount;
|
||||
|
||||
pub struct GridRowTestBuilder<'a> {
|
||||
block_id: String,
|
||||
field_revs: &'a [&'a FieldRevision],
|
||||
field_revs: &'a [Arc<FieldRevision>],
|
||||
inner_builder: RowRevisionBuilder<'a>,
|
||||
}
|
||||
|
||||
impl<'a> GridRowTestBuilder<'a> {
|
||||
pub fn new(block_id: &str, field_revs: &'a [&'a FieldRevision]) -> Self {
|
||||
pub fn new(block_id: &str, field_revs: &'a [Arc<FieldRevision>]) -> Self {
|
||||
assert_eq!(field_revs.len(), FieldType::COUNT);
|
||||
let inner_builder = RowRevisionBuilder::new(field_revs);
|
||||
Self {
|
||||
@ -68,16 +69,15 @@ impl<'a> GridRowTestBuilder<'a> {
|
||||
url_field.id.clone()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn insert_single_select_cell<F>(&mut self, f: F) -> String
|
||||
where
|
||||
F: Fn(&Vec<SelectOption>) -> &SelectOption,
|
||||
F: Fn(Vec<SelectOption>) -> SelectOption,
|
||||
{
|
||||
let single_select_field = self.field_rev_with_type(&FieldType::SingleSelect);
|
||||
let type_option = SingleSelectTypeOption::from(&single_select_field);
|
||||
let option = f(&type_option.options);
|
||||
let option = f(type_option.options);
|
||||
self.inner_builder
|
||||
.insert_select_option_cell(&single_select_field.id, option.id.clone())
|
||||
.insert_select_option_cell(&single_select_field.id, option.id)
|
||||
.unwrap();
|
||||
|
||||
single_select_field.id.clone()
|
||||
@ -85,11 +85,11 @@ impl<'a> GridRowTestBuilder<'a> {
|
||||
|
||||
pub fn insert_multi_select_cell<F>(&mut self, f: F) -> String
|
||||
where
|
||||
F: Fn(&Vec<SelectOption>) -> &Vec<SelectOption>,
|
||||
F: Fn(Vec<SelectOption>) -> Vec<SelectOption>,
|
||||
{
|
||||
let multi_select_field = self.field_rev_with_type(&FieldType::MultiSelect);
|
||||
let type_option = MultiSelectTypeOption::from(&multi_select_field);
|
||||
let options = f(&type_option.options);
|
||||
let options = f(type_option.options);
|
||||
let ops_ids = options
|
||||
.iter()
|
||||
.map(|option| option.id.clone())
|
||||
|
@ -1,6 +1,7 @@
|
||||
#![allow(clippy::all)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
use crate::grid::block_test::util::GridRowTestBuilder;
|
||||
use bytes::Bytes;
|
||||
use flowy_grid::entities::*;
|
||||
use flowy_grid::services::field::SelectOption;
|
||||
@ -158,7 +159,7 @@ fn make_test_grid() -> BuildGridContext {
|
||||
FieldType::Checkbox => {
|
||||
// Checkbox
|
||||
let checkbox = CheckboxTypeOptionBuilder::default();
|
||||
let checkbox_field = FieldBuilder::new(checkbox).name("is done").visibility(true).build();
|
||||
let checkbox_field = FieldBuilder::new(checkbox).name("is urgent").visibility(true).build();
|
||||
grid_builder.add_field(checkbox_field);
|
||||
}
|
||||
FieldType::URL => {
|
||||
@ -171,24 +172,87 @@ fn make_test_grid() -> BuildGridContext {
|
||||
}
|
||||
|
||||
// We have many assumptions base on the number of the rows, so do not change the number of the loop.
|
||||
for _i in 0..10 {
|
||||
for field_type in FieldType::iter() {
|
||||
let field_type: FieldType = field_type;
|
||||
// let mut row_builder = RowRevisionBuilder::new()
|
||||
match field_type {
|
||||
FieldType::RichText => {}
|
||||
FieldType::Number => {}
|
||||
FieldType::DateTime => {}
|
||||
FieldType::SingleSelect => {}
|
||||
FieldType::MultiSelect => {}
|
||||
FieldType::Checkbox => {}
|
||||
FieldType::URL => {}
|
||||
for i in 0..5 {
|
||||
let block_id = grid_builder.block_id().to_owned();
|
||||
let field_revs = grid_builder.field_revs();
|
||||
let mut row_builder = GridRowTestBuilder::new(&block_id, field_revs);
|
||||
match i {
|
||||
0 => {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("A"),
|
||||
FieldType::Number => row_builder.insert_number_cell("1"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(0))
|
||||
}
|
||||
FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("B"),
|
||||
FieldType::Number => row_builder.insert_number_cell("2"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(0))
|
||||
}
|
||||
FieldType::Checkbox => row_builder.insert_checkbox_cell("true"),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
}
|
||||
2 => {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("C"),
|
||||
FieldType::Number => row_builder.insert_number_cell("3"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(1))
|
||||
}
|
||||
FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
}
|
||||
3 => {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("D"),
|
||||
FieldType::Number => row_builder.insert_number_cell("4"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(1))
|
||||
}
|
||||
FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
}
|
||||
4 => {
|
||||
for field_type in FieldType::iter() {
|
||||
match field_type {
|
||||
FieldType::RichText => row_builder.insert_text_cell("E"),
|
||||
FieldType::Number => row_builder.insert_number_cell("5"),
|
||||
FieldType::DateTime => row_builder.insert_date_cell("1647251762"),
|
||||
FieldType::SingleSelect => {
|
||||
row_builder.insert_single_select_cell(|mut options| options.remove(2))
|
||||
}
|
||||
|
||||
FieldType::Checkbox => row_builder.insert_checkbox_cell("false"),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let row_rev = row_builder.build();
|
||||
grid_builder.add_row(row_rev);
|
||||
}
|
||||
// assert_eq!(row_revs.len(), 10);
|
||||
// .add_empty_row()
|
||||
// .add_empty_row()
|
||||
// .add_empty_row()
|
||||
grid_builder.build()
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ impl GridRevision {
|
||||
pub fn from_build_context(grid_id: &str, context: BuildGridContext) -> Self {
|
||||
Self {
|
||||
grid_id: grid_id.to_owned(),
|
||||
fields: context.field_revs.into_iter().map(Arc::new).collect(),
|
||||
fields: context.field_revs,
|
||||
blocks: context.blocks.into_iter().map(Arc::new).collect(),
|
||||
setting: Default::default(),
|
||||
}
|
||||
@ -245,7 +245,7 @@ impl CellRevision {
|
||||
|
||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||
pub struct BuildGridContext {
|
||||
pub field_revs: Vec<FieldRevision>,
|
||||
pub field_revs: Vec<Arc<FieldRevision>>,
|
||||
pub blocks: Vec<GridBlockMetaRevision>,
|
||||
pub blocks_meta_data: Vec<GridBlockRevision>,
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ impl GridBuilder {
|
||||
Self::default()
|
||||
}
|
||||
pub fn add_field(&mut self, field: FieldRevision) {
|
||||
self.build_context.field_revs.push(field);
|
||||
self.build_context.field_revs.push(Arc::new(field));
|
||||
}
|
||||
|
||||
pub fn add_row(&mut self, row_rev: RowRevision) {
|
||||
@ -41,13 +41,17 @@ impl GridBuilder {
|
||||
}
|
||||
|
||||
pub fn add_empty_row(&mut self) {
|
||||
let row = RowRevision::new(&self.build_context.blocks.first().unwrap().block_id);
|
||||
let row = RowRevision::new(self.block_id());
|
||||
self.add_row(row);
|
||||
}
|
||||
|
||||
// pub fn field_revs(&self) -> Vec<FieldRevision> {
|
||||
// self.build_context.field_revs
|
||||
// }
|
||||
pub fn field_revs(&self) -> &Vec<Arc<FieldRevision>> {
|
||||
&self.build_context.field_revs
|
||||
}
|
||||
|
||||
pub fn block_id(&self) -> &str {
|
||||
&self.build_context.blocks.first().unwrap().block_id
|
||||
}
|
||||
|
||||
pub fn build(self) -> BuildGridContext {
|
||||
self.build_context
|
||||
|
Loading…
Reference in New Issue
Block a user