Files
gridcraft/crates/ui-egui/tests/it/dialog_focus.rs
T
aiongg a7608ada6d CI: one test binary per crate, nextest, line tables only (#2372)
* CI: dev builds keep line tables only

* CI: one integration-test binary per crate

* CI: xtask runs tests with nextest, doctests apart, --keep-going on clippy and wasm

cargo xtask test runs the workspace tests (--lib --bins --tests) with cargo-nextest when it is installed, else cargo test, then the doctests. cargo xtask ci uses the same two steps.

* CI: docs name cargo xtask test

* CI: agent guides name the moved fuzz test

* CI: tests added on main join their crate's test binary
2026-10-23 12:59:46 -04:00

82 lines
2.9 KiB
Rust

//! Form dialogs open ready to type, as in Excel: Alt+H, O, W then a number and Enter sets the
//! column width without clicking into the field first.
use egui::{Event, Key, vec2};
use gridcraft_engine::Session;
use gridcraft_engine::core::CellRef;
use gridcraft_ui_egui::SheetApp;
use serde_json::json;
fn harness() -> egui_kittest::Harness<'static, SheetApp> {
let mut session = Session::new();
session.new_workbook();
session.execute("selection.set", json!({"cell": "C3"})).unwrap();
let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 800.0)).build_ui_state(
|ui, app: &mut SheetApp| {
app.logic(&ui.ctx().clone());
app.ui(ui);
},
SheetApp::new(session, Default::default()),
);
h.run_steps(6);
h
}
fn type_and_enter(h: &mut egui_kittest::Harness<'static, SheetApp>, text: &str) {
for c in text.chars() {
h.input_mut().events.push(Event::Text(c.to_string()));
h.run_steps(1);
}
h.key_press(Key::Enter);
h.run_steps(6);
}
#[test]
fn column_width_opens_with_the_width_ready_to_type() {
let mut h = harness();
h.state_mut().open_dialog("columnWidth", json!({}));
h.run_steps(6);
type_and_enter(&mut h, "12");
assert!(h.state().dialog.is_none(), "Enter confirmed the dialog");
let chars = {
let d = h.state().session.active().unwrap();
let sheet = d.wb.active().unwrap();
gridcraft_engine::cmd::format::points_to_chars(sheet.col_width(CellRef::parse("C3").unwrap().col) as f64)
};
assert!((chars - 12.0).abs() < 0.2, "column C is 12 characters wide, got {chars}");
}
#[test]
fn row_height_opens_with_the_height_ready_to_type() {
let mut h = harness();
h.state_mut().open_dialog("rowHeight", json!({}));
h.run_steps(6);
type_and_enter(&mut h, "40");
assert!(h.state().dialog.is_none(), "Enter confirmed the dialog");
let height = {
let d = h.state().session.active().unwrap();
d.wb.active().unwrap().row_height(CellRef::parse("C3").unwrap().row)
};
assert!((height as f64 - 40.0).abs() < 0.6, "row 3 is 40 high, got {height}");
}
#[test]
fn command_search_arrow_and_page_keys_move_the_selection_and_keep_the_search_focused() {
let mut h = harness();
h.state_mut().open_dialog("commandSearch", json!({}));
h.run_steps(6);
h.input_mut().events.push(Event::Text("a".into()));
h.run_steps(3);
assert_eq!(h.state().dialog.as_ref().map(|d| d.list_index), Some(0));
for _ in 0..2 {
h.key_press(Key::ArrowDown);
h.run_steps(2);
}
assert_eq!(h.state().dialog.as_ref().map(|d| d.list_index), Some(2), "two ArrowDown presses");
h.key_press(Key::PageDown);
h.run_steps(2);
let after_page = h.state().dialog.as_ref().map(|d| d.list_index).unwrap_or(0);
assert!(after_page > 2, "PageDown moved past the third row, got {after_page}");
assert!(h.ctx.memory(|m| m.focused()).is_some(), "the search field kept focus");
}