mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Add SnapshotResults struct to egui_kittest (#5672)
I got annoyed by all the slightly different variations of "collect snapshot results and unwrap them at the end of test" I've written, so I added a struct to make this nice and simple. One controversial thing: It panics when dropped. I wanted to ensure people cannot forget to unwrap the results at the end, and this was the best thing I could come up with. I don't think this is possible via clippy lint or something like that. * [x] I have followed the instructions in the PR template
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use egui::accesskit::Role;
|
||||
use egui::{Button, ComboBox, Image, Vec2, Widget};
|
||||
use egui_kittest::{kittest::Queryable, Harness};
|
||||
use egui_kittest::{kittest::Queryable, Harness, SnapshotResults};
|
||||
|
||||
#[test]
|
||||
pub fn focus_should_skip_over_disabled_buttons() {
|
||||
@@ -64,10 +64,10 @@ fn test_combobox() {
|
||||
|
||||
harness.run();
|
||||
|
||||
let mut results = vec![];
|
||||
let mut results = SnapshotResults::new();
|
||||
|
||||
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
|
||||
results.push(harness.try_snapshot("combobox_closed"));
|
||||
results.add(harness.try_snapshot("combobox_closed"));
|
||||
|
||||
let combobox = harness.get_by_role_and_label(Role::ComboBox, "Select Something");
|
||||
combobox.click();
|
||||
@@ -75,7 +75,7 @@ fn test_combobox() {
|
||||
harness.run();
|
||||
|
||||
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
|
||||
results.push(harness.try_snapshot("combobox_opened"));
|
||||
results.add(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
|
||||
@@ -87,10 +87,4 @@ fn test_combobox() {
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::{Harness, SnapshotResults};
|
||||
|
||||
#[test]
|
||||
fn test_shrink() {
|
||||
@@ -10,6 +10,8 @@ fn test_shrink() {
|
||||
|
||||
harness.fit_contents();
|
||||
|
||||
let mut results = SnapshotResults::new();
|
||||
|
||||
#[cfg(all(feature = "snapshot", feature = "wgpu"))]
|
||||
harness.snapshot("test_shrink");
|
||||
results.add(harness.try_snapshot("test_shrink"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user