script.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use crate::database::database_editor::DatabaseEditorTest;
  2. use flowy_database2::entities::CreateRowParams;
  3. pub enum RowScript {
  4. CreateEmptyRow,
  5. AssertRowCount(usize),
  6. }
  7. pub struct DatabaseRowTest {
  8. inner: DatabaseEditorTest,
  9. }
  10. impl DatabaseRowTest {
  11. pub async fn new() -> Self {
  12. let editor_test = DatabaseEditorTest::new_grid().await;
  13. Self { inner: editor_test }
  14. }
  15. pub async fn run_scripts(&mut self, scripts: Vec<RowScript>) {
  16. for script in scripts {
  17. self.run_script(script).await;
  18. }
  19. }
  20. pub async fn run_script(&mut self, script: RowScript) {
  21. match script {
  22. RowScript::CreateEmptyRow => {
  23. let params = CreateRowParams {
  24. view_id: self.view_id.clone(),
  25. start_row_id: None,
  26. group_id: None,
  27. cell_data_by_field_id: None,
  28. };
  29. let row_order = self.editor.create_row(params).await.unwrap().unwrap();
  30. self
  31. .row_by_row_id
  32. .insert(row_order.id.to_string(), row_order.into());
  33. self.rows = self.get_rows().await;
  34. },
  35. RowScript::AssertRowCount(expected_row_count) => {
  36. assert_eq!(expected_row_count, self.rows.len());
  37. },
  38. }
  39. }
  40. }
  41. impl std::ops::Deref for DatabaseRowTest {
  42. type Target = DatabaseEditorTest;
  43. fn deref(&self) -> &Self::Target {
  44. &self.inner
  45. }
  46. }
  47. impl std::ops::DerefMut for DatabaseRowTest {
  48. fn deref_mut(&mut self) -> &mut Self::Target {
  49. &mut self.inner
  50. }
  51. }