//! Real Makepad UI interactions. No Studio hub and no ignored tests. //! Pattern: Nigig's spreadsheet run_with_config isolation and current counter API. use makepad_test::{run_with_config, Selector, TestApp, TestConfig}; fn run(name: &str, body: impl FnOnce(TestApp)) { let mut config = TestConfig::new(env!("CARGO_MANIFEST_DIR"), "budget", name).unwrap(); config.action_timeout = std::time::Duration::from_secs(if name == "desktop_full_capture" { 90 } else { 15 }); let home = std::env::temp_dir().join(format!("budget-ui-{}-{name}", std::process::id())); struct Cleanup(std::path::PathBuf); impl Drop for Cleanup { fn drop(&mut self) { let _ = std::fs::remove_dir_all(&self.0); } } std::fs::create_dir_all(&home).unwrap(); let _cleanup = Cleanup(home.clone()); for (key, path) in [("HOME", home.clone()), ("XDG_DATA_HOME", home.join("data")), ("XDG_CONFIG_HOME", home.join("config")), ("XDG_CACHE_HOME", home.join("cache"))] { std::fs::create_dir_all(&path).unwrap(); config.env.insert(key.into(), path.to_string_lossy().into_owned()); } if let Some(style) = name.strip_prefix("planner_chrome_") { config.env.insert("MAKEPAD_WIDGET_STYLE".into(), style.into()); config.env.insert("MAKEPAD_GPUSIM_DPI".into(), "1".into()); } run_with_config(config, body).unwrap(); } #[test] fn history_rejects_invalid_dates_through_real_inputs() { run("invalid_dates", |app| { app.locator(Selector::id("history_btn")).wait_visible().click(); app.locator(Selector::id("period_start")).wait_visible().fill("not-a-date"); app.locator(Selector::id("show_history")).click(); app.locator(Selector::id("history_result")).wait_text("Invalid start date"); }); } #[test] fn history_rejects_reversed_period_without_saving() { run("reversed_period", |app| { app.locator(Selector::id("history_btn")).wait_visible().click(); app.locator(Selector::id("period_start")).wait_visible().fill("2026-02-01"); app.locator(Selector::id("period_end")).fill("2026-01-01"); app.locator(Selector::id("capture_budget")).click(); app.locator(Selector::id("history_result")).wait_text("Start must not follow end"); }); } #[test] #[cfg(not(target_os = "android"))] fn capture_button_routes_to_platform_workflow() { run("capture_boundary", |app| { app.locator(Selector::id("history_btn")).wait_visible().click(); app.locator(Selector::id("open_capture")).wait_visible().click(); if budget_capture::desktop::supported() { app.locator(Selector::id("desktop_start")).wait_visible(); } else { app.locator(Selector::id("history_result")).wait_text( "Floating cross-app capture is supported only by the integrated Android build; iOS/desktop do not expose this backend."); } }); } #[test] fn desktop_capture_opens_consent_without_capturing() { run("desktop_consent", |app| { app.locator(Selector::id("desktop_btn")).wait_visible().click(); app.locator(Selector::id("desktop_start")).wait_visible(); app.locator(Selector::id("desktop_ocr")).wait_text("Recognized text will appear here."); app.locator(Selector::id("desktop_discard")).click(); app.locator(Selector::id("desktop_status")).wait_text("Capture discarded. Nothing added. An in-flight worker must finish stopping before retry."); app.locator(Selector::id("planner_btn")).click(); app.locator(Selector::id("history_btn")).click(); app.locator(Selector::id("show_history")).wait_visible(); }); } /// Opt-in: a real isolated X11 fixture, native one-frame capture, real offline /// OCR, editable Makepad review and durable explicit confirmation. No injection /// hook or fake OCR result exists in the production app. #[cfg(all(target_os="linux", not(target_env="ohos")))] #[test] fn desktop_full_capture_review_confirmation_when_opted_in() { if std::env::var("BUDGET_LIVE_X11_TEST").as_deref() != Ok("1") { return; } struct Fixture(std::process::Child); impl Drop for Fixture { fn drop(&mut self) { let _ = self.0.kill(); let _ = self.0.wait(); } } let mut fixture = Fixture(std::process::Command::new("xmessage") .args(["-geometry", "900x250+0+0", "-fn", "10x20", "Budget Test Mouse\nZAR 249.99\nQuantity 2"]) .spawn().expect("xmessage required for isolated capture fixture")); assert!(fixture.0.try_wait().unwrap().is_none()); run("desktop_full_capture", |app| { use makepad_widgets::KeyCode; app.locator(Selector::id("desktop_btn")).wait_visible().click(); app.locator(Selector::id("desktop_start")).wait_visible().click(); app.locator(Selector::id("desktop_status")).wait_text("Review the title. Enter and verify price, currency, quantity, shipping, date and category. Nothing has been added."); app.locator(Selector::id("desktop_start")).assert_enabled(false); // Scroll the outer form beside (not inside) the bounded OCR excerpt. app.scroll_at(395.0, 700.0, 0.0, 600.0, None); for (id, text) in [("desktop_title","Reviewed mouse"), ("desktop_price","249.99"), ("desktop_currency","ZAR"), ("desktop_quantity","2"), ("desktop_shipping","30"), ("desktop_date","2026-10-27"), ("desktop_url","https://example.test/mouse")] { app.locator(Selector::id(id)).fill(text); } app.scroll_at(395.0, 700.0, 0.0, 300.0, None); app.locator(Selector::id("desktop_category")).wait_visible().click().press_key(KeyCode::ArrowDown); app.locator(Selector::id("desktop_item")).wait_visible().click().press_key(KeyCode::ArrowDown); app.locator(Selector::id("desktop_confirm")).wait_visible().click(); app.locator(Selector::id("desktop_status")).wait_text("Confirmed and saved as a planned purchase — not a payment."); app.locator(Selector::id("desktop_start")).assert_enabled(true); }); } /// Exercise the *drawn pixels*, not only the presence of widget IDs. A widget /// snapshot alone would miss the reported "cells only, no chrome/borders" bug. fn planner_chrome(style: &str) { run(&format!("planner_chrome_{style}"), |app| { use makepad_widgets::makepad_draw::ImageBuffer; use std::io::{Read, Write}; // The native window resize endpoint waits for the next drawn frame. // Cover desktop chrome as well as the default narrow/phone layout. for (width, height, command) in [(420, 800, "more_btn"), (1200, 800, "new_btn")] { let mut stream = std::net::TcpStream::connect(app.remote_endpoint()).unwrap(); stream.set_read_timeout(Some(std::time::Duration::from_secs(30))).unwrap(); write!(stream, "GET /w?k=resize&width={width}&height={height}&wait=1 HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n").unwrap(); let mut response = String::new(); stream.read_to_string(&mut response).unwrap(); assert!(response.contains("\"ok\":1"), "resize failed: {response}"); for id in ["planner_btn", "forms_btn", "history_btn", "desktop_btn", command, "formula_input", "tab0"] { app.locator(Selector::id(id)).wait_visible(); } let button = app.locator(Selector::id("planner_btn")).snapshot(); let bar = app.locator(Selector::id("modebar")).snapshot(); let image = ImageBuffer::from_png(&std::fs::read(app.screenshot()).unwrap()).unwrap(); let pixel = |x: i64, y: i64| image.data[y as usize * image.width + x as usize]; assert!(button.width > 10 && button.height > 10); assert_ne!( pixel(button.x + button.width / 2, button.y + button.height - 5), pixel(bar.x + 1, button.y + button.height - 5), "{style}: selected button background is missing at width {width}", ); } // A fresh blank sheet gives an unambiguous border probe, without // Budget's coloured headings/text/selection masquerading as grid lines. app.locator(Selector::id("add_tab")).click(); let grid = app.locator(Selector::id("grid")).wait_visible().snapshot(); let image = ImageBuffer::from_png(&std::fs::read(app.screenshot()).unwrap()).unwrap(); let x = (grid.x + 48 + 96 + 48) as usize; // centre of blank column B let y = (grid.y + 22 + 44) as usize; // skip header and selected row let pixels: Vec = (y..y + 88).map(|row| image.data[row * image.width + x]).collect(); let transitions = pixels.windows(2).filter(|p| p[0] != p[1]).count(); assert!(transitions >= 6, "{style}: blank grid has no repeated horizontal borders ({transitions} transitions)"); // Stock Button actions must still navigate after the rendering changes. app.locator(Selector::id("forms_btn")).click(); app.locator(Selector::id("tab_income")).wait_visible(); app.locator(Selector::id("planner_btn")).click(); app.locator(Selector::id("tab0")).wait_visible().click(); app.locator(Selector::id("formula_input")).wait_visible(); }); } #[test] fn planner_chrome_and_grid_borders_omarchy() { planner_chrome("omarchy"); } #[test] fn planner_chrome_and_grid_borders_macos_style() { planner_chrome("macos"); } /// Real macOS panel smoke test. This does not start screen recording. #[cfg(target_os = "macos")] #[test] fn floating_capture_panel_opens_shared_review() { run("floating_capture_panel", |app| { app.locator(Selector::id("panel_capture").window("capture_panel")).wait_visible(); app.locator(Selector::id("panel_review").window("capture_panel")).click(); app.locator(Selector::id("desktop_start").window("main_window")).wait_visible(); app.locator(Selector::id("panel_status").window("capture_panel")) .wait_text("Ready — capture only when you choose."); }); }