test.rs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.editor.get_cell_data_for_field(&text_field.id).await.unwrap();
  60. for (i, cell) in cells.iter().enumerate() {
  61. let text = cell.get_text_field_cell_data().unwrap();
  62. match i {
  63. 0 => assert_eq!(text.as_str(), "A"),
  64. 1 => assert_eq!(text.as_str(), ""),
  65. 2 => assert_eq!(text.as_str(), "C"),
  66. 3 => assert_eq!(text.as_str(), "DA"),
  67. 4 => assert_eq!(text.as_str(), "AE"),
  68. 5 => assert_eq!(text.as_str(), "AE"),
  69. _ => {}
  70. }
  71. }
  72. }
  73. #[tokio::test]
  74. async fn url_cell_date_test() {
  75. let test = GridCellTest::new().await;
  76. let url_field = test.get_first_field_rev(FieldType::URL);
  77. let cells = test.editor.get_cell_data_for_field(&url_field.id).await.unwrap();
  78. for (i, cell) in cells.iter().enumerate() {
  79. let url_cell_data = cell.get_url_field_cell_data().unwrap();
  80. match i {
  81. 0 => assert_eq!(url_cell_data.url.as_str(), "https://www.appflowy.io/"),
  82. _ => {}
  83. }
  84. }
  85. }