use super::fixture::world;
use crate::keymap::CenterTab;
#[test]
fn the_search_tab_is_offered_with_an_answer_and_goes_when_the_answer_does() {
let (lernie, bl) = (
crate::cli_outbound::Cli::new("lernie"),
crate::cli_outbound::Cli::new("bl"),
);
let mut world = world();
let quiet = super::painted(&mut world, &lernie, &bl);
assert!(
!quiet.lines().any(|line| line == "Search"),
"no answer, no tab:\n{quiet}"
);
let key = crate::actions::DraftKey::composer(Some(world.ws.clone()), None);
world
.state
.actions
.drafts
.set(key.clone(), "/search hello".to_owned());
assert!(crate::shell::slash::run(
&mut world.model,
&mut world.state,
&lernie,
&bl,
&key,
"/search hello"
));
assert_eq!(
world.state.center,
CenterTab::Search,
"asking focuses the answer's tab — the ask is the operator's one gesture"
);
world.searches();
let answered = super::painted(&mut world, &lernie, &bl);
assert!(
answered.lines().any(|line| line == "Search"),
"the tab is offered while there is an answer:\n{answered}"
);
assert!(crate::shell::slash::run(
&mut world.model,
&mut world.state,
&lernie,
&bl,
&key,
"/search"
));
world.searches();
let cleared = super::painted(&mut world, &lernie, &bl);
assert!(
!cleared.lines().any(|line| line == "Search"),
"a cleared answer retires its tab:\n{cleared}"
);
assert_eq!(
world.state.center,
CenterTab::Conversation,
"and the center is home again"
);
}
#[test]
fn a_search_that_matches_nothing_says_so_and_keeps_its_tab() {
let (lernie, bl) = (
crate::cli_outbound::Cli::new("lernie"),
crate::cli_outbound::Cli::new("bl"),
);
let mut world = world();
let key = crate::actions::DraftKey::composer(Some(world.ws.clone()), None);
assert!(crate::shell::slash::run(
&mut world.model,
&mut world.state,
&lernie,
&bl,
&key,
"/search zzzznotathing"
));
world.searches();
let painted = super::painted(&mut world, &lernie, &bl);
assert_eq!(
world.state.center,
CenterTab::Search,
"the operator stays on the answer they asked for:\n{painted}"
);
assert!(
painted.lines().any(|line| line == "Search"),
"and its tab is still offered:\n{painted}"
);
assert!(
painted
.lines()
.any(|line| line == "no matches for `zzzznotathing`"),
"the pane names the absence with the needle in it:\n{painted}"
);
assert!(
painted
.lines()
.any(|line| line == crate::search::SEARCHED_EVERYTHING),
"and names the paved path in full:\n{painted}"
);
}