use super::super::transcript::BlockKind;
use super::support::{empty_app, fixed_status, render_buffer};
#[test]
fn sending_a_new_request_folds_the_finished_chapter_on_screen() {
use super::super::application::tests_support::idle_app;
let mut app = idle_app();
app.input.set_text("count the red orders");
app.submit();
app.pending = None;
app.transcript
.push(BlockKind::Assistant, "the red orders total 42");
app.input.set_text("and the blue ones");
app.submit();
app.pending = None;
assert!(
app.transcript.is_folded(1),
"the finished chapter folds when the next request starts"
);
let screen = render_buffer(&app, &fixed_status(), 80, 24);
assert!(
screen.contains("count the red orders"),
"the folded screen keeps the verbatim request:\n{screen}"
);
assert!(
!screen.contains("the red orders total 42"),
"the hidden answer leaves the screen:\n{screen}"
);
}
const ENTER_SENDS_HINT: &str = "Enter sends";
const MULTILINE_SENDS_HINT: &str = "Enter sends all";
const NEWLINE_HINT: &str = "Alt+Enter";
#[test]
fn the_composer_says_what_enter_does_while_typing() {
let mut app = empty_app();
app.input.set_text("how many orders yesterday");
let buffer = render_buffer(&app, &fixed_status(), 80, 24);
assert!(
buffer.contains(ENTER_SENDS_HINT),
"a single-line draft states that Enter sends:\n{buffer}"
);
assert!(
!buffer.contains(NEWLINE_HINT),
"a single-line draft does not name the newline chord:\n{buffer}"
);
}
#[test]
fn a_multiline_draft_warns_that_enter_sends_every_line() {
let mut app = empty_app();
app.input.set_text("select *\nfrom orders\nlimit 10");
let buffer = render_buffer(&app, &fixed_status(), 80, 24);
assert!(
buffer.contains(MULTILINE_SENDS_HINT),
"a multiline draft warns Enter sends every line:\n{buffer}"
);
assert!(
buffer.contains(NEWLINE_HINT),
"a multiline draft names Alt+Enter for a new line:\n{buffer}"
);
}
#[test]
fn a_pasted_block_stays_editable_instead_of_submitting() {
let mut app = empty_app();
app.paste("line one\nline two\nline three");
assert_eq!(
app.input.lines(),
vec!["line one", "line two", "line three"],
"the pasted block holds all three lines as an editable draft"
);
assert!(app.pending.is_none(), "pasting must not submit anything");
assert!(
app.transcript.blocks().is_empty(),
"pasting must not append to the transcript"
);
}
#[test]
fn the_draft_survives_opening_and_closing_an_overlay() {
use super::super::keys::handle_key;
use ratatui::crossterm::event::{KeyCode, KeyModifiers};
let mut app = empty_app();
app.input.set_text("select * from orders");
handle_key(&mut app, KeyCode::F(1), KeyModifiers::NONE);
assert!(
app.overlays.show_help,
"F1 opens the help overlay while a draft is held"
);
handle_key(&mut app, KeyCode::Esc, KeyModifiers::NONE);
assert!(!app.overlays.show_help, "Esc closes the help overlay");
assert_eq!(
app.input.text(),
"select * from orders",
"the draft survives opening and closing the overlay"
);
}