use crate::paint_probe::frame::Window;
use crate::reply::transcript::{Entry, EntryKind, Transcript};
use crate::test_support::window::{click, numbered, seated, seen};
use crate::ui::Model;
const LINES: usize = 700;
fn spilling(n: usize) -> Model {
let content = numbered(n);
let mut model = seated();
model.transcript = Transcript {
entries: vec![Entry {
name: "004-tool.json".to_owned(),
raw: content.clone(),
kind: EntryKind::ToolResult {
tool_use_id: "toolu_1".to_owned(),
content,
is_error: false,
},
}],
};
model
}
fn glass(window: &Window, model: &mut Model) -> Vec<String> {
window.frame(Vec::new(), |ctx| crate::ui::render(ctx, model));
seen(window, |ctx| crate::ui::render(ctx, model))
.into_iter()
.map(|shown| shown.text)
.collect()
}
fn control(n: usize) -> String {
format!("show all {n} lines, {} bytes", numbered(n).len())
}
const FEW: usize = 12;
#[test]
fn a_long_tool_result_stands_as_a_few_lines_and_one_control_saying_what_it_hides() {
let mut model = spilling(LINES);
let window = Window::sized(1400.0, 900.0);
let glyphs = glass(&window, &mut model);
let painted = glyphs.concat();
assert!(painted.contains("line 001"), "{glyphs:?}");
assert!(painted.contains("line 006"), "{glyphs:?}");
assert!(!painted.contains("line 007"), "the rest is folded away");
assert!(!painted.contains("line 700"), "including its tail");
assert!(
glyphs.iter().any(|run| *run == control(LINES)),
"the control says the act and the size: {glyphs:?}"
);
}
#[test]
fn the_control_brings_the_whole_of_it_and_the_other_one_puts_it_back() {
let mut model = spilling(FEW);
let window = Window::sized(1400.0, 900.0);
let folded = glass(&window, &mut model).concat();
assert!(!folded.contains("line 007"), "folded to start with");
click(&window, &control(FEW), |ctx| {
crate::ui::render(ctx, &mut model);
});
let opened = glass(&window, &mut model).concat();
assert!(
opened.contains("line 012"),
"the whole of it is on the glass"
);
assert!(
opened.contains(super::super::fold::UNFOLD),
"and the control names the other act now"
);
click(&window, super::super::fold::UNFOLD, |ctx| {
crate::ui::render(ctx, &mut model);
});
let closed = glass(&window, &mut model).concat();
assert!(!closed.contains("line 007"), "and it folds again");
}