diff --git a/cli/src/commands.rs b/cli/src/commands.rs index d7e1e6d..cb90f63 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -614,17 +614,44 @@ fn parse_command_inner(args: &[String], flags: &Flags) -> Result().ok()); + + if let Some(arg) = positional { if let Ok(timeout) = arg.parse::() { Ok(json!({ "id": id, "action": "wait", "timeout": timeout })) } else { - Ok(json!({ "id": id, "action": "wait", "selector": arg })) + let mut cmd = json!({ "id": id, "action": "wait", "selector": arg }); + if let Some(state) = state_override { + cmd["state"] = json!(state); + } + if let Some(t) = timeout_ms { + cmd["timeout"] = json!(t); + } + Ok(cmd) } } else { Err(ParseError::MissingArguments { context: "wait".to_string(), - usage: "wait ", + usage: "wait [--gone|--hidden] [--timeout ms]", }) } } @@ -5185,4 +5212,47 @@ mod tests { let cmd = parse_command(&args("find role button"), &default_flags()).unwrap(); assert_eq!(cmd["subaction"], "click"); } + + // === wait --gone / --hidden === + + #[test] + fn test_wait_selector_default_visible() { + let cmd = parse_command(&args("wait .toast"), &default_flags()).unwrap(); + assert_eq!(cmd["action"], "wait"); + assert_eq!(cmd["selector"], ".toast"); + assert!(cmd.get("state").is_none(), "default state stays implicit"); + } + + #[test] + fn test_wait_selector_gone_sets_detached_state() { + let cmd = parse_command(&args("wait .toast --gone"), &default_flags()).unwrap(); + assert_eq!(cmd["selector"], ".toast"); + assert_eq!(cmd["state"], "detached"); + } + + #[test] + fn test_wait_selector_hidden_sets_hidden_state() { + let cmd = parse_command(&args("wait .toast --hidden"), &default_flags()).unwrap(); + assert_eq!(cmd["state"], "hidden"); + } + + #[test] + fn test_wait_gone_with_timeout() { + let cmd = parse_command( + &args("wait .modal --gone --timeout 2000"), + &default_flags(), + ) + .unwrap(); + assert_eq!(cmd["selector"], ".modal"); + assert_eq!(cmd["state"], "detached"); + assert_eq!(cmd["timeout"], 2000); + } + + #[test] + fn test_wait_numeric_timeout_still_works() { + // `wait 500` keeps meaning "sleep 500ms", not "wait for selector 500" + let cmd = parse_command(&args("wait 500"), &default_flags()).unwrap(); + assert_eq!(cmd["timeout"], 500); + assert!(cmd.get("selector").is_none()); + } }