mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add more test
This commit is contained in:
parent
3a7c3815b0
commit
da485c6df9
@ -19,7 +19,6 @@ use flowy_database::kv::KV;
|
||||
use flowy_folder_data_model::revision::{gen_view_id, ViewRevision};
|
||||
use flowy_sync::entities::text_block::TextBlockIdPB;
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use lib_infra::util::timestamp;
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
|
||||
const LATEST_VIEW_ID: &str = "latest_view_id";
|
||||
@ -453,24 +452,6 @@ async fn handle_trash_event(
|
||||
}
|
||||
}
|
||||
|
||||
fn make_view_rev_from(params: CreateViewParams) -> ViewRevision {
|
||||
let time = timestamp();
|
||||
ViewRevision {
|
||||
id: params.view_id,
|
||||
app_id: params.belong_to_id,
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
data_type: params.data_type.into(),
|
||||
version: 0,
|
||||
belongings: vec![],
|
||||
modified_time: time,
|
||||
create_time: time,
|
||||
ext_data: "".to_string(),
|
||||
thumbnail: params.thumbnail,
|
||||
layout: params.layout.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_data_processor(
|
||||
data_processors: ViewDataProcessorMap,
|
||||
data_type: &ViewDataTypePB,
|
||||
|
@ -1,8 +1,6 @@
|
||||
use crate::script::{invalid_workspace_name_test_case, FolderScript::*, FolderTest};
|
||||
use flowy_folder::entities::view::ViewDataTypePB;
|
||||
use flowy_folder::entities::workspace::CreateWorkspacePayloadPB;
|
||||
use flowy_folder::entities::ViewLayoutTypePB;
|
||||
|
||||
use flowy_revision::disk::RevisionState;
|
||||
use flowy_test::{event_builder::*, FlowySDKTest};
|
||||
|
||||
@ -136,13 +134,11 @@ async fn app_create_with_view() {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Text,
|
||||
layout: ViewLayoutTypePB::Grid,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
desc: "Grid description".to_owned(),
|
||||
data_type: ViewDataTypePB::Database,
|
||||
layout: ViewLayoutTypePB::Grid,
|
||||
},
|
||||
ReadApp(app.id),
|
||||
])
|
||||
@ -202,13 +198,11 @@ async fn view_delete_all() {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Text,
|
||||
layout: ViewLayoutTypePB::Grid,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
desc: "Grid description".to_owned(),
|
||||
data_type: ViewDataTypePB::Database,
|
||||
layout: ViewLayoutTypePB::Grid,
|
||||
},
|
||||
ReadApp(app.id.clone()),
|
||||
])
|
||||
@ -237,7 +231,6 @@ async fn view_delete_all_permanent() {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Text,
|
||||
layout: ViewLayoutTypePB::Grid,
|
||||
},
|
||||
ReadApp(app.id.clone()),
|
||||
])
|
||||
@ -337,7 +330,6 @@ async fn folder_sync_revision_with_new_view() {
|
||||
name: view_name.clone(),
|
||||
desc: view_desc.clone(),
|
||||
data_type: ViewDataTypePB::Text,
|
||||
layout: ViewLayoutTypePB::Grid,
|
||||
},
|
||||
AssertCurrentRevId(3),
|
||||
AssertNextSyncRevId(Some(3)),
|
||||
|
@ -53,7 +53,6 @@ pub enum FolderScript {
|
||||
name: String,
|
||||
desc: String,
|
||||
data_type: ViewDataTypePB,
|
||||
layout: ViewLayoutTypePB,
|
||||
},
|
||||
AssertView(ViewPB),
|
||||
ReadView(String),
|
||||
@ -181,12 +180,11 @@ impl FolderTest {
|
||||
delete_app(sdk, &self.app.id).await;
|
||||
}
|
||||
|
||||
FolderScript::CreateView {
|
||||
name,
|
||||
desc,
|
||||
data_type,
|
||||
layout,
|
||||
} => {
|
||||
FolderScript::CreateView { name, desc, data_type } => {
|
||||
let layout = match data_type {
|
||||
ViewDataTypePB::Text => ViewLayoutTypePB::Document,
|
||||
ViewDataTypePB::Database => ViewLayoutTypePB::Grid,
|
||||
};
|
||||
let view = create_view(sdk, &self.app.id, &name, &desc, data_type, layout).await;
|
||||
self.view = view;
|
||||
}
|
||||
|
@ -110,8 +110,7 @@ impl GridBlockManager {
|
||||
None => tracing::error!("Internal error: can't find the row with id: {}", changeset.row_id),
|
||||
Some(row_rev) => {
|
||||
let row_pb = make_row_from_row_rev(row_rev.clone());
|
||||
let block_order_changeset =
|
||||
GridBlockChangesetPB::update(&editor.block_id, vec![row_pb]);
|
||||
let block_order_changeset = GridBlockChangesetPB::update(&editor.block_id, vec![row_pb]);
|
||||
let _ = self
|
||||
.notify_did_update_block(&editor.block_id, block_order_changeset)
|
||||
.await?;
|
||||
@ -189,10 +188,9 @@ impl GridBlockManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_cell(&self, changeset: CellChangesetPB ) -> FlowyResult<()>
|
||||
{
|
||||
pub async fn update_cell(&self, changeset: CellChangesetPB) -> FlowyResult<()> {
|
||||
let row_changeset: RowChangeset = changeset.clone().into();
|
||||
let _ = self.update_row(row_changeset, ).await?;
|
||||
let _ = self.update_row(row_changeset).await?;
|
||||
self.notify_did_update_cell(changeset).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -149,6 +149,10 @@ impl Group {
|
||||
pub fn index_of_row(&self, row_id: &str) -> Option<usize> {
|
||||
self.rows.iter().position(|row| row.id == row_id)
|
||||
}
|
||||
|
||||
pub fn number_of_row(&self) -> usize {
|
||||
self.rows.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, T, G, P> GenericGroupController<C, T, G, P>
|
||||
|
@ -249,27 +249,34 @@ fn move_row(
|
||||
) {
|
||||
cell_data.select_options.iter().for_each(|option| {
|
||||
// Remove the row in which group contains the row
|
||||
if option.id == group.id && group.contains_row(&row_rev.id) {
|
||||
let is_group_contains = group.contains_row(&row_rev.id);
|
||||
let to_index = group.index_of_row(to_row_id);
|
||||
|
||||
if option.id == group.id && is_group_contains {
|
||||
group_changeset.push(GroupRowsChangesetPB::delete(group.id.clone(), vec![row_rev.id.clone()]));
|
||||
group.remove_row(&row_rev.id);
|
||||
}
|
||||
|
||||
// Find the inserted group
|
||||
if let Some(index) = group.index_of_row(to_row_id) {
|
||||
if let Some(to_index) = to_index {
|
||||
let row_pb = RowPB::from(row_rev);
|
||||
let inserted_row = InsertedRowPB {
|
||||
row: row_pb.clone(),
|
||||
index: Some(index as i32),
|
||||
index: Some(to_index as i32),
|
||||
};
|
||||
group_changeset.push(GroupRowsChangesetPB::insert(group.id.clone(), vec![inserted_row]));
|
||||
group.insert_row(index, row_pb);
|
||||
|
||||
// If the inserted row comes from other group, it needs to update the corresponding cell content.
|
||||
if option.id != group.id {
|
||||
// Update the corresponding row's cell content.
|
||||
let cell_rev = insert_select_option_cell(group.id.clone(), field_rev);
|
||||
row_changeset.cell_by_field_id.insert(field_rev.id.clone(), cell_rev);
|
||||
if group.number_of_row() == to_index {
|
||||
group.add_row(row_pb);
|
||||
} else {
|
||||
group.insert_row(to_index, row_pb);
|
||||
}
|
||||
}
|
||||
|
||||
// If the inserted row comes from other group, it needs to update the corresponding cell content.
|
||||
if to_index.is_some() && option.id != group.id {
|
||||
// Update the corresponding row's cell content.
|
||||
let cell_rev = insert_select_option_cell(group.id.clone(), field_rev);
|
||||
row_changeset.cell_by_field_id.insert(field_rev.id.clone(), cell_rev);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -24,6 +24,30 @@ async fn board_init_test() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn board_move_row_test() {
|
||||
let mut test = GridGroupTest::new().await;
|
||||
let group = test.group_at_index(0).await;
|
||||
let scripts = vec![
|
||||
MoveRow {
|
||||
from_group_index: 0,
|
||||
from_row_index: 0,
|
||||
to_group_index: 0,
|
||||
to_row_index: 1,
|
||||
},
|
||||
AssertGroup {
|
||||
group_index: 0,
|
||||
row_count: 2,
|
||||
},
|
||||
AssertGroupRow {
|
||||
group_index: 0,
|
||||
row_index: 1,
|
||||
row: group.rows.get(0).unwrap().clone(),
|
||||
},
|
||||
];
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn board_move_row_to_other_group_test() {
|
||||
let mut test = GridGroupTest::new().await;
|
||||
let group = test.group_at_index(0).await;
|
||||
let scripts = vec![
|
||||
@ -49,3 +73,29 @@ async fn board_move_row_test() {
|
||||
];
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn board_move_row_to_other_group_and_reorder_test() {
|
||||
let mut test = GridGroupTest::new().await;
|
||||
let group = test.group_at_index(0).await;
|
||||
let scripts = vec![
|
||||
MoveRow {
|
||||
from_group_index: 0,
|
||||
from_row_index: 0,
|
||||
to_group_index: 1,
|
||||
to_row_index: 1,
|
||||
},
|
||||
MoveRow {
|
||||
from_group_index: 1,
|
||||
from_row_index: 1,
|
||||
to_group_index: 1,
|
||||
to_row_index: 2,
|
||||
},
|
||||
AssertGroupRow {
|
||||
group_index: 1,
|
||||
row_index: 2,
|
||||
row: group.rows.get(0).unwrap().clone(),
|
||||
},
|
||||
];
|
||||
test.run_scripts(scripts).await;
|
||||
}
|
||||
|
@ -320,9 +320,7 @@ impl RevisionSyncSequence {
|
||||
fn compact(&self) -> Option<(RevisionRange, VecDeque<i64>)> {
|
||||
// Make sure there are two rev_id going to sync. No need to compact if there is only
|
||||
// one rev_id in queue.
|
||||
if self.next_rev_id().is_none() {
|
||||
return None;
|
||||
}
|
||||
self.next_rev_id()?;
|
||||
|
||||
let mut new_seq = self.0.clone();
|
||||
let mut drained = new_seq.drain(1..).collect::<VecDeque<_>>();
|
||||
|
@ -186,6 +186,7 @@ impl ViewDataProcessor for TextBlockViewDataProcessor {
|
||||
view_id: &str,
|
||||
layout: ViewLayoutTypePB,
|
||||
) -> FutureResult<Bytes, FlowyError> {
|
||||
debug_assert_eq!(layout, ViewLayoutTypePB::Document);
|
||||
let user_id = user_id.to_string();
|
||||
let view_id = view_id.to_string();
|
||||
let manager = self.0.clone();
|
||||
|
@ -25,16 +25,11 @@ pub struct ViewTest {
|
||||
|
||||
impl ViewTest {
|
||||
#[allow(dead_code)]
|
||||
pub async fn new(
|
||||
sdk: &FlowySDKTest,
|
||||
data_type: ViewDataTypePB,
|
||||
sub_data_type: ViewLayoutTypePB,
|
||||
data: Vec<u8>,
|
||||
) -> Self {
|
||||
pub async fn new(sdk: &FlowySDKTest, data_type: ViewDataTypePB, layout: ViewLayoutTypePB, data: Vec<u8>) -> Self {
|
||||
let workspace = create_workspace(sdk, "Workspace", "").await;
|
||||
open_workspace(sdk, &workspace.id).await;
|
||||
let app = create_app(sdk, "App", "AppFlowy GitHub Project", &workspace.id).await;
|
||||
let view = create_view(sdk, &app.id, data_type, sub_data_type, data).await;
|
||||
let view = create_view(sdk, &app.id, data_type, layout, data).await;
|
||||
Self {
|
||||
sdk: sdk.clone(),
|
||||
workspace,
|
||||
@ -52,7 +47,7 @@ impl ViewTest {
|
||||
}
|
||||
|
||||
pub async fn new_text_block_view(sdk: &FlowySDKTest) -> Self {
|
||||
Self::new(sdk, ViewDataTypePB::Text, ViewLayoutTypePB::Grid, vec![]).await
|
||||
Self::new(sdk, ViewDataTypePB::Text, ViewLayoutTypePB::Document, vec![]).await
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ impl RowChangeset {
|
||||
row_id,
|
||||
height: None,
|
||||
visibility: None,
|
||||
cell_by_field_id: Default::default()
|
||||
cell_by_field_id: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user