From 9432ae487cd28ce272452096218ca0bff2413057 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 11:36:54 -0700 Subject: [PATCH] test(kde): pin the JSON of Monitor and MonitorInformation Two unit tests in komorebi-for-kde's monitor.rs, the counterpart of the Windows pins: a Monitor read from the monitor object of a real komorebic state capture (e2e/lib/tests/fixtures/kfde-tiled.json, workspaces emptied) serializes back to the same JSON value, and MonitorInformation has its four fields. They fix the representation before any move of the Monitor type. Verified: KDE cargo test -p komorebi --lib monitor:: (native, lite env): 14 passed, 0 failed. Not a behaviour change. --- komorebi-for-kde/komorebi/src/monitor.rs | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/komorebi-for-kde/komorebi/src/monitor.rs b/komorebi-for-kde/komorebi/src/monitor.rs index c1698d86..6c25242b 100644 --- a/komorebi-for-kde/komorebi/src/monitor.rs +++ b/komorebi-for-kde/komorebi/src/monitor.rs @@ -914,4 +914,48 @@ mod tests { assert_eq!(fake.rect_of(511), Some(rect(100, 0, 1820, 1050))); Ok(()) } + + /// The monitor object of a real `komorebic state` capture (e2e/lib/tests/fixtures/kfde-tiled.json, + /// workspaces emptied): the JSON a Monitor reads and writes. Pins the representation of `id` (a + /// plain number) and `serial_number_id` (a string) so that moving the type cannot change the + /// state JSON. + const MONITOR_JSON: &str = r#"{ + "id": 1230296105, + "device": "Virtual-0", + "serial_number_id": "Virtual-0", + "workspaces": { "elements": [], "focused": 0 }, + "size": { "left": 0, "top": 0, "right": 1920, "bottom": 1080 }, + "work_area_offset": null, + "work_area_size": { "left": 0, "top": 0, "right": 1920, "bottom": 1050 }, + "window_based_work_area_offset": null, + "window_based_work_area_offset_limit": 1, + "container_padding": null, + "workspace_padding": null, + "last_focused_workspace": 0, + "wallpaper": null, + "floating_layer_behaviour": null + }"#; + + #[test] + fn a_monitor_serializes_to_the_json_of_the_state_capture() { + let expected: serde_json::Value = serde_json::from_str(MONITOR_JSON).unwrap(); + let monitor: Monitor = serde_json::from_value(expected.clone()).unwrap(); + + assert_eq!(serde_json::to_value(&monitor).unwrap(), expected); + } + + #[test] + fn monitor_information_has_the_four_documented_fields() { + let monitor: Monitor = serde_json::from_str(MONITOR_JSON).unwrap(); + + assert_eq!( + serde_json::to_value(MonitorInformation::from(&monitor)).unwrap(), + serde_json::json!({ + "id": 1230296105, + "device": "Virtual-0", + "serial_number_id": "Virtual-0", + "size": { "left": 0, "top": 0, "right": 1920, "bottom": 1080 } + }) + ); + } }