Skip to content

Commit

Permalink
fix: select option color backward compatibility (#341)
Browse files Browse the repository at this point in the history
* fix: select option color backward compatibility

* chore: cargo clippy
  • Loading branch information
speed2exe authored Dec 5, 2024
1 parent cc31b09 commit 7c18835
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ mod checklist_type_option_tests {

let json_value = json!({
"options": [
{ "id": "1", "name": "Option1", "color": 0 },
{ "id": "2", "name": "Option2", "color": 1 }
{ "id": "1", "name": "Option1", "color": "Pink" },
{ "id": "2", "name": "Option2", "color": "LightPink" }
],
"selected_option_ids": ["1"]
});
Expand Down
32 changes: 31 additions & 1 deletion collab-database/src/fields/type_option/select_type_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ impl SelectOption {
}
}
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
#[serde(try_from = "u8", into = "u8")]
#[repr(u8)]
#[derive(Default)]
pub enum SelectOptionColor {
Expand Down Expand Up @@ -553,4 +552,35 @@ mod tests {
let result = select_type_option.convert_raw_cell_data(&raw_data);
assert_eq!(result, "Option 1, Option 2");
}

#[test]
fn test_select_content_deser() {
let js_str = r#"{
"options": [
{
"id": "CEZD",
"name": "To Do",
"color": "Purple"
},
{
"id": "TznH",
"name": "Doing",
"color": "Orange"
},
{
"id": "__n6",
"name": "✅ Done",
"color": "Yellow"
}
],
"disable_color": false
}"#;

let select_ty_opt = serde_json::from_str::<SelectTypeOption>(js_str).unwrap();
assert_eq!(select_ty_opt.options.len(), 3);
assert_eq!(select_ty_opt.options[0].name, "To Do");
assert_eq!(select_ty_opt.options[1].color, SelectOptionColor::Orange);
assert_eq!(select_ty_opt.options[2].id, "__n6");
assert!(!select_ty_opt.disable_color);
}
}

0 comments on commit 7c18835

Please sign in to comment.