Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Color Picker test: the typed-CMYK case on its own

moppeeer8509c39102ae
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 2404a7032..9fe6a049c 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -11058,6 +11058,25 @@ mod tests {
/// is on, the new colour over the old one, and the values in every space.
#[test]
+ fn the_color_picker_keeps_a_typed_cmyk_value_the_colour_shown_does_not_change_with() {
+ use egui_kittest::kittest::Queryable;
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ app.ui.dialog = Some(Dialog::new("colorPicker", json!({"target": "fill", "cmyk": [0.0, 0.0, 0.0, 100.0], "text": false})));
+ let mut h = crate::test_window::open(app, egui::vec2(1400.0, 900.0));
+ h.run_steps(3);
+ // A C typed at 100% K is kept, whether or not the colour shown changes with it.
+ let rgb = h.state().app.ui.dialog.as_ref().unwrap().fields.get("rgb").cloned();
+ h.get_by_label("C").focus();
+ h.run_steps(1);
+ h.event(egui::Event::Text("50".into()));
+ h.run_steps(2);
+ let d = h.state().app.ui.dialog.as_ref().unwrap();
+ assert_eq!(d.fields["cmyk"], json!([50.0, 0.0, 0.0, 100.0]), "rgb {:?} (was {rgb:?})", d.fields.get("rgb"));
+ assert!(d.b("edited"));
+ }
+
+ #[test]
fn the_color_picker_picks_on_its_field_and_slider_and_adds_a_cmyk_swatch() {
use egui_kittest::kittest::Queryable;
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
@@ -11116,19 +11135,6 @@ mod tests {
panic!("a CMYK swatch")
};
assert_eq!([c, m, y, k].map(|v| (v * 100.0).round()), [0.0, 50.0, 100.0, 0.0]);
- // A C typed at 100% K is kept, whether or not the colour shown changes with it.
- let rgb = h.state().app.ui.dialog.as_ref().unwrap().fields["rgb"].clone();
- h.state_mut().app.ui.dialog.as_mut().unwrap().fields.insert("cmyk".into(), json!([0.0, 0.0, 0.0, 100.0]));
- h.run_steps(2);
- h.get_by_label("C").focus();
- h.run_steps(1);
- h.event(egui::Event::Text("50".into()));
- h.run_steps(2);
- let d = h.state().app.ui.dialog.as_ref().unwrap();
- assert_eq!(d.fields["cmyk"], json!([50.0, 0.0, 0.0, 100.0]), "rgb {} (was {rgb})", d.fields["rgb"]);
- assert!(d.b("edited"));
- store_picked(h.state_mut().app.ui.dialog.as_mut().unwrap(), &Picked::from_rgb([124.0 / 255.0, 19.0 / 255.0, 21.0 / 255.0], 0.0));
- h.run_steps(2);
// Its own OK, at the top right, applies it.
h.get_by_label("OK").click();
h.run_steps(3);