mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-12 08:51:00 -06:00
Tests: the hex paste dialog tests release Enter after each press
A dialog's OK ignores a repeat of Enter, and an egui context keeps a key down until it is released. The Color Picker, Swatch Options and Define Grid tests pressed Enter in one context without releasing it, so every press after the first was a repeat and the dialog stayed open. Each test now releases Enter after pressing it.
This commit is contained in:
@@ -978,6 +978,8 @@ fn a_hex_code_pasted_into_the_hex_field_replaces_its_digits() {
|
||||
texts
|
||||
};
|
||||
let key = |key| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() };
|
||||
// The context keeps a key down until it is let go, and a dialog ignores a repeat of Enter.
|
||||
let release = |key| egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers: Default::default() };
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
type Open = fn(&mut VectorcraftApp);
|
||||
type Applied = fn(&VectorcraftApp) -> String;
|
||||
@@ -1024,6 +1026,7 @@ fn a_hex_code_pasted_into_the_hex_field_replaces_its_digits() {
|
||||
let shows = frame(&mut app, vec![egui::Event::Paste(paste.into())]);
|
||||
assert!(shows.iter().any(|(t, _)| t == hex), "{name}: the # field keeps {hex} after pasting {paste:?}");
|
||||
frame(&mut app, vec![key(egui::Key::Enter)]);
|
||||
frame(&mut app, vec![release(egui::Key::Enter)]);
|
||||
assert!(app.ui.dialog.is_none(), "{name}: Enter closes the dialog after pasting {paste:?}");
|
||||
assert_eq!(applied(&app), before, "{name}: pasting {paste:?} changes no color");
|
||||
}
|
||||
@@ -1050,6 +1053,7 @@ fn a_hex_code_pasted_into_the_hex_field_replaces_its_digits() {
|
||||
click_in(&mut app);
|
||||
frame(&mut app, vec![egui::Event::Paste(paste.into())]);
|
||||
frame(&mut app, vec![key(egui::Key::Enter)]);
|
||||
frame(&mut app, vec![release(egui::Key::Enter)]);
|
||||
assert!(app.ui.dialog.is_none(), "{name}: Enter closes the dialog after pasting {paste:?}");
|
||||
assert_eq!(applied(&app), "#00ff00", "{name}: Enter applies {paste:?}");
|
||||
app.run("swatch.edit", json!({"name": "Sky", "color": "#3366cc"})).unwrap();
|
||||
|
||||
@@ -94,7 +94,8 @@ fn define_grid_takes_a_three_digit_color() {
|
||||
texts
|
||||
};
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() };
|
||||
// The context keeps a key down until it is let go, and a dialog ignores a repeat of Enter.
|
||||
let enter = |pressed| egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Default::default() };
|
||||
for (how, input) in [("pasted", egui::Event::Paste("0f0".into())), ("typed", egui::Event::Text("0f0".into()))] {
|
||||
app.run("ui.perspectiveGridDialog", json!({})).unwrap();
|
||||
set(&mut app, "leftColor", json!("#123456"));
|
||||
@@ -107,7 +108,8 @@ fn define_grid_takes_a_three_digit_color() {
|
||||
frame(&mut app, vec![button(at, false)]);
|
||||
frame(&mut app, vec![]);
|
||||
frame(&mut app, vec![input]);
|
||||
frame(&mut app, vec![enter.clone()]);
|
||||
frame(&mut app, vec![enter(true)]);
|
||||
frame(&mut app, vec![enter(false)]);
|
||||
assert_eq!(kind(&app), None, "{how}: Enter closes the dialog");
|
||||
assert_eq!(grid(&app).left_color.hex(), "#00ff00", "{how}: the grid takes the color");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user