Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge main into #243 (combine with #207's Windows test fixes)

Brandon Thomas2e48f2599715
diff --cc crates/ui-egui/src/headless.rs
index 7e2dc518e,a77e34e71..ac9e619c7
--- a/crates/ui-egui/src/headless.rs
+++ b/crates/ui-egui/src/headless.rs
@@@ -231,6 -231,32 +231,18 @@@ impl Headless
self.paint()
}
- /// Wait for a fixture widget whose background directory listing may still be loading.
- #[cfg(test)]
- pub(crate) fn wait_for_widget(&mut self, id: &str, timeout: Duration) -> bool {
- let start = Instant::now();
- while let Some(remaining) = timeout.checked_sub(start.elapsed()) {
- let reply = self.request("ui.widgets", json!({"filter": id}), remaining);
- if reply["result"].as_array().is_some_and(|widgets| widgets.iter().any(|w| w["id"].as_str() == Some(id))) {
- return true;
- }
- std::thread::sleep(Duration::from_millis(1));
- }
- false
- }
-
+ /// Tests that browse a folder in the temp directory expect it to be a Local location of its
+ /// own. Where the temp directory lies inside the home folder (Windows), the sidebar lists it
+ /// inside Home's tree instead, so hide Home for the test; elsewhere this does nothing.
+ #[cfg(test)]
+ pub(crate) fn hide_home_above(&mut self, path: &std::path::Path) {
+ let home = std::env::var("HOME").or_else(|_| std::env::var("USERPROFILE")).unwrap_or_default();
+ if !home.is_empty() && lightcraft_catalog::query::folder_within(&path.to_string_lossy(), &home) {
+ let r = self.request("engine.execute", json!({"command": "local.hide", "params": {"path": home}}), Duration::from_secs(10));
+ assert_eq!(r["ok"], true, "{r}");
+ }
+ }
+
/// Send a control-protocol request (see [`crate::control`]) and run frames until it is
/// answered, then until its input has been consumed. Returns `{"ok": …, "result"|"error": …}`.
pub fn request(&mut self, method: &str, params: Value, timeout: Duration) -> Value {
@@@ -893,9 -920,10 +906,11 @@@ mod tests
let r = h.request("engine.execute", json!({"command": "library.browse", "params": {"path": path}}), t);
assert_eq!(r["ok"], true, "{r}");
h.settle(SETTLE);
- assert!(h.wait_for_widget(&format!("source:local:{path}"), t), "the browsed folder is listed: {:?}", ids(&mut h));
+ let row = format!("source:local:{path}");
+ assert!(h.step_until(t, |h| h.app.widgets.iter().any(|(w, _)| *w == row)), "the browsed folder is listed: {:?}", ids(&mut h));
- assert!(!ids(&mut h).iter().any(|i| i == "source:local:restoreHidden"));
+ // the "Show hidden locations" row appears only while something is hidden
+ let hidden_before = !h.app.ui.hidden_locations.is_empty();
+ assert_eq!(ids(&mut h).iter().any(|i| i == "source:local:restoreHidden"), hidden_before);
// hide it while it is still being browsed
let r = h.request("engine.execute", json!({"command": "local.hide", "params": {"path": path}}), t);
assert_eq!(r["ok"], true, "{r}");