77 lines
2.6 KiB
Rust
77 lines
2.6 KiB
Rust
//! tip: the cheat sheet page (render, JSON, --random, REPL completion).
|
|
|
|
mod common;
|
|
|
|
use agent_manager::cli::Cli;
|
|
use agent_manager::commands::tip_cmd;
|
|
use clap::Parser;
|
|
|
|
#[test]
|
|
fn tip_page_renders_header_sections_and_options() {
|
|
// Issue #74: the page follows the locale; force French here so the
|
|
// assertions are deterministic whatever the host LANG says.
|
|
let app = common::test_app("tip", &["--lang", "fr", "tip"]);
|
|
let text = tip_cmd::render(&app, false);
|
|
assert!(text.contains("TIP"), "header missing:\n{text}");
|
|
assert!(text.contains("antisèche"), "subtitle missing:\n{text}");
|
|
for title in [
|
|
"Lancer & piloter",
|
|
"Installer & maintenir",
|
|
"Observer",
|
|
"Personnaliser",
|
|
"Boîte à outils",
|
|
] {
|
|
assert!(text.contains(title), "missing section '{title}':\n{text}");
|
|
}
|
|
assert!(text.contains("start <agent>"), "missing usage line");
|
|
assert!(text.contains("--background"), "missing option");
|
|
assert!(text.contains("Le saviez-vous"), "missing tip of the day");
|
|
assert!(
|
|
text.contains("Vos commandes les plus utilisées"),
|
|
"missing personal section"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn tip_json_output_is_structured() {
|
|
let app = common::test_app("tip-json", &["tip", "--json"]);
|
|
let text = tip_cmd::render(&app, false);
|
|
let v: serde_json::Value = serde_json::from_str(&text).expect("valid JSON output");
|
|
assert!(v["sections"].is_array(), "sections missing");
|
|
assert_eq!(v["sections"].as_array().unwrap().len(), 5);
|
|
assert!(v["tip"]["title"].is_string());
|
|
assert!(v["tip"]["body"].is_string());
|
|
assert!(v["most_used"].is_array());
|
|
}
|
|
|
|
#[test]
|
|
fn tip_random_prints_a_single_tip() {
|
|
let app = common::test_app("tip-rnd", &["tip", "--random"]);
|
|
let text = tip_cmd::render(&app, true);
|
|
assert!(text.contains("💡"), "random tip missing: {text}");
|
|
assert!(!text.contains("antisèche"), "random mode must not print the page");
|
|
}
|
|
|
|
#[test]
|
|
fn tip_run_succeeds() {
|
|
let app = common::test_app("tip-run", &["tip"]);
|
|
assert_eq!(tip_cmd::run(&app, false).unwrap(), 0);
|
|
}
|
|
|
|
#[test]
|
|
fn cli_parses_tip_flags() {
|
|
let cli = Cli::parse_from(["am", "tip", "--random"]);
|
|
match cli.command {
|
|
Some(agent_manager::cli::Command::Tip { random }) => assert!(random, "--random must be parsed"),
|
|
other => panic!("unexpected command: {other:?}"),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn repl_completion_proposes_tip() {
|
|
let app = common::test_app("tip-comp", &["list"]);
|
|
let c = agent_manager::repl::AmCompleter::new(&app);
|
|
let (_, cands) = c.candidates_for("ti", 2);
|
|
assert!(cands.contains(&"tip".to_string()), "candidates: {cands:?}");
|
|
}
|