From 767e9b067d07e3aa61ac866da26a0dfe320f2c8f Mon Sep 17 00:00:00 2001 From: mavrick Date: Sun, 29 Nov 2026 12:01:06 -0600 Subject: [PATCH] test(ui): stabilize Select By Attributes dialog interactions --- crates/ui-egui/src/dialogs.rs | 89 ++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index e70eabe5f9..d899000448 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -4067,7 +4067,7 @@ mod tests { let stop = h.state().dialogs.matching.stop_flag(); assert!(!stop.load(std::sync::atomic::Ordering::Relaxed), "counting for the open dialog"); h.get_by_role_and_label(Role::Button, "Cancel").click(); - h.run(); + h.step(); assert_eq!(h.state().dialogs.open, None, "Cancel closed it"); assert!(stop.load(std::sync::atomic::Ordering::Relaxed), "and the count was told to stop"); } @@ -4079,9 +4079,9 @@ mod tests { use egui_kittest::kittest::Queryable; let mut h = sba_ready(); h.get_by_role_and_label(Role::Button, "Cancel").focus(); - h.run(); + h.step(); h.key_press(egui::Key::Enter); - h.run(); + h.step(); assert_eq!(h.state().dialogs.open, None, "Cancel closed it"); assert_eq!(selected(h.state()), 0, "and nothing was selected"); } @@ -4093,11 +4093,11 @@ mod tests { use egui_kittest::kittest::Queryable; let mut h = sba_ready(); h.state_mut().dialogs.text = "pop_est > 1 AND".into(); - h.run(); + h.step(); h.get_by_role_and_label(Role::Button, "continent").focus(); - h.run(); + h.step(); h.key_press(egui::Key::Enter); - h.run(); + h.step(); assert_eq!(h.state().dialogs.text, "pop_est > 1 AND continent ", "the field added"); assert_eq!(h.state().dialogs.open, Some("selectByAttributes"), "the dialog is still open"); assert_eq!(h.state().dialogs.error, None, "and didn't run"); @@ -4112,24 +4112,24 @@ mod tests { use egui_kittest::kittest::Queryable; let mut h = sba_ready(); h.ctx.memory_mut(|m| m.request_focus(egui::Id::unique("sba_where"))); - h.run(); + h.step(); h.key_press(egui::Key::Enter); - h.run(); + h.step(); assert_eq!(h.state().dialogs.open, None, "the box's Enter applied"); let n = selected(h.state()); assert!(n > 0, "and selected"); let mut h = sba_ready(); h.get_by_role_and_label(Role::Button, "Apply").focus(); - h.run(); + h.step(); h.key_press(egui::Key::Enter); - h.run(); + h.step(); assert_eq!(h.state().dialogs.open, None, "Apply's Enter applied"); assert_eq!(h.state().dialogs.error, None); assert_eq!(selected(h.state()), n); let mut h = sba_ready(); assert_eq!(h.ctx.memory(|m| m.focused()), None, "nothing focused"); h.key_press(egui::Key::Enter); - h.run(); + h.step(); assert_eq!(h.state().dialogs.open, None, "Enter with nothing focused applied"); assert_eq!(selected(h.state()), n); } @@ -4260,9 +4260,9 @@ mod tests { use egui_kittest::kittest::Queryable; let mut h = sba_ready(); h.get_by_role_and_label(Role::ComboBox, "Selection Type").focus(); - h.run(); + h.step(); h.key_press(egui::Key::Enter); - h.run(); + h.run_steps(2); assert!(h.query_by_label("Add To Current Selection").is_some(), "the drop-down opened"); assert_eq!(h.state().dialogs.open, Some("selectByAttributes"), "the dialog is still open"); assert_eq!(selected(h.state()), 0, "and didn't run"); @@ -4716,21 +4716,22 @@ mod tests { let shown = |h: &egui_kittest::Harness<'static, RustGisApp>, name: &str| h.query_all_by_role_and_label(Role::Button, name).count(); let (pop, continent) = (shown(&h, "pop_est"), shown(&h, "continent")); h.ctx.memory_mut(|m| m.request_focus(egui::Id::unique("sba_where"))); - h.run(); + h.step(); + // Suggestions need a layout frame after processing text input. h.event(egui::Event::Text("pop_e".into())); - h.run(); + h.run_steps(2); assert_eq!(shown(&h, "pop_est"), pop + 1, "the field offered"); assert!(h.query_by_label_contains("Invalid:").is_none(), "no error while it is offered"); h.key_press(egui::Key::Enter); - h.run(); + h.step(); assert_eq!(h.state().dialogs.text, "pop_est"); assert_eq!(h.state().dialogs.open, Some("selectByAttributes"), "Enter took the field, not Apply"); assert_eq!(h.state().dialogs.error, None, "and didn't run"); h.event(egui::Event::Text(" > 1 AND cont".into())); - h.run(); + h.run_steps(2); assert_eq!(shown(&h, "continent"), continent + 1, "offered on"); h.key_press(egui::Key::Escape); - h.run(); + h.step(); assert_eq!(shown(&h, "continent"), continent, "the list closed"); assert_eq!(h.state().dialogs.open, Some("selectByAttributes"), "Escape took the list, not the dialog"); assert!(h.query_by_label_contains("Invalid:").is_some(), "the error once the list is closed"); @@ -4749,20 +4750,22 @@ mod tests { app.dialogs.layer = "Countries".into(); let mut h = app_harness(app); h.run_steps(3); + // A Values click opens the popup and the next frame places it using its measured size. + // The background match count can still be running while we check the list. let values = |h: &mut egui_kittest::Harness<'static, RustGisApp>| { h.get_by_role_and_label(Role::Button, "Values ▾").click(); - h.run(); + h.run_steps(2); }; let pick = |h: &mut egui_kittest::Harness<'static, RustGisApp>, value: &str| { h.get_by_role_and_label(Role::Button, value).click(); - h.run(); + h.step(); }; // No field chosen yet: it says what to do, as the list has nothing to show. values(&mut h); assert!(h.query_by_label("Click a field, or put the cursor in one, to list its values").is_some()); // A field clicked: its values are listed, read once however long the list stays open. h.get_by_role_and_label(Role::Button, "continent").click(); - h.run(); + h.step(); assert!(h.query_by_label("Click a field, or put the cursor in one, to list its values").is_none(), "said no more"); // The button wrote the field into the box, and the box is not cleared: the value adds the // comparison to it, not the field again. @@ -4787,14 +4790,14 @@ mod tests { assert_eq!(h.state().dialogs.text, "name IN ('Asia') ", "a list of one, closed so the clause reads"); // Another field reads its own values. h.get_by_role_and_label(Role::Button, "name").click(); - h.run(); + h.step(); h.state_mut().dialogs.text.clear(); values(&mut h); assert_eq!(h.state().dialogs.values.reads, 2); assert!(h.query_by_role_and_label(Role::Button, "'Asia'").is_none(), "not the last field's values"); // Another layer has no field chosen: the list is dropped with the layer. h.key_press(egui::Key::Escape); - h.run(); + h.step(); h.state_mut().dialogs.layer = "Cities".into(); h.run_steps(2); values(&mut h); @@ -4803,13 +4806,13 @@ mod tests { h.state_mut().dialogs.layer = "Countries".into(); h.run_steps(2); h.get_by_role_and_label(Role::Button, "continent").click(); - h.run(); + h.step(); values(&mut h); assert_eq!(h.state().dialogs.values.reads, 3); h.key_press(egui::Key::Escape); - h.run(); + h.step(); h.get_by_role_and_label(Role::Button, "Cancel").click(); - h.run(); + h.step(); assert_eq!((h.state().dialogs.open, h.state().dialogs.values.reads), (None, 0)); } @@ -4827,15 +4830,15 @@ mod tests { let id = egui::Id::unique("sba_where"); h.state_mut().dialogs.text = "continent = AND pop_est > 1".into(); h.ctx.memory_mut(|m| m.request_focus(id)); - h.run(); + h.step(); let mut state = egui::widgets::text_edit::TextEditState::load(&h.ctx, id).unwrap_or_default(); state.cursor.set_char_range(Some(CCursorRange::one(CCursor::new(12)))); state.store(&h.ctx, id); - h.run(); + h.step(); h.get_by_role_and_label(Role::Button, "Values ▾").click(); - h.run(); + h.run_steps(2); h.get_by_role_and_label(Role::Button, "'Asia'").click(); - h.run(); + h.step(); assert_eq!(h.state().dialogs.text, "continent = 'Asia' AND pop_est > 1", "the gap filled, the rest kept"); } @@ -4852,17 +4855,17 @@ mod tests { let mut h = app_harness(app); h.run_steps(3); h.get_by_role_and_label(Role::Button, "continent").click(); - h.run(); + h.step(); let id = egui::Id::unique("sba_where"); h.state_mut().dialogs.text = "upper(name) = ".into(); h.ctx.memory_mut(|m| m.request_focus(id)); - h.run(); + h.step(); let mut state = egui::widgets::text_edit::TextEditState::load(&h.ctx, id).unwrap_or_default(); state.cursor.set_char_range(Some(CCursorRange::one(CCursor::new(14)))); state.store(&h.ctx, id); - h.run(); + h.step(); h.get_by_role_and_label(Role::Button, "Values ▾").click(); - h.run(); + h.run_steps(2); assert!(h.query_by_label("Click a field, or put the cursor in one, to list its values").is_some(), "no field chosen"); assert!(h.query_by_role_and_label(Role::Button, "'Asia'").is_none(), "continent isn't listed"); } @@ -4887,10 +4890,10 @@ mod tests { let first = rustgis_engine::data::query::field_values(&ds, field, rustgis_engine::data::query::VALUES_READ).values[0].written.clone(); h.get_by_role_and_label(Role::Button, "continent").click(); - h.run(); + h.step(); h.state_mut().dialogs.text.clear(); h.get_by_role_and_label(Role::Button, "Values ▾").click(); - h.run(); + h.run_steps(2); assert_eq!(h.state().dialogs.values.reads, 1); // A new value that sorts before the rest arrives while the list is open. let mut attrs = vec![Value::Null; ds.fields.len()]; @@ -4900,12 +4903,12 @@ mod tests { assert!(h.query_by_role_and_label(Role::Button, "'Aaa'").is_none(), "the list is as it was opened"); assert_eq!(h.state().dialogs.values.reads, 1, "not read again while open"); h.key_press(egui::Key::Enter); - h.run(); + h.step(); assert_eq!(h.state().dialogs.text, format!("continent = {first} "), "Enter takes the value that was highlighted"); // Opened again: the rows now. h.state_mut().dialogs.text.clear(); h.get_by_role_and_label(Role::Button, "Values ▾").click(); - h.run(); + h.run_steps(2); assert_eq!(h.state().dialogs.values.reads, 2); assert!(h.query_by_role_and_label(Role::Button, "'Aaa'").is_some(), "read again on the next opening"); } @@ -4997,15 +5000,15 @@ mod tests { let mut h = app_harness(app); h.run_steps(3); h.get_by_role_and_label(Role::Button, "name").click(); - h.run(); + h.step(); h.state_mut().dialogs.text.clear(); h.get_by_role_and_label(Role::Button, "Values ▾").click(); - h.run(); + h.run_steps(2); h }; let mut h = open(points(vec!["O'Brien".into(), "Paul".into()])); h.get_by_role_and_label(Role::Button, "'O''Brien'").click(); - h.run(); + h.step(); let text = h.state().dialogs.text.clone(); assert_eq!(text, "name = 'O''Brien' "); let layer = h.state().session.map().layer_by_name(&h.state().dialogs.layer).map(|l| l.dataset.clone()); @@ -5019,9 +5022,9 @@ mod tests { h.state_mut().session.map_mut().layer_mut(id).unwrap().dataset.windowed = true; // The list stays as it was read while it is open; opened again, it says so. h.get_by_role_and_label(Role::Button, "Values ▾").click(); - h.run(); + h.run_steps(2); h.get_by_role_and_label(Role::Button, "Values ▾").click(); - h.run(); + h.run_steps(2); assert!(h.query_by_label("Values of the 3 features read for the view").is_some()); // More features than are read: a sample, and how much of it.