diff --git a/crates/plugins/src/panel.rs b/crates/plugins/src/panel.rs index 470b14d7b5..17dd76d602 100644 --- a/crates/plugins/src/panel.rs +++ b/crates/plugins/src/panel.rs @@ -559,10 +559,18 @@ impl Dropped { parts.push(format!("{} {what}: {names}{more}", ids.len().saturating_add(unlisted))); } } - for (id, given) in &self.cut { + if !self.cut.is_empty() { + let names = self + .cut + .iter() + .take(MAX_NAMED) + .map(|(id, given)| format!("{} ({given} nodes given)", diagnostic_name(id))) + .collect::>() + .join(", "); + let more = if self.cut.len() > MAX_NAMED { ", …" } else { "" }; parts.push(format!( - "tree {} was given {given} nodes: only the first {MAX_TREE_NODES} are kept, the most a tree holds", - diagnostic_name(id) + "{} tree(s) cut: only the first {MAX_TREE_NODES} nodes are kept, the most a tree holds: {names}{more}", + self.cut.len() )); } if self.nodes > 0 { diff --git a/crates/plugins/src/tests.rs b/crates/plugins/src/tests.rs index 4e14dbbfd3..d65a63e8cc 100644 --- a/crates/plugins/src/tests.rs +++ b/crates/plugins/src/tests.rs @@ -1220,6 +1220,24 @@ fn a_tree_cut_at_its_limit_says_so() { assert_eq!(over.nodes, 2, "the node without an id and its child"); assert_eq!(st.items["catalogue"].cut, Some(given)); + // Two trees cut in one answer: one part, with the count and each tree. + let mut m: Value = serde_json::from_str(&testing::panel_manifest("tree-panel")).unwrap(); + for id in ["catalogue", "places"] { + m["panel"]["items"].as_array_mut().unwrap().push(json!({"kind": "tree", "id": id, "label": id, "command": "q"})); + } + let two = Manifest::parse(&m.to_string()).unwrap().panel.unwrap(); + let mut both = PanelState::new(&two); + let over = both + .apply(&two, &json!({"items": {"catalogue": {"nodes": flat(MAX_TREE_NODES + 1)}, "places": {"nodes": flat(MAX_TREE_NODES + 2)}}})); + let notice = over.notice().unwrap(); + assert_eq!(notice.matches("tree(s) cut").count(), 1, "{notice}"); + assert!(notice.contains(&format!("2 tree(s) cut: only the first {MAX_TREE_NODES} nodes")), "{notice}"); + assert!( + notice.contains(&format!("catalogue ({} nodes given)", MAX_TREE_NODES + 1)) + && notice.contains(&format!("places ({} nodes given)", MAX_TREE_NODES + 2)), + "{notice}" + ); + // Fewer again: no cut left to say. assert_eq!(st.apply(&decl, &json!({"items": {"catalogue": {"nodes": flat(3)}}})).notice(), None); assert_eq!(st.items["catalogue"].cut, None); diff --git a/crates/ui-egui/src/pluginpanel.rs b/crates/ui-egui/src/pluginpanel.rs index bd0b5cc486..922821fae1 100644 --- a/crates/ui-egui/src/pluginpanel.rs +++ b/crates/ui-egui/src/pluginpanel.rs @@ -1327,6 +1327,56 @@ mod tests { assert_eq!(shown_value(&json!("two")), "two"); } + /// A tree the plugin gave more nodes than it holds says so under it: under its rows, and + /// under a search that finds nothing, since what it looks for may be among those left out; + /// a tree within its limit says nothing (#1546). + #[test] + fn a_cut_tree_says_so_under_its_rows_and_an_empty_search() { + let _turn = crate::fetching::turn(); + use egui_kittest::kittest::Queryable; + use rustgis_engine::plugins; + let mut m: Value = serde_json::from_str(&plugins::testing::panel_manifest("ui-cut")).unwrap(); + m["panel"]["items"] = json!([{"kind": "tree", "id": "area", "label": "Area", "command": "q", "search": true}]); + m["panel"].as_object_mut().unwrap().remove("state"); + let manifest = m.to_string(); + let zip = plugins::testing::zip_of(&[("plugin.json", manifest.as_bytes()), ("plugin.wasm", &plugins::testing::wasm())]); + plugins::load(plugins::Package::from_zip(&zip).unwrap(), "test").unwrap(); + let decl = plugins::Manifest::parse(&manifest).unwrap().panel.unwrap(); + let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1400.0, 860.0)).with_step_dt(0.05).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + RustGisApp::with_sample(), + ); + h.state_mut().run("ui.pane.plugin", json!({"id": "ui-cut"})).unwrap(); + h.run_steps(3); + let give = |h: &mut egui_kittest::Harness<'_, RustGisApp>, n: usize| { + let nodes: Vec = (0..n).map(|i| json!({"id": format!("m{i}"), "label": format!("Place {i}")})).collect(); + let st = h.state_mut().session.plugin_panels.get_mut("ui-cut").unwrap(); + st.apply(&decl, &json!({"items": {"area": {"nodes": nodes}}})); + h.run_steps(3); + }; + let given = MAX_TREE_NODES + 1; + give(&mut h, given); + let note = format!( + "Only the first {MAX_TREE_NODES} of the {given} nodes the plugin gave are shown: a tree holds at most {MAX_TREE_NODES}." + ); + assert!(h.query_by_label("Place 0").is_some(), "its rows shown"); + assert!(h.query_by_label(¬e).is_some(), "the note under them"); + // The node past the limit isn't found, and the note says why it may not be. + h.state_mut().ui.plugin_panel.search.insert("area".into(), format!("Place {MAX_TREE_NODES}")); + h.run_steps(3); + assert!(h.query_by_label("Nothing matches.").is_some()); + assert!(h.query_by_label(¬e).is_some(), "the note under an empty search too"); + h.state_mut().ui.plugin_panel.search.clear(); + give(&mut h, 3); + assert!(h.query_by_label("Place 2").is_some()); + assert!(h.query_by_label_contains("Only the first").is_none(), "a tree within its limit says nothing"); + plugins::unload("ui-cut"); + } + /// A plugin's command adding data by address doesn't wait for it: the app downloads it off /// the frame, as the browser does, and the layer lands as the plugin asked for it (#1144). #[test] diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 5bd89ca574..0fd77a6ac6 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -2410,6 +2410,7 @@ dependencies = [ "parquet", "postgres", "proj4rs", + "quick-xml", "roxmltree", "rusqlite", "rustgis-geom", @@ -2500,6 +2501,7 @@ dependencies = [ "serde", "serde_json", "sha2 0.11.1", + "unicode-normalization", "ureq", "wasmi", "zip",