cell_test.rs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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::{MultiSelectTypeOption, SelectOptionCellContentChangeset, SingleSelectTypeOption};
  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 field_type: FieldType = field_rev.field_type_rev.into();
  18. let data = match field_type {
  19. FieldType::RichText => "".to_string(),
  20. FieldType::Number => "123".to_string(),
  21. FieldType::DateTime => make_date_cell_string("123"),
  22. FieldType::SingleSelect => {
  23. let type_option = SingleSelectTypeOption::from(field_rev);
  24. SelectOptionCellContentChangeset::from_insert(&type_option.options.first().unwrap().id).to_str()
  25. }
  26. FieldType::MultiSelect => {
  27. let type_option = MultiSelectTypeOption::from(field_rev);
  28. SelectOptionCellContentChangeset::from_insert(&type_option.options.first().unwrap().id).to_str()
  29. }
  30. FieldType::Checkbox => "1".to_string(),
  31. FieldType::URL => "1".to_string(),
  32. };
  33. scripts.push(UpdateCell {
  34. changeset: CellChangeset {
  35. grid_id: block_id.to_string(),
  36. row_id: row_rev.id.clone(),
  37. field_id: field_rev.id.clone(),
  38. cell_content_changeset: Some(data),
  39. },
  40. is_err: false,
  41. });
  42. }
  43. }
  44. test.run_scripts(scripts).await;
  45. }