1
0
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:
lucasmerlin
2025-02-04 14:01:32 +01:00
committed by GitHub
parent 23ed49334e
commit b8051cc301
10 changed files with 135 additions and 53 deletions

View File

@@ -165,7 +165,7 @@ mod tests {
use egui::accesskit::Role;
use egui::Key;
use egui_kittest::kittest::Queryable;
use egui_kittest::Harness;
use egui_kittest::{Harness, SnapshotResults};
#[test]
fn clicking_escape_when_popup_open_should_not_close_modal() {
@@ -233,22 +233,18 @@ mod tests {
initial_state,
);
let mut results = Vec::new();
let mut results = SnapshotResults::new();
harness.run();
results.push(harness.try_snapshot("modals_1"));
results.add(harness.try_snapshot("modals_1"));
harness.get_by_label("Save").click();
harness.run_ok();
results.push(harness.try_snapshot("modals_2"));
results.add(harness.try_snapshot("modals_2"));
harness.get_by_label("Yes Please").click();
harness.run_ok();
results.push(harness.try_snapshot("modals_3"));
for result in results {
result.unwrap();
}
results.add(harness.try_snapshot("modals_3"));
}
// This tests whether the backdrop actually prevents interaction with lower layers.