cell_test.rs 2.0 KB

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