use super::super::render;
use super::fixture::{World, world};
use super::input;
use crate::cli_outbound::Cli;
use crate::paint_probe::Painted;
struct Window {
ctx: egui::Context,
lernie: Cli,
bl: Cli,
bz: Cli,
}
impl Window {
fn new() -> Self {
Self {
ctx: egui::Context::default(),
lernie: Cli::new("yog-absent-lernie"),
bl: Cli::new("yog-absent-bl"),
bz: Cli::new("yog-absent-bz"),
}
}
fn settled(&self, world: &mut World) -> Vec<Painted> {
self.settled_on(world, input())
}
fn settled_on(&self, world: &mut World, raw: egui::RawInput) -> Vec<Painted> {
let mut out = None;
for _ in 0..4 {
out = Some(self.ctx.run(raw.clone(), |ctx| {
render(
ctx,
&mut world.model,
&mut world.state,
&self.lernie,
&self.bl,
&self.bz,
);
}));
}
crate::paint_probe::painted_of(&out.expect("four frames ran"))
}
fn panel(&self, id: &str) -> egui::Rect {
egui::containers::panel::PanelState::load(&self.ctx, egui::Id::new(id))
.expect("the panel stores its rect")
.rect
}
}
fn all(painted: &[Painted], needle: &str) -> Vec<egui::Rect> {
painted
.iter()
.filter(|(text, _)| text.contains(needle))
.map(|(_, rect)| *rect)
.collect()
}
fn one(painted: &[Painted], needle: &str) -> egui::Rect {
*all(painted, needle)
.first()
.unwrap_or_else(|| panic!("{needle:?} not painted"))
}
#[test]
fn a_conversations_settings_rows_sit_below_the_composer_at_the_pane_foot() {
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
let win = Window::new();
let painted = win.settled(&mut world);
let seat = win.panel("conversation-settings");
let composer = win.panel("composer");
assert!(
seat.top() >= composer.bottom() - 1.0,
"the settings rows sit below the goal box (bl-58e4): seat {seat:?} vs composer {composer:?}"
);
let budgets = all(&painted, "budget ");
assert!(
!budgets.is_empty(),
"the spend figures reach the paint layer"
);
for figure in &budgets {
assert!(
figure.top() >= seat.top() - 1.0,
"a spend figure paints above the settings seat: {figure:?} vs {seat:?}"
);
}
let model = one(&painted, "(none)");
assert!(
model.top() >= seat.top() - 1.0,
"the model dropdown sits in the bottom seat: {model:?} vs {seat:?}"
);
assert!(
all(&painted, "change…").is_empty(),
"the row is the selection: nothing to press before the dropdowns"
);
let name = one(&painted, "hello");
assert!(
name.bottom() <= seat.top(),
"the identity header leads the surface: {name:?} vs {seat:?}"
);
}
#[test]
fn an_empty_selection_answers_the_same_question_in_the_same_seat() {
let mut world = world();
let ws = world.ws.clone();
world.model.focus_workspace(&ws);
let win = Window::new();
let painted = win.settled(&mut world);
let seat = win.panel("conversation-settings");
for row in ["work directory:", "(none)"] {
let rect = one(&painted, row);
assert!(
rect.top() >= seat.top() - 1.0,
"{row:?} belongs to the settings seat: {rect:?} vs {seat:?}"
);
}
assert!(
all(&painted, "context ").is_empty(),
"no conversation, no context figure"
);
let composer = win.panel("composer");
assert!(
seat.top() >= composer.bottom() - 1.0,
"and the empty seat takes the same side of the box as the full one \
(bl-58e4): {seat:?} vs {composer:?}"
);
}
#[test]
fn an_expanded_picker_cannot_grow_the_seat_past_half_the_pane() {
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
let win = Window::new();
let collapsed = {
win.settled(&mut world);
win.panel("conversation-settings").height()
};
world.state.wall.picker.open = true;
win.settled(&mut world);
let expanded = win.panel("conversation-settings");
assert!(
expanded.height() > collapsed,
"the picker does open inline at the line: {collapsed} → {}",
expanded.height()
);
let window = input().screen_rect.expect("the probe sizes the screen");
assert!(
expanded.height() <= window.height() / 2.0,
"and the seat stays under half the pane: {} of {}",
expanded.height(),
window.height()
);
}
#[test]
fn the_seat_is_bounded_at_the_smallest_supported_window_too() {
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
let win = Window::new();
win.settled_on(&mut world, crate::paint_probe::screen_sized(420.0, 320.0));
world.state.wall.picker.open = true;
win.settled_on(&mut world, crate::paint_probe::screen_sized(420.0, 320.0));
let seat = win.panel("conversation-settings");
assert!(
seat.height() <= 320.0 / 2.0,
"an open picker may not take more than half the pane: {}",
seat.height()
);
}
#[test]
fn a_conversation_states_how_full_its_context_is_beneath_what_it_has_spent() {
let mut world = world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
let win = Window::new();
let painted = win.settled(&mut world);
let seat = win.panel("conversation-settings");
let context = one(&painted, "context 25%");
assert!(
context.top() >= seat.top() - 1.0,
"the context figure belongs to the settings seat: {context:?} vs {seat:?}"
);
one(&painted, "(50000 / 200000 tok · m)");
let spend = one(&painted, "budget ");
assert!(
spend.bottom() <= context.bottom(),
"spend leads, fullness follows: {spend:?} vs {context:?}"
);
}