diff --git a/crates/ui-egui/src/dialogs/tests_plugin_fields.rs b/crates/ui-egui/src/dialogs/tests_plugin_fields.rs index c02363e9f5..795c540b64 100644 --- a/crates/ui-egui/src/dialogs/tests_plugin_fields.rs +++ b/crates/ui-egui/src/dialogs/tests_plugin_fields.rs @@ -257,3 +257,67 @@ fn an_open_plugin_dialog_follows_a_change_of_language() { assert_eq!(shown, (false, true), "the label in German"); assert_eq!(values.unwrap()["size"].as_f64(), Some(7.0), "the value set before"); } + +/// The width of every path in the active document together, in points. +fn paths_width(app: &VectorcraftApp) -> Option { + let doc = &app.session.doc().ok()?.doc; + let mut ids = Vec::new(); + doc.walk(|n| { + if n.path_data().is_some() { + ids.push(n.id); + } + }); + doc.bounds_of(&ids, false).map(|r| r.x1 - r.x0) +} + +/// Values typed and clicked in a plug-in's dialog reach the plug-in: a check box shows the row +/// whose `visibleWhen` it meets, the number typed there previews on the canvas, and OK runs the +/// filter with it as one undo step. +#[test] +fn typed_plugin_values_show_rows_and_reach_the_preview_and_the_run() { + use crate::tests::panel_harness::Panel; + let id = "test.ui.fields.typed"; + let manifest = format!( + r#"{{"id":"{id}","name":"Typed Values","version":"1","kind":"filter","params":{{ + "grow":{{"type":"bool","default":false,"label":"Grow"}}, + "n":{{"type":"int","min":0,"max":10,"default":3,"label":"Count","visibleWhen":{{"grow":[true]}}}}}}}}"# + ); + // A 30 pt wide triangle when the filter is given `n` 7, a 50 pt square otherwise. + let triangle = r#"{"objects":[{"path":{"subpaths":[{"closed":true,"anchors":[{"p":[0,0]},{"p":[30,0]},{"p":[15,20]}]}]}}]}"#; + let square = r#"{"objects":[{"path":{"subpaths":[{"closed":true,"anchors":[{"p":[0,0]},{"p":[50,0]},{"p":[50,50]},{"p":[0,50]}]}]}}]}"#; + let wasm = wat::parse_str(tpl::when_given_else(&manifest, tpl::Given::Params, r#""n":7"#, triangle, square)).unwrap(); + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + app.run("plugin.install", json!({"dataBase64": vectorcraft_format::base64_encode(&wasm)})).unwrap(); + let mut panel = Panel::new(app, crate::tests::picks::dialogs); + panel.app().run("plugin.dialog", json!({"id": id})).unwrap(); + panel.frame(); + panel.frame(); + assert!(!panel.shows("Count"), "Count is hidden while Grow is off"); + panel.click("Grow"); + panel.frame(); + assert_eq!(fields(&panel.app())["grow"], json!(true), "the click reaches the dialog's values"); + assert!(panel.shows("Count"), "checking Grow shows Count"); + panel.click("Count"); + panel.key(egui::Key::A, egui::Modifiers::COMMAND); + panel.type_text("7"); + panel.key(egui::Key::Tab, egui::Modifiers::NONE); + panel.frame(); + panel.frame(); + let typed = fields(&panel.app())["n"].clone(); + let previewed = paths_width(&panel.app()); + let undo = panel.app().session.doc().unwrap().history.undo.len(); + panel.click("OK"); + panel.frame(); + panel.frame(); + let (closed, steps, ran) = { + let app = panel.app(); + (!app.any_dialog_open(), app.session.doc().unwrap().history.undo.len(), paths_width(&app)) + }; + panel.app().run("plugin.remove", json!({"id": id})).unwrap(); + assert_eq!(typed.as_f64(), Some(7.0), "the typed count reaches the dialog's values"); + assert_eq!(previewed, Some(30.0), "the typed count previewed"); + assert!(closed, "OK closed the dialog"); + assert_eq!(steps, undo + 1, "one undo step"); + assert_eq!(ran, Some(30.0), "the filter ran with the typed count"); +}