|
@@ -65,53 +65,57 @@ impl CellDataOperation for RichTextTypeOption {
|
|
|
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
+ use crate::services::field::FieldBuilder;
|
|
|
+ use crate::services::field::*;
|
|
|
+ use crate::services::row::{CellDataOperation, TypeOptionCellData};
|
|
|
+ use flowy_grid_data_model::entities::FieldType;
|
|
|
|
|
|
- // #[test]
|
|
|
- // fn text_description_test() {
|
|
|
- // let type_option = RichTextTypeOption::default();
|
|
|
- //
|
|
|
- // // date
|
|
|
- // let date_time_field_meta = FieldBuilder::from_field_type(&FieldType::DateTime).build();
|
|
|
- // let data = TypeOptionCellData::new("1647251762", FieldType::DateTime).json();
|
|
|
- // assert_eq!(
|
|
|
- // type_option.decode_cell_data(data, &date_time_field_meta),
|
|
|
- // "Mar 14,2022 17:56".to_owned()
|
|
|
- // );
|
|
|
- //
|
|
|
- // // Single select
|
|
|
- // let done_option = SelectOption::new("Done");
|
|
|
- // let done_option_id = done_option.id.clone();
|
|
|
- // let single_select = SingleSelectTypeOptionBuilder::default().option(done_option);
|
|
|
- // let single_select_field_meta = FieldBuilder::new(single_select).build();
|
|
|
- // let cell_data = TypeOptionCellData::new(&done_option_id, FieldType::SingleSelect).json();
|
|
|
- // assert_eq!(
|
|
|
- // type_option.decode_cell_data(cell_data, &single_select_field_meta),
|
|
|
- // "Done".to_owned()
|
|
|
- // );
|
|
|
- //
|
|
|
- // // Multiple select
|
|
|
- // let google_option = SelectOption::new("Google");
|
|
|
- // let facebook_option = SelectOption::new("Facebook");
|
|
|
- // let ids = vec![google_option.id.clone(), facebook_option.id.clone()].join(SELECTION_IDS_SEPARATOR);
|
|
|
- // let cell_data_changeset = SelectOptionCellChangeset::from_insert(&ids).cell_data();
|
|
|
- // let multi_select = MultiSelectTypeOptionBuilder::default()
|
|
|
- // .option(google_option)
|
|
|
- // .option(facebook_option);
|
|
|
- // let multi_select_field_meta = FieldBuilder::new(multi_select).build();
|
|
|
- // let multi_type_option = MultiSelectTypeOption::from(&multi_select_field_meta);
|
|
|
- // let cell_data = multi_type_option.apply_changeset(cell_data_changeset, None).unwrap();
|
|
|
- // assert_eq!(
|
|
|
- // type_option.decode_cell_data(cell_data, &multi_select_field_meta),
|
|
|
- // "Google,Facebook".to_owned()
|
|
|
- // );
|
|
|
- //
|
|
|
- // //Number
|
|
|
- // let number = NumberTypeOptionBuilder::default().set_format(NumberFormat::USD);
|
|
|
- // let number_field_meta = FieldBuilder::new(number).build();
|
|
|
- // let data = TypeOptionCellData::new("18443", FieldType::Number).json();
|
|
|
- // assert_eq!(
|
|
|
- // type_option.decode_cell_data(data, &number_field_meta),
|
|
|
- // "$18,443".to_owned()
|
|
|
- // );
|
|
|
- // }
|
|
|
+ #[test]
|
|
|
+ fn text_description_test() {
|
|
|
+ let type_option = RichTextTypeOption::default();
|
|
|
+
|
|
|
+ // date
|
|
|
+ let date_time_field_meta = FieldBuilder::from_field_type(&FieldType::DateTime).build();
|
|
|
+ let data = TypeOptionCellData::new("1647251762", FieldType::DateTime).json();
|
|
|
+ assert_eq!(
|
|
|
+ type_option.decode_cell_data(data, &date_time_field_meta),
|
|
|
+ "Mar 14,2022".to_owned()
|
|
|
+ );
|
|
|
+
|
|
|
+ // Single select
|
|
|
+ let done_option = SelectOption::new("Done");
|
|
|
+ let done_option_id = done_option.id.clone();
|
|
|
+ let single_select = SingleSelectTypeOptionBuilder::default().option(done_option);
|
|
|
+ let single_select_field_meta = FieldBuilder::new(single_select).build();
|
|
|
+ let cell_data = TypeOptionCellData::new(&done_option_id, FieldType::SingleSelect).json();
|
|
|
+ assert_eq!(
|
|
|
+ type_option.decode_cell_data(cell_data, &single_select_field_meta),
|
|
|
+ "Done".to_owned()
|
|
|
+ );
|
|
|
+
|
|
|
+ // Multiple select
|
|
|
+ let google_option = SelectOption::new("Google");
|
|
|
+ let facebook_option = SelectOption::new("Facebook");
|
|
|
+ let ids = vec![google_option.id.clone(), facebook_option.id.clone()].join(SELECTION_IDS_SEPARATOR);
|
|
|
+ let cell_data_changeset = SelectOptionCellChangeset::from_insert(&ids).cell_data();
|
|
|
+ let multi_select = MultiSelectTypeOptionBuilder::default()
|
|
|
+ .option(google_option)
|
|
|
+ .option(facebook_option);
|
|
|
+ let multi_select_field_meta = FieldBuilder::new(multi_select).build();
|
|
|
+ let multi_type_option = MultiSelectTypeOption::from(&multi_select_field_meta);
|
|
|
+ let cell_data = multi_type_option.apply_changeset(cell_data_changeset, None).unwrap();
|
|
|
+ assert_eq!(
|
|
|
+ type_option.decode_cell_data(cell_data, &multi_select_field_meta),
|
|
|
+ "Google,Facebook".to_owned()
|
|
|
+ );
|
|
|
+
|
|
|
+ //Number
|
|
|
+ let number = NumberTypeOptionBuilder::default().set_format(NumberFormat::USD);
|
|
|
+ let number_field_meta = FieldBuilder::new(number).build();
|
|
|
+ let data = TypeOptionCellData::new("18443", FieldType::Number).json();
|
|
|
+ assert_eq!(
|
|
|
+ type_option.decode_cell_data(data, &number_field_meta),
|
|
|
+ "$18,443".to_owned()
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|