script.rs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. use crate::grid::grid_editor::GridEditorTest;
  2. use flowy_grid::entities::CellChangeset;
  3. pub enum CellScript {
  4. UpdateCell { changeset: CellChangeset, is_err: bool },
  5. }
  6. pub struct GridCellTest {
  7. inner: GridEditorTest,
  8. }
  9. impl GridCellTest {
  10. pub async fn new() -> Self {
  11. let inner = GridEditorTest::new().await;
  12. Self { inner }
  13. }
  14. pub async fn run_scripts(&mut self, scripts: Vec<CellScript>) {
  15. for script in scripts {
  16. self.run_script(script).await;
  17. }
  18. }
  19. pub async fn run_script(&mut self, script: CellScript) {
  20. // let grid_manager = self.sdk.grid_manager.clone();
  21. // let pool = self.sdk.user_session.db_pool().unwrap();
  22. let rev_manager = self.editor.rev_manager();
  23. let _cache = rev_manager.revision_cache().await;
  24. match script {
  25. CellScript::UpdateCell { changeset, is_err } => {
  26. let result = self.editor.update_cell(changeset).await;
  27. if is_err {
  28. assert!(result.is_err())
  29. } else {
  30. let _ = result.unwrap();
  31. self.row_revs = self.get_row_revs().await;
  32. }
  33. } // CellScript::AssertGridRevisionPad => {
  34. // sleep(Duration::from_millis(2 * REVISION_WRITE_INTERVAL_IN_MILLIS)).await;
  35. // let mut grid_rev_manager = grid_manager.make_grid_rev_manager(&self.grid_id, pool.clone()).unwrap();
  36. // let grid_pad = grid_rev_manager.load::<GridPadBuilder>(None).await.unwrap();
  37. // println!("{}", grid_pad.delta_str());
  38. // }
  39. }
  40. }
  41. }
  42. impl std::ops::Deref for GridCellTest {
  43. type Target = GridEditorTest;
  44. fn deref(&self) -> &Self::Target {
  45. &self.inner
  46. }
  47. }
  48. impl std::ops::DerefMut for GridCellTest {
  49. fn deref_mut(&mut self) -> &mut Self::Target {
  50. &mut self.inner
  51. }
  52. }