use super::super::focus;
use super::fixture::{world, world_empty};
use super::screen::{Screen, command_shift, press};
const BOOTSTRAP_INVITATION: &str = "start a conversation:";
const SELECT_A_CONVERSATION: &str = "select a conversation";
#[test]
fn launch_lands_the_keyboard_in_the_composer() {
let mut world = world();
assert!(
world.state.focus_composer,
"a fresh ShellState carries the launch request"
);
let screen = Screen::new();
assert!(
screen.idle(&mut world),
"the first frame hands the keyboard to the composer"
);
assert!(
!world.state.focus_composer,
"and spends the request rather than re-grabbing every frame"
);
}
#[test]
fn the_empty_world_bootstrap_takes_the_launch_request_too() {
let mut world = world_empty();
let screen = Screen::new();
let painted = screen.text(&mut world);
for run in [crate::theme::TAGLINE, BOOTSTRAP_INVITATION] {
assert!(
painted.contains(run),
"`{run}` is the bootstrap's own — this is not the bootstrap frame:\n{painted}"
);
}
assert!(
!painted.contains(SELECT_A_CONVERSATION),
"and the conversation centre is not up beside it:\n{painted}"
);
assert!(
screen.idle(&mut world),
"the bootstrap box takes the keyboard"
);
}
#[test]
fn opening_a_conversation_by_pointer_hands_over_the_keyboard() {
let mut world = world();
let ws = world.ws.clone();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
focus::conversation(&mut world.model, &mut world.state, &ws, "c-1");
assert!(
screen.idle(&mut world),
"the click that selected the conversation put the cursor in the box"
);
}
#[test]
fn switching_workspace_by_pointer_hands_over_the_keyboard() {
let mut world = world();
let ws = world.ws.clone();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
focus::workspace(&mut world.model, &mut world.state, &ws);
assert!(screen.idle(&mut world), "and the tab click does too");
}
#[test]
fn escape_with_nothing_pending_does_not_re_grab() {
let mut world = world();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
assert!(
!screen.idle(&mut world),
"the release holds — Escape then `i` is the §11 idiom, and `i` is a key"
);
}
#[test]
fn i_and_ctrl_i_jump_the_keyboard_to_the_composer() {
let mut world = world();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
screen.frame(&mut world, vec![press(egui::Key::I, egui::Modifiers::NONE)]);
assert!(screen.idle(&mut world), "bare `i` claims the box");
screen.release(&mut world);
screen.frame(
&mut world,
vec![press(egui::Key::I, egui::Modifiers::COMMAND)],
);
assert!(screen.idle(&mut world), "and so does Ctrl+I");
}
#[test]
fn the_new_workspace_form_claims_the_keyboard_but_ctrl_i_can_take_it_back() {
let mut world = world();
let screen = Screen::new();
screen.idle(&mut world);
screen.frame(&mut world, vec![press(egui::Key::N, command_shift())]);
assert!(
world.state.new_ws.open,
"Ctrl+Shift+N opened the §11 name form (the precondition, not the claim)"
);
assert!(screen.idle(&mut world), "the form holds the keyboard");
screen.frame(
&mut world,
vec![press(egui::Key::I, egui::Modifiers::COMMAND)],
);
assert!(
screen.idle(&mut world),
"and Ctrl+I still reaches the composer from inside it"
);
}
#[test]
fn a_dismissed_modal_hands_the_keyboard_back() {
let mut world = world();
let ws = world.ws.clone();
let screen = Screen::new();
screen.idle(&mut world);
screen.release(&mut world);
assert!(
world.model.delete_confirmation(&ws).is_none(),
"the fixture workspace is foreign — §3.6 offers no confirmation on it, \
which is what makes its dialog close on the frame it opens"
);
super::super::delete::open(&mut world.state, &ws);
assert!(
!screen.idle(&mut world),
"the modals paint last, so the frame that dismisses one has already \
drawn the composer: the request is for the frame after"
);
assert!(world.state.delete.target.is_none(), "and it did dismiss");
assert!(
screen.idle(&mut world),
"the next frame puts the cursor back in the box"
);
}
#[test]
fn sending_a_message_keeps_the_keyboard() {
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
world.state.actions.drafts.set(
crate::actions::DraftKey::Message("c-1".to_owned()),
"ping".to_owned(),
);
let screen = Screen::new();
assert!(screen.idle(&mut world), "the cursor starts in the box");
screen.frame(
&mut world,
vec![press(egui::Key::Enter, egui::Modifiers::NONE)],
);
assert!(
screen.idle(&mut world),
"the send left the cursor where the next message gets typed"
);
}
#[test]
fn a_request_is_spent_once() {
let mut world = world();
assert!(world.state.focus_composer, "launch stands the request up");
let screen = Screen::new();
screen.idle(&mut world);
assert!(!world.state.focus_composer, "the composer spent it");
focus::request(&mut world.state);
focus::request(&mut world.state);
assert!(world.state.focus_composer, "asking twice is asking once");
screen.idle(&mut world);
assert!(!world.state.focus_composer, "and one frame clears it");
}