use super::super::{login_pane, start_rows};
use super::fixture::world;
use crate::cli_outbound::Cli;
use crate::config_edit::brazen::ProviderRowView;
use crate::paint_probe::{self, Painted};
use crate::projects::join::JoinState;
use crate::start::{BallSpec, Payload, StartInputs};
const PANEL: f32 = 240.0;
fn in_a_bounded_panel(body: impl FnOnce(&mut egui::Ui)) -> Vec<Painted> {
let ctx = egui::Context::default();
let mut body = Some(body);
let out = ctx.run(paint_probe::screen_sized(600.0, 400.0), |ctx| {
egui::SidePanel::left("bounded")
.exact_width(PANEL)
.show(ctx, |ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate);
if let Some(body) = body.take() {
body(ui);
}
});
});
paint_probe::painted_of(&out)
}
fn in_a_seat_with_no_wrap_mode(body: impl FnOnce(&mut egui::Ui)) -> Vec<Painted> {
let ctx = egui::Context::default();
let mut body = Some(body);
let out = ctx.run(paint_probe::screen_sized(PANEL, 400.0), |ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
if let Some(body) = body.take() {
body(ui);
}
});
});
paint_probe::painted_of(&out)
}
fn says(painted: &[Painted]) -> String {
let mut out = String::new();
for (text, _) in painted {
out.push_str(text);
out.push('\n');
}
out
}
fn assert_inside_the_panel(painted: &[Painted]) {
for (text, rect) in painted {
assert!(
rect.right() <= PANEL + 1.0,
"`{text}` is laid past the panel edge at {}",
rect.right()
);
}
}
#[test]
fn the_login_verb_stays_whole_on_the_row_whose_name_would_have_eaten_it() {
let painted = in_a_bounded_panel(|ui| {
login_pane::provider_row(
ui,
&ProviderRowView {
name: "claude-session-direct".to_owned(),
fact: "auth oauth2 · not signed in".to_owned(),
blocked: None,
},
);
});
let said = says(&painted);
assert!(
said.contains("Login"),
"the verb is on screen whole, not a bare `…`:\n{said}"
);
assert!(
!said.contains("auth oauth2 · not signed in"),
"and the row really was over-full — the fact beside it elided:\n{said}"
);
assert!(
said.contains("claude-session-direct"),
"the name, which is the row's identity, survives:\n{said}"
);
assert_inside_the_panel(&painted);
}
#[test]
fn the_assign_verb_stays_whole_behind_a_ball_title_of_any_length() {
let (lernie, bl) = (Cli::new("lernie"), Cli::new("bl"));
let mut world = world();
let ws = world.ws.clone();
let inputs = StartInputs {
workspace: ws.clone(),
payload: Payload::Ball {
project: ws.clone(),
ball: BallSpec::Existing {
id: "bl-b5ce".to_owned(),
title: "epic: the inspector rework".to_owned(),
body: String::new(),
join: JoinState::ReadyStartable,
},
},
home: ws.clone(),
yog_data_root: world.yog_data.clone(),
balls_state_root: ws,
conversation_names: Vec::new(),
};
let to = world
.model
.focused_ws_name()
.expect("the fixture focuses a workspace");
let painted = in_a_bounded_panel(|ui| {
start_rows::ready_row(ui, &mut world.model, &mut world.state, &lernie, &bl, inputs);
});
let said = says(&painted);
assert!(
said.contains(&format!("assign → {to}")),
"the assign verb names its target whole:\n{said}"
);
assert!(
!said.contains("epic: the inspector rework"),
"and the row really was over-full — the ▶ label elided:\n{said}"
);
assert!(
said.contains("▶ bl-b5ce"),
"keeping the verb glyph and the ball id at its head:\n{said}"
);
assert_inside_the_panel(&painted);
}
#[test]
fn the_row_truncates_itself_in_a_seat_that_declares_no_wrap_mode() {
let painted = in_a_seat_with_no_wrap_mode(|ui| {
login_pane::provider_row(
ui,
&ProviderRowView {
name: "openai-chatgpt".to_owned(),
fact: "auth bearer · no credential stored".to_owned(),
blocked: Some("bearer-token provider — set the token in Config".to_owned()),
},
);
});
let said = says(&painted);
assert!(
said.contains("bearer-token provider — set the token in Config"),
"the reason there is no verb stays whole:\n{said}"
);
assert!(
!said.contains("auth bearer · no credential stored"),
"and the fact beside it elided rather than extending:\n{said}"
);
for (i, (a_text, a)) in painted.iter().enumerate() {
for (b_text, b) in painted.iter().skip(i + 1) {
assert!(
!a.intersects(*b),
"`{a_text}` and `{b_text}` share pixels: {a:?} vs {b:?}"
);
}
}
assert_inside_the_panel(&painted);
}