use super::fixture::world;
use super::screen::{Screen, click, command_shift, locate, press, rect_of};
use crate::keymap::CenterTab;
#[test]
fn a_combo_focuses_config_from_inside_the_box_and_escape_comes_home() {
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
let screen = Screen::new();
assert!(
screen.idle(&mut world),
"the keyboard rests in the composer"
);
world.state.actions.drafts.set(
crate::actions::DraftKey::Message("c-1".to_owned()),
"half a sentence".to_owned(),
);
screen.frame(&mut world, vec![press(egui::Key::Num2, command_shift())]);
assert_eq!(
world.state.center,
CenterTab::Config,
"Ctrl+Shift+2 focuses the Config tab without the box letting go first"
);
screen.frame(
&mut world,
vec![press(egui::Key::Escape, egui::Modifiers::NONE)],
);
assert_eq!(
world.state.center,
CenterTab::Conversation,
"Escape dismisses the tab (QUALITY F3)"
);
assert_eq!(
world
.state
.actions
.drafts
.text(&crate::actions::DraftKey::Message("c-1".to_owned())),
"half a sentence",
"and loses nothing typed"
);
}
#[test]
fn every_peer_is_reachable_from_every_tab_and_no_tab_paints_over_the_composer() {
let (lernie, bl) = (
crate::cli_outbound::Cli::new("lernie"),
crate::cli_outbound::Cli::new("bl"),
);
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
let home = super::painted(&mut world, &lernie, &bl);
for tab in ["Conversation", "Config", "Login"] {
assert!(
home.lines().any(|line| line == tab),
"the strip offers {tab} from the conversation:\n{home}"
);
}
assert!(
home.contains("Message"),
"the conversation carries its composer:\n{home}"
);
crate::shell::center::focus(&world.model, &mut world.state, CenterTab::Config);
let config = super::painted(&mut world, &lernie, &bl);
for tab in ["Conversation", "Config", "Login"] {
assert!(
config.lines().any(|line| line == tab),
"and still offers {tab} from the Config tab:\n{config}"
);
}
assert!(
config.contains("brazen config.toml"),
"which is showing the editors:\n{config}"
);
assert!(
!config.contains("→ message hello"),
"the composer belongs to the conversation, so it is absent — not \
buried under a full-cover pane:\n{config}"
);
assert!(
!config.contains("pong reply"),
"and the transcript is not painted over, it is simply not this tab"
);
}
#[test]
fn the_login_rows_paint_in_the_center_not_in_the_roster_column() {
let mut world = world();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
let seat = locate(&screen.shapes(&mut world, Vec::new()), "Login")
.expect("the left panel's Login entry reaches the paint layer");
click(&screen, &mut world, seat);
assert_eq!(world.state.center, CenterTab::Login, "the entry focuses it");
let shapes = screen.shapes(&mut world, Vec::new());
let column = rect_of(&shapes, "new conversation")
.expect("the roster's own header marks the column")
.right();
let rows = rect_of(&shapes, "Login (bz browser sign-in)")
.expect("the Login surface reaches the paint layer");
assert!(
rows.left() > column,
"the provider rows must sit right of the roster column ({} vs {column})",
rows.left()
);
}
#[test]
fn no_tab_lays_off_window_at_either_capture() {
for (w, h) in [(420.0, 320.0), (1600.0, 2400.0)] {
let (lernie, bl, bz) = (
crate::cli_outbound::Cli::new("yog-absent-lernie"),
crate::cli_outbound::Cli::new("yog-absent-bl"),
crate::cli_outbound::Cli::new("yog-absent-bz"),
);
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
world.model.search("hello");
world.searches();
let ctx = egui::Context::default();
let raw = crate::paint_probe::screen_sized(w, h);
let mut out = None;
for _ in 0..4 {
out = Some(ctx.run(raw.clone(), |ctx| {
crate::shell::render(ctx, &mut world.model, &mut world.state, &lernie, &bl, &bz);
}));
}
let shapes = out.expect("four frames ran").shapes;
for tab in CenterTab::all() {
let rect = rect_of(&shapes, tab.label())
.unwrap_or_else(|| panic!("{tab:?} paints nothing at {w}x{h}"));
assert!(
rect.right() <= w + 1.0 && rect.bottom() <= h + 1.0 && rect.left() >= -1.0,
"{tab:?} lays off a {w}x{h} window: {rect:?}"
);
}
}
}