use super::super::{ShellState, render};
use super::fixture::World;
use crate::AppModel;
use crate::cli_outbound::Cli;
use crate::keymap::InspectorTab;
pub(super) fn wired(
world: &mut World,
paint: &mut dyn FnMut(&mut AppModel, &mut ShellState) -> String,
) -> String {
let _ = paint(&mut world.model, &mut world.state);
world.model.refresh();
world.reads();
world.acts();
let _ = paint(&mut world.model, &mut world.state);
world.model.refresh();
paint(&mut world.model, &mut world.state)
}
fn arm(world: &mut World) {
let root = world.model.state_root().to_path_buf();
std::fs::write(
root.join(crate::app::cadence::CADENCE_YAML),
"fleet:\n /ws/a:\n project: /dev/yog\n cap: 3\n",
)
.expect("the fixture world takes a cadence file");
world
.model
.dirty_handle()
.mark_all([(root, crate::watch::Mark::Watch)]);
world.converge();
}
fn painted_board(world: &mut World, answered: bool) -> String {
let lernie = Cli::new("lernie");
let mut paint = |model: &mut AppModel, state: &mut ShellState| {
crate::paint_probe::paint(|ui| {
super::super::board::board(ui, model, state, &lernie);
})
};
if answered {
wired(world, &mut paint)
} else {
paint(&mut world.model, &mut world.state)
}
}
#[test]
fn the_balls_fold_paints_the_board_the_wire_answers_and_nothing_without_one() {
let mut world = super::fixture::world();
arm(&mut world);
let unanswered = painted_board(&mut world, false);
assert!(
!unanswered.contains("fleet"),
"with nothing answering, the fold has no board to paint:\n{unanswered}"
);
let answered = painted_board(&mut world, true);
assert!(
answered.contains("fleet"),
"and the armed loop reaches the glass once a reply lands:\n{answered}"
);
assert!(
answered.contains("3 drones"),
"the row's own figures ride the same reply:\n{answered}"
);
}
fn painted_unanswered(world: &mut World) -> String {
let (lernie, bl, bz) = (Cli::new("lernie"), Cli::new("bl"), Cli::new("bz"));
let ctx = egui::Context::default();
let frame = |world: &mut World| {
ctx.run(super::input(), |ctx| {
render(ctx, &mut world.model, &mut world.state, &lernie, &bl, &bz);
})
};
let _ = frame(world);
crate::paint_probe::text_of(&frame(world))
}
#[test]
fn the_inspector_paints_the_chat_the_wire_answers_and_nothing_without_one() {
let (lernie, bl) = (Cli::new("lernie"), Cli::new("bl"));
let mut world = super::fixture::world();
let ws = world.ws.clone();
world.model.focus_agent(&ws, "c-1");
world.model.select_tab(InspectorTab::Transcript);
let unanswered = painted_unanswered(&mut world);
assert!(
!unanswered.contains("pong reply"),
"with nothing answering, the chat has nothing to paint:\n{unanswered}"
);
assert!(
unanswered.contains("(no messages yet)"),
"and it says so rather than painting a torn pane:\n{unanswered}"
);
let answered = super::painted(&mut world, &lernie, &bl);
assert!(
answered.contains("pong reply"),
"and the conversation reaches the glass once a reply lands:\n{answered}"
);
}