2022-03-04 10:11:12 +00:00
|
|
|
use flowy_grid_data_model::entities::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn grid_serde_test() {
|
|
|
|
let grid_id = "1".to_owned();
|
2022-03-10 04:01:31 +00:00
|
|
|
let fields = vec![create_field("1")];
|
|
|
|
let grid = GridMeta {
|
|
|
|
grid_id,
|
|
|
|
fields,
|
2022-03-18 09:14:46 +00:00
|
|
|
block_metas: vec![],
|
2022-03-04 10:11:12 +00:00
|
|
|
};
|
|
|
|
|
2022-03-10 04:01:31 +00:00
|
|
|
let grid_1_json = serde_json::to_string(&grid).unwrap();
|
2022-03-10 09:14:10 +00:00
|
|
|
let _: GridMeta = serde_json::from_str(&grid_1_json).unwrap();
|
2022-03-04 10:11:12 +00:00
|
|
|
assert_eq!(
|
2022-03-10 04:01:31 +00:00
|
|
|
grid_1_json,
|
2022-03-10 09:14:10 +00:00
|
|
|
r#"{"id":"1","fields":[{"id":"1","name":"Text Field","desc":"","field_type":"RichText","frozen":false,"visibility":true,"width":150,"type_options":{"type_id":"","value":[]}}],"blocks":[]}"#
|
2022-03-04 10:11:12 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn grid_default_serde_test() {
|
|
|
|
let grid_id = "1".to_owned();
|
2022-03-10 04:01:31 +00:00
|
|
|
let grid = GridMeta {
|
|
|
|
grid_id,
|
|
|
|
fields: vec![],
|
2022-03-18 09:14:46 +00:00
|
|
|
block_metas: vec![],
|
2022-03-04 10:11:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let json = serde_json::to_string(&grid).unwrap();
|
2022-03-10 09:14:10 +00:00
|
|
|
assert_eq!(json, r#"{"id":"1","fields":[],"blocks":[]}"#)
|
2022-03-04 10:11:12 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 03:07:18 +00:00
|
|
|
fn create_field(field_id: &str) -> FieldMeta {
|
|
|
|
let mut field = FieldMeta::new("Text Field", "", FieldType::RichText);
|
2022-03-12 01:30:13 +00:00
|
|
|
field.id = field_id.to_string();
|
|
|
|
field
|
2022-03-04 10:11:12 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 01:03:02 +00:00
|
|
|
#[allow(dead_code)]
|
2022-03-04 10:11:12 +00:00
|
|
|
fn uuid() -> String {
|
|
|
|
uuid::Uuid::new_v4().to_string()
|
|
|
|
}
|