cell_test.rs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. use crate::grid::field_util::make_date_cell_string;
  2. use crate::grid::script::EditorScript::*;
  3. use crate::grid::script::*;
  4. use flowy_grid::entities::{CellChangeset, FieldType};
  5. use flowy_grid::services::field::select_option::SelectOptionCellContentChangeset;
  6. use flowy_grid::services::field::{MultiSelectTypeOption, SingleSelectTypeOption};
  7. #[tokio::test]
  8. async fn grid_cell_update() {
  9. let mut test = GridEditorTest::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.field_type_rev.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 = SingleSelectTypeOption::from(field_rev);
  25. SelectOptionCellContentChangeset::from_insert(&type_option.options.first().unwrap().id).to_str()
  26. }
  27. FieldType::MultiSelect => {
  28. let type_option = MultiSelectTypeOption::from(field_rev);
  29. SelectOptionCellContentChangeset::from_insert(&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: CellChangeset {
  36. grid_id: block_id.to_string(),
  37. row_id: row_rev.id.clone(),
  38. field_id: field_rev.id.clone(),
  39. cell_content_changeset: Some(data),
  40. },
  41. is_err: false,
  42. });
  43. }
  44. }
  45. test.run_scripts(scripts).await;
  46. }