use makepad_widgets::makepad_test::{run_with_config, Selector, TestApp, TestConfig}; fn run_ui_test(test_name: &str, body: impl FnOnce(TestApp)) { let mut config = TestConfig::current_package( env!("CARGO_MANIFEST_DIR"), env!("CARGO_PKG_NAME"), format!("ui::{test_name}"), ) .expect("makepad test configuration"); // StudioHub launches the package through a child shell. Explicitly pass // the isolated Cargo path so the child can find the same toolchain as the // outer `cargo test` process. if let Ok(path) = std::env::var("PATH") { config.env.insert("PATH".into(), path.clone()); for directory in path.split(':') { let cargo = std::path::Path::new(directory).join("cargo"); if cargo.is_file() { config .env .insert("CARGO".into(), cargo.to_string_lossy().into_owned()); break; } } } for key in ["CARGO_HOME", "RUSTUP_HOME", "RUSTC"] { if let Ok(value) = std::env::var(key) { config.env.insert(key.into(), value); } } // The current Makepad Linux branch has an incomplete `MAKEPAD=headless` // cfg path. Let Linux compile its native backend; the Studio hub still // drives the app through the test protocol. config.env.remove("MAKEPAD"); run_with_config(config, body).expect("Makepad app failed to start or test failed"); } #[test] fn spreadsheet_workspace_smoke() { run_ui_test("spreadsheet_workspace_smoke", |app: TestApp| { app.locator(Selector::id("formula_input")).wait_visible(); app.locator(Selector::id("grid")).wait_visible(); app.locator(Selector::id("add_sheet_btn")).wait_visible(); }); } #[test] fn spreadsheet_workspace_can_add_sheet() { run_ui_test("spreadsheet_workspace_can_add_sheet", |app: TestApp| { app.locator(Selector::id("add_sheet_btn")) .wait_visible() .click(); app.locator(Selector::id("sheet_status")) .wait_text("Active Sheet: Sheet4 | AutoCalc On"); }); }