test_helper.rs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. use crate::entities::{data_format_from_layout, CreateViewParams, ViewLayoutTypePB};
  2. use crate::manager::FolderManager;
  3. use crate::services::folder_editor::FolderEditor;
  4. use folder_model::gen_view_id;
  5. use std::collections::HashMap;
  6. use std::sync::Arc;
  7. #[cfg(feature = "flowy_unit_test")]
  8. impl FolderManager {
  9. pub async fn folder_editor(&self) -> Arc<FolderEditor> {
  10. self.folder_editor.read().await.clone().unwrap()
  11. }
  12. pub async fn create_test_grid_view(
  13. &self,
  14. app_id: &str,
  15. name: &str,
  16. ext: HashMap<String, String>,
  17. ) -> String {
  18. self
  19. .create_test_view(app_id, name, ViewLayoutTypePB::Grid, ext)
  20. .await
  21. }
  22. pub async fn create_test_board_view(
  23. &self,
  24. app_id: &str,
  25. name: &str,
  26. ext: HashMap<String, String>,
  27. ) -> String {
  28. self
  29. .create_test_view(app_id, name, ViewLayoutTypePB::Board, ext)
  30. .await
  31. }
  32. async fn create_test_view(
  33. &self,
  34. app_id: &str,
  35. name: &str,
  36. layout: ViewLayoutTypePB,
  37. ext: HashMap<String, String>,
  38. ) -> String {
  39. let view_id = gen_view_id();
  40. let data_format = data_format_from_layout(&layout);
  41. let params = CreateViewParams {
  42. belong_to_id: app_id.to_string(),
  43. name: name.to_string(),
  44. desc: "".to_string(),
  45. thumbnail: "".to_string(),
  46. data_format,
  47. layout,
  48. view_id: view_id.clone(),
  49. initial_data: vec![],
  50. ext,
  51. };
  52. self
  53. .view_controller
  54. .create_view_from_params(params)
  55. .await
  56. .unwrap();
  57. view_id
  58. }
  59. }