use super::fixture::{world, world_empty};
use super::screen::{Screen, command_shift, press, rect_of, rects_of};
use crate::keymap::CenterTab;
use crate::names::DEFAULT_NAME;
#[test]
fn the_empty_world_reaches_a_populated_roster_from_inside_the_box() {
let mut world = world_empty();
let screen = Screen::new();
assert!(
screen.idle(&mut world),
"the empty world opens with the keyboard in the bootstrap box"
);
assert!(
world.model.focused_workspace().is_none(),
"and with nothing focused, or this is not the state under test"
);
screen.frame(&mut world, vec![press(egui::Key::Num3, command_shift())]);
assert_eq!(
world.state.center,
CenterTab::Login,
"Ctrl+Shift+3 focuses the Login tab without the box letting go first"
);
let painted = screen.text(&mut world);
let rows = world.state.wall.login.rows.clone();
assert!(
!rows.is_empty(),
"the roster is the newborn wall's, and brazen's shipped table is not empty"
);
for row in &rows {
assert!(
painted.contains(&row.name) && painted.contains(&row.fact),
"every row reaches the glass with its credential fact:\n{painted}"
);
}
assert!(
!painted.contains("brazen listed no provider rows"),
"the empty-roster sentence is the answer to a different question:\n{painted}"
);
assert!(
painted.contains(DEFAULT_NAME),
"and the pane names the sphere a sign-in here lands in:\n{painted}"
);
}
const BROWSER_ROW: &str = "openai-chatgpt";
#[test]
fn the_default_rosters_oauth_row_offers_the_browser_login_beside_its_name() {
let mut world = world_empty();
let screen = Screen::new();
screen.idle(&mut world);
screen.frame(&mut world, vec![press(egui::Key::Num3, command_shift())]);
let rows = world.state.wall.login.rows.clone();
let loginable: Vec<&str> = rows
.iter()
.filter(|row| row.blocked.is_none())
.map(|row| row.name.as_str())
.collect();
assert_eq!(
loginable,
[BROWSER_ROW],
"a default install's table carries the shipped oauth2 row and no other \
login-capable one"
);
let row = rows
.iter()
.find(|row| row.name == BROWSER_ROW)
.expect("the row just named");
assert_eq!(
row.fact, "auth oauth2 · not signed in",
"and it says so in the words only a login can change"
);
assert!(
rows.iter()
.any(|other| other.blocked.as_deref()
== Some("api-key provider — set the key in Config")),
"the keyed rows still answer with the editor — the ruling added a path, \
it did not reclassify the table: {rows:?}"
);
let shapes = screen.shapes(&mut world, Vec::new());
let name = rect_of(&shapes, BROWSER_ROW).expect("the row's name is on the glass");
let verb = rects_of(&shapes, "Login")
.into_iter()
.find(|rect| (rect.center().y - name.center().y).abs() < name.height())
.expect("the row carries the Login verb, not a reason to have none");
assert!(
verb.left() >= name.right(),
"and it is the control at the end of that row (§11 rule 1b), not the tab \
strip's entry: name {name:?}, verb {verb:?}"
);
}
#[test]
fn the_roster_names_whichever_sphere_the_window_is_pointed_at() {
let mut world = world();
let screen = Screen::new();
screen.idle(&mut world);
crate::shell::center::focus(&world.model, &mut world.state, CenterTab::Login);
let painted = screen.text(&mut world);
let leaf = world
.ws
.file_name()
.expect("the fixture workspace has a leaf")
.to_string_lossy()
.into_owned();
assert_ne!(leaf, DEFAULT_NAME, "the fixture must not be named `home`");
assert!(
painted.contains(&format!("belong to the workspace {leaf}")),
"the focused sphere is the one named:\n{painted}"
);
}
#[test]
fn the_newborn_rosters_wall_is_the_one_the_first_message_will_use() {
let mut world = world_empty();
let screen = Screen::new();
screen.idle(&mut world);
let holder = &world.state.wall.login;
assert_eq!(
holder.workspace.as_deref(),
Some(world.model.start_workspace().as_path()),
"the roster belongs to the sphere §3.4 says the next Enter lands in"
);
let wall = holder
.wall
.iter()
.find(|(key, _)| key == crate::world::wall::YOG_WALL)
.map(|(_, value)| std::path::PathBuf::from(value))
.expect("the spawn layer names the wall");
assert_eq!(
wall.file_name().map(std::ffi::OsStr::to_string_lossy),
Some(DEFAULT_NAME.into()),
"and it is `<world>/walls/home` — the name IS the wall (§16.2), so the \
credential written here is the one the founded `home` reads"
);
}