Add a test for comboboxes (#5574)
* [x] I have followed the instructions in the PR template
This commit is contained in:
parent
329c8f2fc1
commit
7186f72cbe
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:202091634d4483949cb1c5c4c5ec02faa23f4d19e7e833aba135887b77e3188d
|
||||
size 4485
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0a61ecf294d930ebbee9837611d7a75381e690348f448b1c0c8264b27f44ceb3
|
||||
size 7535
|
||||
Loading…
Reference in New Issue