test.rs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. use crate::database::cell_test::script::CellScript::*;
  2. use crate::database::cell_test::script::DatabaseCellTest;
  3. use crate::database::field_test::util::make_date_cell_string;
  4. use flowy_database::entities::{CellChangesetPB, FieldType};
  5. use flowy_database::services::cell::ToCellChangesetString;
  6. use flowy_database::services::field::selection_type_option::SelectOptionCellChangeset;
  7. use flowy_database::services::field::{
  8. ChecklistTypeOptionPB, MultiSelectTypeOptionPB, SingleSelectTypeOptionPB,
  9. };
  10. #[tokio::test]
  11. async fn grid_cell_update() {
  12. let mut test = DatabaseCellTest::new().await;
  13. let field_revs = &test.field_revs;
  14. let row_revs = &test.row_revs;
  15. let grid_blocks = &test.block_meta_revs;
  16. // For the moment, We only have one block to store rows
  17. let block_id = &grid_blocks.first().unwrap().block_id;
  18. let mut scripts = vec![];
  19. for (_, row_rev) in row_revs.iter().enumerate() {
  20. for field_rev in field_revs {
  21. let field_type: FieldType = field_rev.ty.into();
  22. let data = match field_type {
  23. FieldType::RichText => "".to_string(),
  24. FieldType::Number => "123".to_string(),
  25. FieldType::DateTime => make_date_cell_string("123"),
  26. FieldType::SingleSelect => {
  27. let type_option = SingleSelectTypeOptionPB::from(field_rev);
  28. SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id)
  29. .to_cell_changeset_str()
  30. },
  31. FieldType::MultiSelect => {
  32. let type_option = MultiSelectTypeOptionPB::from(field_rev);
  33. SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id)
  34. .to_cell_changeset_str()
  35. },
  36. FieldType::Checklist => {
  37. let type_option = ChecklistTypeOptionPB::from(field_rev);
  38. SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id)
  39. .to_cell_changeset_str()
  40. },
  41. FieldType::Checkbox => "1".to_string(),
  42. FieldType::URL => "1".to_string(),
  43. };
  44. scripts.push(UpdateCell {
  45. changeset: CellChangesetPB {
  46. view_id: block_id.to_string(),
  47. row_id: row_rev.id.clone(),
  48. field_id: field_rev.id.clone(),
  49. type_cell_data: data,
  50. },
  51. is_err: false,
  52. });
  53. }
  54. }
  55. test.run_scripts(scripts).await;
  56. }
  57. #[tokio::test]
  58. async fn text_cell_date_test() {
  59. let test = DatabaseCellTest::new().await;
  60. let text_field = test.get_first_field_rev(FieldType::RichText);
  61. let cells = test
  62. .editor
  63. .get_cells_for_field(&test.view_id, &text_field.id)
  64. .await
  65. .unwrap();
  66. for (i, cell) in cells.into_iter().enumerate() {
  67. let text = cell.into_text_field_cell_data().unwrap();
  68. match i {
  69. 0 => assert_eq!(text.as_str(), "A"),
  70. 1 => assert_eq!(text.as_str(), ""),
  71. 2 => assert_eq!(text.as_str(), "C"),
  72. 3 => assert_eq!(text.as_str(), "DA"),
  73. 4 => assert_eq!(text.as_str(), "AE"),
  74. 5 => assert_eq!(text.as_str(), "AE"),
  75. _ => {},
  76. }
  77. }
  78. }
  79. #[tokio::test]
  80. async fn url_cell_date_test() {
  81. let test = DatabaseCellTest::new().await;
  82. let url_field = test.get_first_field_rev(FieldType::URL);
  83. let cells = test
  84. .editor
  85. .get_cells_for_field(&test.view_id, &url_field.id)
  86. .await
  87. .unwrap();
  88. for (i, cell) in cells.into_iter().enumerate() {
  89. let url_cell_data = cell.into_url_field_cell_data().unwrap();
  90. if i == 0 {
  91. assert_eq!(url_cell_data.url.as_str(), "https://www.appflowy.io/");
  92. }
  93. }
  94. }