test.rs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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::field::selection_type_option::SelectOptionCellChangeset;
  6. use flowy_grid::services::field::{MultiSelectTypeOptionPB, SingleSelectTypeOptionPB};
  7. #[tokio::test]
  8. async fn grid_cell_update() {
  9. let mut test = GridCellTest::new().await;
  10. let field_revs = &test.field_revs;
  11. let row_revs = &test.row_revs;
  12. let grid_blocks = &test.block_meta_revs;
  13. // For the moment, We only have one block to store rows
  14. let block_id = &grid_blocks.first().unwrap().block_id;
  15. let mut scripts = vec![];
  16. for (_, row_rev) in row_revs.iter().enumerate() {
  17. for field_rev in field_revs {
  18. let field_type: FieldType = field_rev.ty.into();
  19. let data = match field_type {
  20. FieldType::RichText => "".to_string(),
  21. FieldType::Number => "123".to_string(),
  22. FieldType::DateTime => make_date_cell_string("123"),
  23. FieldType::SingleSelect => {
  24. let type_option = SingleSelectTypeOptionPB::from(field_rev);
  25. SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id).to_str()
  26. }
  27. FieldType::MultiSelect => {
  28. let type_option = MultiSelectTypeOptionPB::from(field_rev);
  29. SelectOptionCellChangeset::from_insert_option_id(&type_option.options.first().unwrap().id).to_str()
  30. }
  31. FieldType::Checkbox => "1".to_string(),
  32. FieldType::URL => "1".to_string(),
  33. };
  34. scripts.push(UpdateCell {
  35. changeset: CellChangesetPB {
  36. grid_id: block_id.to_string(),
  37. row_id: row_rev.id.clone(),
  38. field_id: field_rev.id.clone(),
  39. content: data,
  40. },
  41. is_err: false,
  42. });
  43. }
  44. }
  45. test.run_scripts(scripts).await;
  46. }