diff --git a/crates/egui_kittest/tests/regression_tests.rs b/crates/egui_kittest/tests/regression_tests.rs index 32b412e6ed8..8567e10ea90 100644 --- a/crates/egui_kittest/tests/regression_tests.rs +++ b/crates/egui_kittest/tests/regression_tests.rs @@ -1,4 +1,5 @@ -use egui::{Button, Image, Vec2, Widget}; +use egui::accesskit::Role; +use egui::{Button, ComboBox, Image, Vec2, Widget}; use egui_kittest::{kittest::Queryable, Harness}; #[test] @@ -43,3 +44,53 @@ fn image_failed() { #[cfg(all(feature = "wgpu", feature = "snapshot"))] harness.snapshot("image_snapshots"); } + +#[test] +fn test_combobox() { + let items = ["Item 1", "Item 2", "Item 3"]; + let mut harness = Harness::builder() + .with_size(Vec2::new(300.0, 200.0)) + .build_ui_state( + |ui, selected| { + ComboBox::new("combobox", "Select Something").show_index( + ui, + selected, + items.len(), + |idx| *items.get(idx).expect("Invalid index"), + ); + }, + 0, + ); + + harness.run(); + + let mut results = vec![]; + + #[cfg(all(feature = "wgpu", feature = "snapshot"))] + results.push(harness.try_snapshot("combobox_closed")); + + let combobox = harness.get_by_role_and_label(Role::ComboBox, "Select Something"); + combobox.click(); + + harness.run(); + + #[cfg(all(feature = "wgpu", feature = "snapshot"))] + results.push(harness.try_snapshot("combobox_opened")); + + let item_2 = harness.get_by_role_and_label(Role::Button, "Item 2"); + // Node::click doesn't close the popup, so we use simulate_click + item_2.simulate_click(); + + harness.run(); + + assert_eq!(harness.state(), &1); + + // Popup should be closed now + assert!(harness.query_by_label("Item 2").is_none()); + + for result in results { + if let Err(err) = result { + panic!("{}", err); + } + } +} diff --git a/crates/egui_kittest/tests/snapshots/combobox_closed.png b/crates/egui_kittest/tests/snapshots/combobox_closed.png new file mode 100644 index 00000000000..18a9d0bc9f2 --- /dev/null +++ b/crates/egui_kittest/tests/snapshots/combobox_closed.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:202091634d4483949cb1c5c4c5ec02faa23f4d19e7e833aba135887b77e3188d +size 4485 diff --git a/crates/egui_kittest/tests/snapshots/combobox_opened.png b/crates/egui_kittest/tests/snapshots/combobox_opened.png new file mode 100644 index 00000000000..201fc999e2e --- /dev/null +++ b/crates/egui_kittest/tests/snapshots/combobox_opened.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a61ecf294d930ebbee9837611d7a75381e690348f448b1c0c8264b27f44ceb3 +size 7535