Bartosz Sypytkowski fd5299a13d
move to latest appflowy collab version (#5894)
* chore: move to latest appflowy collab version

* chore: filter mapping

* chore: remove mutex folder

* chore: cleanup borrow checker issues

* chore: fixed flowy user crate compilation errors

* chore: removed parking lot crate

* chore: adjusting non locking approach

* chore: remove with folder method

* chore: fix folder manager

* chore: fixed workspace database compilation errors

* chore: initialize database plugins

* chore: fix locks in flowy core

* chore: remove supabase

* chore: async traits

* chore: add mutexes in dart ffi

* chore: post rebase fixes

* chore: remove supabase dart code

* chore: fix deadlock

* chore: fix page_id is empty

* chore: use data source to init collab

* chore: fix user awareness test

* chore: fix database deadlock

* fix: initialize user awareness

* chore: fix open workspace test

* chore: fix import csv

* chore: fix update row meta deadlock

* chore: fix document size test

* fix: timestamp set/get type convert

* fix: calculation

* chore: revert Arc to Rc

* chore: attach plugin to database and database row

* chore: async get row

* chore: clippy

* chore: fix tauri build

* chore: clippy

* fix: duplicate view deadlock

* chore: fmt

* chore: tauri build

---------

Co-authored-by: nathan <nathan@appflowy.io>
2024-08-18 11:16:42 +08:00

148 lines
3.9 KiB
Rust

use collab_database::fields::{Field, TypeOptionData};
use flowy_database2::entities::{CreateFieldParams, FieldChangesetParams, FieldType};
use flowy_database2::services::cell::stringify_cell;
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,
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;
let _ = self.editor.create_field_with_type_option(params).await;
let fields = self.editor.get_fields(&self.view_id, None).await;
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).await.is_some() {
self.field_count -= 1;
}
self.editor.delete_field(&field.id).await.unwrap();
let fields = self.editor.get_fields(&self.view_id, None).await;
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).await.unwrap();
self
.editor
.update_field_type_option(&field_id, type_option, old_field)
.await
.unwrap();
},
FieldScript::AssertFieldCount(count) => {
assert_eq!(self.get_fields().await.len(), count);
},
FieldScript::AssertFieldTypeOptionEqual {
field_index,
expected_type_option_data,
} => {
let fields = self.get_fields().await;
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,
expected_content,
} => {
let field = self.editor.get_field(&field_id).await.unwrap();
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(&cell, &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
}
}