mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-27 03:56:50 -06:00
UI: close About dialog on Cancel and test Options Cancel from File tab (#782)
In release 0.7.0, Cancel in the Preferences dialog (opened via Options in the File tab) did nothing. This was previously addressed on main by #757 (#752). This change adds an egui_kittest regression test verifying that clicking Options from the File tab opens the Preferences dialog and clicking Cancel closes it while keeping Backstage open. In addition, the About dialog's Cancel button now properly closes the dialog instead of being ignored. Closes #782.
This commit is contained in:
@@ -535,3 +535,20 @@ fn print_slides_follow_the_settings() {
|
||||
bs.print_layout = "slides";
|
||||
assert_eq!(print_page_size(&bs, &doc), (doc.slide_size.width as f32, doc.slide_size.height as f32), "slides print slide-shaped");
|
||||
}
|
||||
|
||||
/// Options in the File tab opens the Preferences dialog, and Cancel closes it (#782, #752).
|
||||
#[test]
|
||||
fn options_in_backstage_opens_preferences_and_cancel_closes_it() {
|
||||
let mut h = harness(new_app());
|
||||
h.get_by_label("File").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().backstage_open());
|
||||
h.get_by_label("Options").click();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().dialog.is_some(), "Options opens Preferences dialog");
|
||||
assert_eq!(h.state().dialog.as_ref().map(|d| d.id.as_str()), Some("preferences"));
|
||||
h.query_all_by_role_and_label(Role::Button, "Cancel").next().expect("Cancel button").click_accesskit();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().dialog.is_none(), "Cancel closes Preferences dialog");
|
||||
assert!(h.state().backstage_open(), "Backstage remains open");
|
||||
}
|
||||
|
||||
@@ -2085,8 +2085,8 @@ fn body(app: &mut SlideApp, ui: &mut Ui, d: &mut Dialog) -> bool {
|
||||
}
|
||||
_ => about(app, ui),
|
||||
}
|
||||
let (ok, _) = buttons(ui, "Close");
|
||||
ok
|
||||
let (ok, cancel) = buttons(ui, "Close");
|
||||
ok || cancel
|
||||
}
|
||||
"autocorrect" => {
|
||||
let pr = &mut app.session.prefs;
|
||||
|
||||
@@ -2642,6 +2642,41 @@ mod tests {
|
||||
assert_ne!(s.session.prefs.snap_to_grid, before.snap_to_grid, "Done keeps snap to grid");
|
||||
}
|
||||
|
||||
/// About dialog: Close and Cancel each close the dialog.
|
||||
#[test]
|
||||
fn about_dialog_close_and_cancel_close_it() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|
||||
|ui, app: &mut SlideApp| {
|
||||
app.logic(ui.ctx());
|
||||
app.ui(ui);
|
||||
},
|
||||
SlideApp::new(Session::with_new(), Services::default()),
|
||||
);
|
||||
harness.run_steps(2);
|
||||
harness.state_mut().run("app.about", json!({})).unwrap();
|
||||
harness.run_steps(2);
|
||||
assert!(harness.state().dialog.is_some());
|
||||
harness
|
||||
.query_all_by_role_and_label(egui::accesskit::Role::Button, "Cancel")
|
||||
.next()
|
||||
.unwrap_or_else(|| panic!("no Cancel button in About dialog"))
|
||||
.click_accesskit();
|
||||
harness.run_steps(2);
|
||||
assert!(harness.state().dialog.is_none(), "Cancel closes About dialog");
|
||||
|
||||
harness.state_mut().run("app.about", json!({})).unwrap();
|
||||
harness.run_steps(2);
|
||||
assert!(harness.state().dialog.is_some());
|
||||
harness
|
||||
.query_all_by_role_and_label(egui::accesskit::Role::Button, "Close")
|
||||
.next()
|
||||
.unwrap_or_else(|| panic!("no Close button in About dialog"))
|
||||
.click_accesskit();
|
||||
harness.run_steps(2);
|
||||
assert!(harness.state().dialog.is_none(), "Close closes About dialog");
|
||||
}
|
||||
|
||||
fn canvas_harness() -> egui_kittest::Harness<'static, SlideApp> {
|
||||
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
|
||||
|ui, app: &mut SlideApp| {
|
||||
|
||||
Reference in New Issue
Block a user