test.rs 3.8 KB

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