Files
imeai-aKode/akode-rs/tui/src/tooltips/keybinding_tests.rs
andrea.difonzo 7c1c6dfa8d Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
  nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 12:37:52 +01:00

114 lines
3.9 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Tooltip placeholders follow current keybindings and chords, render safely as Markdown,
//! and suppress tips when any referenced shortcut is invalid or unbound.
use super::*;
use pretty_assertions::assert_eq;
use serde_json::json;
#[test]
fn configured_shortcut_tips_render_at_narrow_width() {
let config = serde_json::from_value(json!({
"global": {
"open_transcript": ["ctrl-x t", "f12"],
"find_transcript": "ctrl-x f",
"open_external_editor": "ctrl-x e",
"copy": "ctrl-x `"
},
"composer": {
"history_search_previous": "ctrl-x r",
"queue": "ctrl-x q"
},
"chat": {
"open_presets": "ctrl-x p",
"increase_reasoning_effort": "ctrl-x +",
"decrease_reasoning_effort": "ctrl-x minus"
}
}))
.unwrap();
let keymap = RuntimeKeymap::from_config(&config).unwrap();
let mut lines = Vec::new();
for (label, keymap) in [("Default", RuntimeKeymap::defaults()), ("Remapped", keymap)] {
lines.push(label.into());
for template in TOOLTIPS.iter().filter(|tip| tip.contains("{key:")) {
let tip = render_tooltip(template, Some(&keymap)).expect("valid shortcut tip");
crate::markdown::append_markdown(
&format!("**Tip:** {tip}"),
Some(40),
/*cwd*/ None,
&mut lines,
);
lines.push("".into());
}
}
// This snapshot owns the preset hint's content and layout; Markdown tests own the
// terminal-default foreground applied to the shared "Tip:" prefix.
for line in lines
.iter_mut()
.filter(|line| line.to_string().contains("then 0–9"))
{
line.spans[0].style.fg = None;
}
insta::assert_snapshot!(
lines
.iter()
.map(|line| format!("{line:?}"))
.collect::<Vec<_>>()
.join("\n")
);
}
#[test]
fn skips_unbound_or_invalid_placeholders() {
let config = serde_json::from_value(json!({ "global": { "copy": [] } })).unwrap();
let keymap = RuntimeKeymap::from_config(&config).unwrap();
for template in [
"Press {key:global.copy} to copy.",
"Press {key:global.open_transcript} or {key:global.copy}.",
"Press {key:global.missing}.",
"Press {key:missing.copy}.",
"Press {key:copy}.",
"Press {key:global.copy",
] {
assert_eq!(render_tooltip(template, Some(&keymap)), None, "{template}");
}
assert_eq!(
render_tooltip("Press {key:global.copy}.", /*keymap*/ None),
None
);
assert_eq!(
render_tooltip("Use /copy to copy a response.", /*keymap*/ None),
Some("Use /copy to copy a response.".to_string())
);
}
#[test]
fn reasoning_tip_requires_both_bindings() {
let template = TOOLTIPS
.iter()
.find(|tip| tip.contains("{key:chat.increase_reasoning_effort}"))
.unwrap();
for action in ["increase_reasoning_effort", "decrease_reasoning_effort"] {
let config = serde_json::from_value(json!({ "chat": { action: [] } })).unwrap();
let keymap = RuntimeKeymap::from_config(&config).unwrap();
assert_eq!(render_tooltip(template, Some(&keymap)), None);
}
}
#[test]
fn subsequent_tips_reflect_remapped_bindings() {
for (configured, label) in [
(json!("f12"), Some("f12")),
(json!(["ctrl-x t", "f12"]), Some("⌃x t")),
(json!([]), None),
] {
let config =
serde_json::from_value(json!({ "global": { "open_transcript": configured } })).unwrap();
let keymap = RuntimeKeymap::from_config(&config).unwrap();
assert_eq!(
resolved_tooltips(Some(&keymap))
.find(|tip| tip.ends_with(" to open the full transcript.")),
label.map(|label| format!("Press `` {label} `` to open the full transcript."))
);
}
}