Initial public release
Luxe 0.1.0: a coding agent harness for the terminal. See README.md to get started and CHANGELOG.md for releases.
This commit is contained in:
169
crates/luxe-tui/src/view/dock/tests/lists.rs
Normal file
169
crates/luxe-tui/src/view/dock/tests/lists.rs
Normal file
@@ -0,0 +1,169 @@
|
||||
//! Lists — scrolling lists, elsewhere, and the hint row.
|
||||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn changes_of(paths: &[&str]) -> DockChanges {
|
||||
DockChanges {
|
||||
files: paths
|
||||
.iter()
|
||||
.map(|path| DockChangeItem {
|
||||
path: (*path).to_string(),
|
||||
status: luxe_core::workspace::FileChangeStatus::Modified,
|
||||
additions: Some(1),
|
||||
deletions: Some(0),
|
||||
})
|
||||
.collect(),
|
||||
total_files: paths.len(),
|
||||
additions: Some(paths.len() as u64),
|
||||
deletions: Some(0),
|
||||
remaining: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The lane is paid for out of the rows it belongs to, and only while it is drawn.
|
||||
///
|
||||
/// A list that fits keeps its full width: two cells is a directory component in a forty-cell
|
||||
/// rail, and giving them up for a bar that is not there would cost every reader a path.
|
||||
#[test]
|
||||
fn a_scrolling_list_gives_up_exactly_the_lane_and_a_settled_one_gives_up_nothing() {
|
||||
let app = app();
|
||||
let paths: Vec<String> = (0..24).map(|index| format!("src/dir{index:02}/f.rs")).collect();
|
||||
let long: Vec<&str> = paths.iter().map(String::as_str).collect();
|
||||
|
||||
let widest = |section: &DockSection| {
|
||||
let (start, end) = section.list.as_ref().map_or((0, section.lines.len()), |l| l.rows);
|
||||
section.lines[start..end]
|
||||
.iter()
|
||||
.map(|line| UnicodeWidthStr::width(text(line).as_str()))
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
};
|
||||
|
||||
let scrolling = file_lines(Some(&changes_of(&long)), &app, 8);
|
||||
assert!(scrolling.list.is_some(), "twenty-four folders outgrow eight rows");
|
||||
assert!(
|
||||
widest(&scrolling) <= DEFAULT_ROW - SCROLLBAR_LANE,
|
||||
"a row ran into the lane: {}",
|
||||
widest(&scrolling)
|
||||
);
|
||||
|
||||
let settled = file_lines(Some(&changes_of(&long[..2])), &app, 8);
|
||||
assert!(settled.list.is_none(), "two files fit");
|
||||
assert!(widest(&settled) <= DEFAULT_ROW, "and still cannot outgrow the rail");
|
||||
}
|
||||
|
||||
/// A place holding `files`, each as `(path, additions)`.
|
||||
pub(super) fn place(root: &str, files: &[(&str, u64)]) -> DockExternalGroup {
|
||||
DockExternalGroup {
|
||||
root: root.into(),
|
||||
location: root.to_string(),
|
||||
branch: None,
|
||||
git: false,
|
||||
files: files
|
||||
.iter()
|
||||
.map(|(path, additions)| DockChangeItem {
|
||||
path: (*path).to_string(),
|
||||
status: luxe_core::workspace::FileChangeStatus::Modified,
|
||||
additions: Some(*additions),
|
||||
deletions: Some(0),
|
||||
})
|
||||
.collect(),
|
||||
remaining: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Elsewhere reads like Changes one level in: a place, the folders under it, the files under
|
||||
/// those — except at a place's own root, where the place already is the folder.
|
||||
#[test]
|
||||
fn elsewhere_nests_folders_under_a_place_but_not_at_its_root() {
|
||||
let app = app();
|
||||
let external = DockExternal {
|
||||
groups: vec![place("/work/sdk", &[("src/client.ts", 40), ("README.md", 2)])],
|
||||
total_files: 2,
|
||||
};
|
||||
let rows = external_rows(&external, &app);
|
||||
// A→Z, exactly as the changes are grouped — which puts the place's own root ahead of its folders.
|
||||
assert_eq!(
|
||||
shape(&rows),
|
||||
["place", "file", "directory", "file"],
|
||||
"one heading, and the root file has none"
|
||||
);
|
||||
assert!(
|
||||
matches!(&rows[2], ExternalRow::Under { row: DockChangeRow::Directory(at), .. }
|
||||
if at.directory == "src"),
|
||||
"and the heading is the folder the nested file is in"
|
||||
);
|
||||
}
|
||||
|
||||
/// What each ELSEWHERE row is, for a test that cares about the shape rather than the words.
|
||||
pub(super) fn shape<'a>(rows: &'a [ExternalRow<'a>]) -> Vec<&'static str> {
|
||||
rows.iter()
|
||||
.map(|row| match row {
|
||||
ExternalRow::Place { .. } => "place",
|
||||
ExternalRow::Under { row: DockChangeRow::Directory(_), .. } => "directory",
|
||||
ExternalRow::Under { .. } => "file",
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A window opening mid-place repeats what its rows sit under — up to two headings, because
|
||||
/// the list nests twice — and a window opening on a heading of its own repeats nothing.
|
||||
#[test]
|
||||
fn a_window_into_elsewhere_repeats_the_headings_it_opened_under() {
|
||||
let app = app();
|
||||
let external = DockExternal {
|
||||
groups: vec![
|
||||
place("/work/sdk", &[("src/client.ts", 40), ("src/events.ts", 20), ("README.md", 2)]),
|
||||
place("/work/tools", &[("bin/run.sh", 3)]),
|
||||
],
|
||||
total_files: 4,
|
||||
};
|
||||
let rows = external_rows(&external, &app);
|
||||
assert_eq!(
|
||||
shape(&rows),
|
||||
["place", "file", "directory", "file", "file", "place", "directory", "file"]
|
||||
);
|
||||
|
||||
assert!(external_context(&rows, 0).is_empty(), "the top is under nothing");
|
||||
assert!(external_context(&rows, 5).is_empty(), "and so is a place heading");
|
||||
assert_eq!(external_context(&rows, 2), [0], "a folder needs its place");
|
||||
assert_eq!(external_context(&rows, 3), [0, 2], "a nested file needs both");
|
||||
assert_eq!(external_context(&rows, 1), [0], "a root file needs only the place");
|
||||
assert_eq!(external_context(&rows, 7), [5, 6], "and the second place is its own");
|
||||
}
|
||||
|
||||
/// Both ways in, on one row, each answering for its own words — and never wrapped, because a
|
||||
/// wrapped hint puts half of itself where its click region no longer points.
|
||||
#[test]
|
||||
fn the_hint_row_offers_both_ways_in_and_keeps_them_on_one_line() {
|
||||
let app = app();
|
||||
let (line, regions) = hint_line(&change_hints(&app), 7, &app);
|
||||
assert_eq!(text(&line), "ctrl+p preview · ctrl+g review");
|
||||
assert!(
|
||||
UnicodeWidthStr::width(text(&line).as_str()) <= usize::from(CONTEXT_DOCK_WIDTH) - 2,
|
||||
"the rail has to seat it: {:?}",
|
||||
text(&line)
|
||||
);
|
||||
|
||||
// Each region names the columns its own words occupy, on the row it was built for.
|
||||
let (peek, review) = (®ions[0], ®ions[1]);
|
||||
assert_eq!(peek.target, crate::mouse::MouseTarget::DockPeekChanges);
|
||||
assert_eq!((peek.line, peek.columns), (7, Some((0, 14))));
|
||||
assert_eq!(review.target, crate::mouse::MouseTarget::DockReviewChanges);
|
||||
assert_eq!((review.line, review.columns), (7, Some((17, 13))));
|
||||
|
||||
// A rail too narrow for both keeps the review: every file row above already opens the preview.
|
||||
let long = vec![
|
||||
ChangeHint {
|
||||
text: "a very long way to say peek indeed, at length".into(),
|
||||
target: crate::mouse::MouseTarget::DockPeekChanges,
|
||||
},
|
||||
ChangeHint {
|
||||
text: "ctrl+g review".into(),
|
||||
target: crate::mouse::MouseTarget::DockReviewChanges,
|
||||
},
|
||||
];
|
||||
let (line, regions) = hint_line(&long, 0, &app);
|
||||
assert_eq!(text(&line), "ctrl+g review");
|
||||
assert_eq!(regions.len(), 1);
|
||||
}
|
||||
186
crates/luxe-tui/src/view/dock/tests/plan.rs
Normal file
186
crates/luxe-tui/src/view/dock/tests/plan.rs
Normal file
@@ -0,0 +1,186 @@
|
||||
//! Plan — the checklist, its order, its wrapping and its window.
|
||||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn todo(subject: &str, status: TodoSummaryStatus) -> DockPlanItem {
|
||||
DockPlanItem { subject: subject.into(), status }
|
||||
}
|
||||
|
||||
pub(super) fn checklist(statuses: &[TodoSummaryStatus]) -> DockPlan {
|
||||
let items: Vec<DockPlanItem> = statuses
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, status)| todo(&format!("step {index}"), *status))
|
||||
.collect();
|
||||
DockPlan {
|
||||
pending: items.iter().filter(|i| i.status == TodoSummaryStatus::Pending).count(),
|
||||
in_progress: items.iter().filter(|i| i.status == TodoSummaryStatus::InProgress).count(),
|
||||
completed: items.iter().filter(|i| i.status == TodoSummaryStatus::Completed).count(),
|
||||
total: items.len(),
|
||||
remaining: None,
|
||||
items,
|
||||
}
|
||||
}
|
||||
|
||||
/// A plan is a sequence, and ticking a box must not move it.
|
||||
///
|
||||
/// The rows used to be regrouped by status on every render, so finishing the third item sent it
|
||||
/// to the bottom and pulled everything below it up a line — the list rearranged itself under a
|
||||
/// reader who was working down it.
|
||||
#[test]
|
||||
fn the_checklist_keeps_the_order_it_was_written_in() {
|
||||
use TodoSummaryStatus::{Completed, InProgress, Pending};
|
||||
let app = app();
|
||||
let plan = checklist(&[Completed, InProgress, Pending, Completed, Pending]);
|
||||
let rows: Vec<String> = plan_lines(&plan, &app)
|
||||
.lines
|
||||
.iter()
|
||||
.map(text)
|
||||
.filter(|row| row.contains("step "))
|
||||
.collect();
|
||||
let subjects: Vec<&str> =
|
||||
rows.iter().map(|row| row.trim_end().rsplit_once("step ").expect("a subject").1).collect();
|
||||
assert_eq!(subjects, ["0", "1", "2", "3", "4"], "{rows:?}");
|
||||
}
|
||||
|
||||
/// A long subject wraps under its own first word instead of being cut at the rail's edge, and
|
||||
/// the rows for it come out of a budget that serves the work in hand first.
|
||||
#[test]
|
||||
fn a_long_subject_wraps_within_the_plans_budget() {
|
||||
use TodoSummaryStatus::{Completed, InProgress, Pending};
|
||||
let app = app();
|
||||
let long = "Survey the AI Hub codebases (dev/prod, backend/frontend): scale, architecture, \
|
||||
test coverage and every integration that touches billing";
|
||||
let mut plan = checklist(&[Completed, InProgress, Pending]);
|
||||
for item in &mut plan.items {
|
||||
item.subject = long.to_string();
|
||||
}
|
||||
let rows: Vec<String> = plan_lines(&plan, &app).lines.iter().map(text).collect();
|
||||
let body = &rows[3..];
|
||||
assert_eq!(body.len(), 2 + 3 + 2, "done and next get two rows, the work in hand three");
|
||||
assert!(body[1].starts_with("│ "), "the connector carries down: {:?}", body[1]);
|
||||
assert!(body.last().is_some_and(|row| row.starts_with(" ")), "and closes at the end");
|
||||
assert!(body.iter().all(|row| row.width() <= DEFAULT_ROW), "{body:?}");
|
||||
assert!(body[1].ends_with('…'), "what does not fit is still cut: {:?}", body[1]);
|
||||
|
||||
// A full window has fewer spare rows, and the work in hand is first to them
|
||||
let mut busy = checklist(&[Completed; 8]);
|
||||
busy.items[7].status = InProgress;
|
||||
for item in &mut busy.items {
|
||||
item.subject = long.to_string();
|
||||
}
|
||||
let grants = plan_row_grants(
|
||||
&busy.items.iter().collect::<Vec<_>>(),
|
||||
&busy.items.iter().map(|item| subject_rows(&item.subject, 35)).collect::<Vec<_>>(),
|
||||
);
|
||||
assert_eq!(grants[7], 3, "{grants:?}");
|
||||
assert_eq!(grants.iter().sum::<usize>(), PLAN_ROWS_MAX + PLAN_WRAP_ROWS, "{grants:?}");
|
||||
|
||||
// And a subject that fits takes the one row it always did
|
||||
let short = checklist(&[Pending, Pending]);
|
||||
assert_eq!(plan_lines(&short, &app).lines.len(), 3 + 2);
|
||||
}
|
||||
|
||||
/// Done is green *and* struck through; nothing else on the rail is.
|
||||
#[test]
|
||||
fn a_finished_row_is_struck_through_and_only_its_words_are() {
|
||||
let app = app();
|
||||
let done = todo_lines(
|
||||
&todo("ship it", TodoSummaryStatus::Completed),
|
||||
vec!["ship it".into()],
|
||||
true,
|
||||
30,
|
||||
1,
|
||||
&app,
|
||||
)
|
||||
.remove(0);
|
||||
let subject = done.spans.iter().find(|s| s.content.contains("ship it")).expect("subject");
|
||||
assert!(subject.style.add_modifier.contains(Modifier::CROSSED_OUT));
|
||||
assert_eq!(subject.style.fg, app.theme_styles.success.fg, "still green");
|
||||
|
||||
// The tick itself is not struck: a struck ✓ reads as a mistake rather than a finished row.
|
||||
let tick = done.spans.iter().find(|s| s.content.contains('✓')).expect("a tick");
|
||||
assert!(!tick.style.add_modifier.contains(Modifier::CROSSED_OUT));
|
||||
|
||||
for open in
|
||||
[TodoSummaryStatus::Pending, TodoSummaryStatus::InProgress, TodoSummaryStatus::Blocked]
|
||||
{
|
||||
let line =
|
||||
todo_lines(&todo("ship it", open), vec!["ship it".into()], true, 30, 1, &app).remove(0);
|
||||
let subject = line.spans.iter().find(|s| s.content.contains("ship it")).expect("subject");
|
||||
assert!(
|
||||
!subject.style.add_modifier.contains(Modifier::CROSSED_OUT),
|
||||
"{open:?} is not finished"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The follow position is anchored at the top and slides only to keep the work in hand in view.
|
||||
#[test]
|
||||
fn the_plan_window_follows_the_row_in_hand_without_leaving_the_top() {
|
||||
use TodoSummaryStatus::{Completed, InProgress, Pending};
|
||||
let at = |active: usize, total: usize| {
|
||||
let statuses: Vec<TodoSummaryStatus> = (0..total)
|
||||
.map(|index| match index.cmp(&active) {
|
||||
std::cmp::Ordering::Less => Completed,
|
||||
std::cmp::Ordering::Equal => InProgress,
|
||||
std::cmp::Ordering::Greater => Pending,
|
||||
})
|
||||
.collect();
|
||||
plan_follow(&checklist(&statuses).items)
|
||||
};
|
||||
|
||||
// Everything fits: no window at all.
|
||||
assert_eq!(at(3, PLAN_ROWS_MAX), 0);
|
||||
|
||||
// It stays pinned to the top while the active row and its lookahead still fit …
|
||||
assert_eq!(at(0, 20), 0);
|
||||
assert_eq!(at(PLAN_ROWS_MAX - PLAN_LOOKAHEAD - 1, 20), 0);
|
||||
|
||||
// … then slides one row at a time, keeping the lookahead below the active row.
|
||||
assert_eq!(at(PLAN_ROWS_MAX - PLAN_LOOKAHEAD, 20), 1, "one row of history folded away");
|
||||
assert_eq!(at(PLAN_ROWS_MAX - PLAN_LOOKAHEAD + 1, 20), 2);
|
||||
|
||||
// And it stops at the end rather than scrolling past it.
|
||||
assert_eq!(at(19, 20), 12);
|
||||
|
||||
// A finished plan shows its tail, not its head.
|
||||
assert_eq!(plan_follow(&checklist(&[Completed; 20]).items), 12);
|
||||
}
|
||||
|
||||
/// A checklist longer than the rail is a viewport onto the whole thing: the bar says where the
|
||||
/// window sits, nothing counts what is outside it in words, and the active row survives.
|
||||
#[test]
|
||||
fn a_long_checklist_scrolls_under_a_bar_rather_than_counting_its_folds() {
|
||||
use TodoSummaryStatus::{Completed, InProgress, Pending};
|
||||
let app = app();
|
||||
let mut statuses = vec![Completed; 12];
|
||||
statuses[11] = InProgress;
|
||||
statuses.extend([Pending; 8]);
|
||||
let mut plan = checklist(&statuses);
|
||||
plan.remaining = Some(2);
|
||||
plan.total += 2;
|
||||
|
||||
let section = plan_lines(&plan, &app);
|
||||
let rendered: Vec<String> = section.lines.iter().map(text).collect();
|
||||
let all = rendered.join("\n");
|
||||
assert!(!all.contains("earlier"), "the bar says where the window is: {all}");
|
||||
assert!(!all.contains("more"), "and what is below it: {all}");
|
||||
assert!(!all.contains("not listed"), "and the rail counts nothing in words: {all}");
|
||||
assert!(all.contains("step 11"), "the row in hand is never the one folded away: {all}");
|
||||
assert!(all.contains("step 13"), "and the work just after it stays in view: {all}");
|
||||
assert_eq!(rendered.iter().filter(|row| row.contains("step ")).count(), PLAN_ROWS_MAX);
|
||||
|
||||
// The lane exists, spans exactly the todo rows, and gives them their two cells back.
|
||||
let list = section.list.expect("a checklist that outgrew the rail scrolls");
|
||||
assert_eq!(list.total, 20);
|
||||
assert_eq!(list.offset, plan_follow(&plan.items));
|
||||
assert_eq!(list.rows.1 - list.rows.0, PLAN_ROWS_MAX);
|
||||
for row in &rendered[list.rows.0..list.rows.1] {
|
||||
assert!(row.contains("step "), "the lane covers only the checklist: {row:?}");
|
||||
}
|
||||
|
||||
// A checklist that fits gets no lane, and keeps its full width.
|
||||
let short = checklist(&[Completed, InProgress, Pending]);
|
||||
assert!(plan_lines(&short, &app).list.is_none());
|
||||
}
|
||||
505
crates/luxe-tui/src/view/dock/tests/rail.rs
Normal file
505
crates/luxe-tui/src/view/dock/tests/rail.rs
Normal file
@@ -0,0 +1,505 @@
|
||||
//! Rail — the telemetry rows, their columns, and what the session says about itself.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A row of the default rail, which is what every test app draws.
|
||||
pub(super) const DEFAULT_ROW: usize = CONTEXT_DOCK_WIDTH as usize - 2;
|
||||
|
||||
pub(super) fn app() -> App {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel(4);
|
||||
App::new(tx, KeyMap::defaults(), Config { theme: Some("nord".into()), ..Config::default() })
|
||||
}
|
||||
|
||||
pub(super) fn text(line: &Line<'_>) -> String {
|
||||
line.spans.iter().map(|span| span.content.as_ref()).collect()
|
||||
}
|
||||
|
||||
/// The rail carries walk-away mode too, because it is what remains when the bar is hidden.
|
||||
///
|
||||
/// Telemetry relocates here exactly then, so without this row a reader who turned the
|
||||
/// statusline off would have no standing word that every escalation is being approved — and
|
||||
/// turning a bar off is not consent to that.
|
||||
#[test]
|
||||
fn the_rail_reports_a_session_that_is_approving_its_own_asks() {
|
||||
let mut app = app();
|
||||
app.status.model = "claude-sonnet-5".into();
|
||||
let quiet: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
assert!(
|
||||
!quiet.iter().any(|row| row.contains("auto-approve")),
|
||||
"prompting is not news: {quiet:?}"
|
||||
);
|
||||
|
||||
app.permission_auto_approve = true;
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
let row = rendered
|
||||
.iter()
|
||||
.find(|row| row.starts_with("approvals"))
|
||||
.unwrap_or_else(|| panic!("no approvals row in {rendered:?}"));
|
||||
assert!(row.contains("auto-approve"), "{row}");
|
||||
}
|
||||
|
||||
/// The surface behind the span carrying `needle` — the slab the badge is cut from.
|
||||
pub(super) fn surface_behind(line: &Line<'_>, needle: &str) -> Color {
|
||||
line.spans
|
||||
.iter()
|
||||
.find(|span| span.content.contains(needle))
|
||||
.and_then(|span| span.style.bg)
|
||||
.unwrap_or_else(|| panic!("no surface behind {needle:?}"))
|
||||
}
|
||||
|
||||
/// The bar's rule stood on end: the accent undiluted at both anchors, receding between them.
|
||||
///
|
||||
/// Pinned by section rather than by color literal, so a theme cannot break it and a section
|
||||
/// moving to a new depth has to say so here — which is the point, because the rail's colors are
|
||||
/// only legible as a ramp while the assignment stays deliberate.
|
||||
#[test]
|
||||
fn the_rail_is_anchored_at_both_ends_and_recedes_between_them() {
|
||||
let app = app();
|
||||
let shades = app.theme_styles.slab;
|
||||
let surface =
|
||||
|section: Section| surface_behind(§ion_heading_line(section, &app), section.label());
|
||||
|
||||
for anchor in [Section::Project, Section::Model] {
|
||||
assert_eq!(surface(anchor), shades.hero, "{anchor:?} anchors the rail");
|
||||
}
|
||||
for live in [Section::Plan, Section::Files] {
|
||||
assert_eq!(surface(live), shades.at(Depth::Raised), "{live:?} is one step back");
|
||||
}
|
||||
for ambient in [Section::Elsewhere, Section::Session] {
|
||||
assert_eq!(surface(ambient), shades.at(Depth::Recessed), "{ambient:?} is two");
|
||||
}
|
||||
// Or every assertion above passes on a theme with no ramp at all.
|
||||
assert_ne!(shades.hero, shades.at(Depth::Raised));
|
||||
assert_ne!(shades.at(Depth::Raised), shades.at(Depth::Recessed));
|
||||
}
|
||||
|
||||
/// A badge opens on the column its body rows start at, so a section reads as one block — which
|
||||
/// puts its label one cap and one pad further in, at every glyph tier, because a cap keeps its
|
||||
/// cell when the font cannot draw it.
|
||||
#[test]
|
||||
fn a_badge_opens_on_the_column_its_body_starts_at() {
|
||||
let app = app();
|
||||
for tier in [GlyphTier::Nerd, GlyphTier::Unicode, GlyphTier::Ascii] {
|
||||
set_tier(tier);
|
||||
let heading = text(§ion_heading_line(Section::Files, &app));
|
||||
let at = heading.find("FILES").expect("the label is on the row");
|
||||
assert_eq!(UnicodeWidthStr::width(&heading[..at]), 2, "at {tier:?}: {heading:?}");
|
||||
}
|
||||
set_tier(GlyphTier::Nerd);
|
||||
assert_eq!(text(&text_line("12 files".into(), &app)), "12 files", "body hugs the margin");
|
||||
}
|
||||
|
||||
/// Every badge holds one word, so the run of them down the rail reads as structure; what a
|
||||
/// heading summarizes follows it on the canvas, past the closing cap.
|
||||
#[test]
|
||||
fn a_heading_summary_rides_bare_beside_its_badge() {
|
||||
let app = app();
|
||||
let line = section_heading_with(Section::Plan, "4/9".into(), &app);
|
||||
assert!(text(&line).ends_with(" 4/9"), "{:?}", text(&line));
|
||||
assert_eq!(surface_behind(&line, "PLAN"), app.theme_styles.slab.at(Depth::Raised));
|
||||
assert_eq!(
|
||||
surface_behind(&line, "4/9"),
|
||||
app.theme_styles.tool_bg.bg.expect("the panel names its fill"),
|
||||
"the ratio sits on the panel, not on the badge"
|
||||
);
|
||||
}
|
||||
|
||||
/// The project row wears the statusline project module's folder, the way the branch and model
|
||||
/// rows under it wear their modules' icons: one fact, drawn the same on both forms of a surface.
|
||||
#[test]
|
||||
fn the_project_row_carries_the_statusline_folder() {
|
||||
use luxe_core::workspace::{ProjectIdentity, WorkspaceScopeId, WorkspaceSnapshot};
|
||||
let app = app();
|
||||
let snapshot = WorkspaceSnapshot::empty(
|
||||
WorkspaceScopeId::new("dock-project"),
|
||||
ProjectIdentity {
|
||||
root: "/work/luxe".into(),
|
||||
display_name: "luxe".into(),
|
||||
display_path: "~/work/luxe".into(),
|
||||
git_branch: Some("main".into()),
|
||||
git_head: None,
|
||||
git_dirty: false,
|
||||
},
|
||||
);
|
||||
let model = DockSectionModel::from_snapshot(&snapshot);
|
||||
let (header, ..) = region_lines(&model, &app, 40, false, DockPresentation::SideBySide);
|
||||
let project = text(&header[1]);
|
||||
assert_eq!(project, icon_label(Icon::Folder.glyph(), "luxe"), "{project:?}");
|
||||
assert!(text(&header[2]).starts_with(&icon_label(Icon::Branch.glyph(), "")), "the branch");
|
||||
}
|
||||
|
||||
/// One look, one setting. A bar asked to go flat takes the rail with it: this is the same shape
|
||||
/// on both forms of one surface, and half of it obeying would be worse than neither.
|
||||
#[test]
|
||||
fn a_flat_bar_flattens_the_rail_too() {
|
||||
let mut app = app();
|
||||
app.config.statusline.style = Some(StatuslineStyle::Flat);
|
||||
let heading = section_heading_line(Section::Project, &app);
|
||||
assert_eq!(text(&heading), "PROJECT", "no caps and no padding");
|
||||
assert_eq!(heading.spans[0].style.fg, app.theme_styles.accent.fg);
|
||||
}
|
||||
|
||||
/// The rail reports the model either way, and the row that opens the picker is there either way.
|
||||
///
|
||||
/// The section used to be suppressed when nothing was chosen, which hid the pointer's only way
|
||||
/// into the picker from the one reader who had not chosen yet.
|
||||
#[test]
|
||||
fn the_rail_says_when_no_model_is_selected() {
|
||||
let app = app();
|
||||
assert!(app.status.model.is_empty(), "nothing is chosen for the reader");
|
||||
let rendered: String =
|
||||
telemetry_lines(&app).iter().map(|line| format!("{}\n", text(line))).collect();
|
||||
assert!(rendered.contains("no model"), "{rendered}");
|
||||
|
||||
let mut chosen = app;
|
||||
chosen.status.model = "claude-sonnet-5".into();
|
||||
let rendered: String =
|
||||
telemetry_lines(&chosen).iter().map(|line| format!("{}\n", text(line))).collect();
|
||||
assert!(rendered.contains("claude-sonnet-5"), "{rendered}");
|
||||
assert!(!rendered.contains("no model"), "{rendered}");
|
||||
}
|
||||
|
||||
/// The review's row holds what the review had cost while its guide is being written, and
|
||||
/// shows the whole figure once it lands, rather than a batch's share of it partway through.
|
||||
#[test]
|
||||
fn the_review_row_waits_for_its_spend_to_settle() {
|
||||
use luxe_core::usage::{SessionUsage, SourceUsage, UsageSource, UsageTotals};
|
||||
let spent = |review: f64| {
|
||||
let totals = |cost_usd| UsageTotals { calls: 1, cost_usd, ..Default::default() };
|
||||
SessionUsage {
|
||||
total: totals(review),
|
||||
by_source: vec![SourceUsage { source: UsageSource::Review, totals: totals(review) }],
|
||||
}
|
||||
};
|
||||
let review_row = |app: &App| {
|
||||
telemetry_lines(app)
|
||||
.iter()
|
||||
.map(text)
|
||||
.find(|row| row.starts_with("review"))
|
||||
.map(|row| row.trim_start_matches("review").trim().to_owned())
|
||||
};
|
||||
let mut app = app();
|
||||
app.status.session = spent(0.10);
|
||||
assert_eq!(review_row(&app).as_deref(), Some("$0.10"));
|
||||
|
||||
app.status.hold_review_cost();
|
||||
app.review.queued = Some(crate::app::QueuedReview {
|
||||
target: luxe_core::guided_review::ReviewTarget::WorkingTree,
|
||||
state: crate::app::QueuedReviewState::Writing { since: std::time::Instant::now() },
|
||||
});
|
||||
app.status.session = spent(0.17);
|
||||
assert_eq!(review_row(&app).as_deref(), Some("$0.10"), "held while the guide is written");
|
||||
|
||||
app.review.queued.as_mut().expect("queued").state = crate::app::QueuedReviewState::Ready;
|
||||
app.status.session = spent(0.32);
|
||||
assert_eq!(review_row(&app).as_deref(), Some("$0.32"), "the whole figure once it lands");
|
||||
}
|
||||
|
||||
/// Every telemetry value opens on the same column, and it clears the badge above it.
|
||||
///
|
||||
/// The column only holds while every row goes through it — including the widest label there is,
|
||||
/// which is a cost breakdown's.
|
||||
#[test]
|
||||
fn every_telemetry_value_opens_on_one_column_clear_of_the_badge() {
|
||||
let mut app = app();
|
||||
app.status.model = "claude-sonnet-5".into();
|
||||
app.status.provider = "anthropic".into();
|
||||
app.status.context_window = 1_000_000;
|
||||
app.status.context_pct = 3.0;
|
||||
app.status.session = luxe_core::usage::SessionUsage {
|
||||
total: luxe_core::usage::UsageTotals {
|
||||
calls: 12,
|
||||
prompt_tokens: 295_000,
|
||||
completion_tokens: 5_300,
|
||||
cache_read_tokens: 266_000,
|
||||
cost_usd: 0.18,
|
||||
..Default::default()
|
||||
},
|
||||
by_source: vec![luxe_core::usage::SourceUsage {
|
||||
source: luxe_core::usage::UsageSource::Compaction,
|
||||
totals: luxe_core::usage::UsageTotals {
|
||||
calls: 2,
|
||||
cost_usd: 0.02,
|
||||
..Default::default()
|
||||
},
|
||||
}],
|
||||
};
|
||||
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
let value_at = |label: &str| -> usize {
|
||||
let row = rendered
|
||||
.iter()
|
||||
.find(|row| row.starts_with(label))
|
||||
.unwrap_or_else(|| panic!("no {label} row in {rendered:?}"));
|
||||
UnicodeWidthStr::width(&row[..row.len() - row.trim_start_matches(label).trim_start().len()])
|
||||
};
|
||||
for label in ["anthropic", "thinking", "context", "tokens", "cost", "compaction"] {
|
||||
assert_eq!(value_at(label), TELEMETRY_LABEL_WIDTH, "{label} in {rendered:?}");
|
||||
}
|
||||
|
||||
// The badge is a cap, a pad, the word and a pad, then the closing cap.
|
||||
let badge =
|
||||
UnicodeWidthStr::width(text(§ion_heading_line(Section::Session, &app)).as_str());
|
||||
assert!(badge < TELEMETRY_LABEL_WIDTH, "a value would sit under the badge: {badge}");
|
||||
|
||||
// And the widest row still fits the rail it is drawn in.
|
||||
let widest = rendered.iter().map(|row| UnicodeWidthStr::width(row.as_str())).max();
|
||||
assert!(
|
||||
widest.is_some_and(|width| width <= usize::from(CONTEXT_DOCK_WIDTH) - 2),
|
||||
"the rail cannot seat it: {rendered:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The token row keeps the two counts and gives up the footnote when the rail is tight.
|
||||
///
|
||||
/// It is the only value with nothing bounding it, so it is the one that used to decide how
|
||||
/// wide the label column beside it could be. Shedding cache reuse at the top of the range buys
|
||||
/// that column four cells for every session, at the cost of a figure only the largest sessions
|
||||
/// lose — and it is a footnote to the two counts it sits beside.
|
||||
#[test]
|
||||
fn the_token_row_sheds_its_footnote_rather_than_the_rail() {
|
||||
let totals = |prompt, completion, cache| luxe_core::usage::UsageTotals {
|
||||
prompt_tokens: prompt,
|
||||
completion_tokens: completion,
|
||||
cache_read_tokens: cache,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// Ordinary and large-but-real sessions keep all three.
|
||||
let room = telemetry_value_width(DEFAULT_ROW, TELEMETRY_LABEL_WIDTH);
|
||||
let ordinary = token_value(&totals(900_000, 42_000, 600_000), room);
|
||||
assert_eq!(ordinary, format!("↑900k ↓42k {}600k", crate::glyphs::Mark::CacheReuse));
|
||||
let large = token_value(&totals(12_300_000, 340_000, 9_800_000), room);
|
||||
assert!(
|
||||
large.contains(&crate::glyphs::Mark::CacheReuse.to_string()),
|
||||
"a session with room keeps its footnote: {large}"
|
||||
);
|
||||
|
||||
// At the top of the range the footnote goes, and the counts never do.
|
||||
let vast = token_value(&totals(999_900_000, 999_900_000, 999_900_000), room);
|
||||
assert_eq!(vast, "↑999.9M ↓999.9M", "the two counts are the row");
|
||||
assert!(vast.width() <= room, "{vast} still overruns");
|
||||
|
||||
// Nothing to report is not the same as no room to report it.
|
||||
assert_eq!(token_value(&totals(900_000, 42_000, 0), room), "↑900k ↓42k");
|
||||
}
|
||||
|
||||
/// The label column is paid for out of the value column, so the widest value still has to fit.
|
||||
///
|
||||
/// Not the sample figures above but the widest the formatters can produce: `compact_number`
|
||||
/// tops out at six cells (`999.9M`), and the token row spends two of those plus their marks
|
||||
/// and a space. A row that outgrows the rail wraps, and a wrapped telemetry row is two rows
|
||||
/// where the grid promised one — under a block pinned to the bottom of the rail, so it moves
|
||||
/// what the reader was looking at.
|
||||
#[test]
|
||||
fn every_telemetry_row_fits_the_rail() {
|
||||
let mut app = app();
|
||||
app.status.model = "a-very-long-model-identifier".into();
|
||||
app.status.provider = "a-self-hosted-gateway".into();
|
||||
app.status.context_window = 999_999_999;
|
||||
app.status.context_pct = 99.9;
|
||||
app.permission_auto_approve = true;
|
||||
app.status.session.total = luxe_core::usage::UsageTotals {
|
||||
calls: 9,
|
||||
prompt_tokens: 999_900_000,
|
||||
completion_tokens: 999_900_000,
|
||||
cache_read_tokens: 999_900_000,
|
||||
cost_usd: 98_765.43,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let content = usize::from(CONTEXT_DOCK_WIDTH) - 2;
|
||||
for row in telemetry_lines(&app).iter().map(text) {
|
||||
assert!(
|
||||
UnicodeWidthStr::width(row.as_str()) <= content,
|
||||
"{row:?} is {} cells, and the rail seats {content}",
|
||||
UnicodeWidthStr::width(row.as_str())
|
||||
);
|
||||
}
|
||||
|
||||
// The other end of the same budget: the column has to seat the longest provider anyone has
|
||||
// put in front of it, or this is all arithmetic about nothing.
|
||||
assert!(
|
||||
TELEMETRY_LABEL_WIDTH > "foundry-anthropic".width(),
|
||||
"a gateway-prefixed provider is cut, which is the whole reason for the column's width"
|
||||
);
|
||||
app.status.provider = "foundry-anthropic".into();
|
||||
app.status.model = "Claude Fable 5.1 (EU)".into();
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
assert!(
|
||||
rendered.iter().any(|row| row.starts_with("foundry-anthropic ")),
|
||||
"the provider is elided: {rendered:?}"
|
||||
);
|
||||
|
||||
// And the third end: the label column is a split, so taking a cell from the value is
|
||||
// taking it from a model's name. Both of these elide, and a column that seated every
|
||||
// provider id ever written would leave the names — where the variety actually is — paying
|
||||
// for it on every row of every session.
|
||||
let name_room = telemetry_value_width(DEFAULT_ROW, TELEMETRY_LABEL_WIDTH)
|
||||
.saturating_sub(icon_cells(Icon::Model.glyph()));
|
||||
assert!(
|
||||
name_room >= "Claude Sonnet 4.6".width(),
|
||||
"a routine model name does not fit in {name_room} cells"
|
||||
);
|
||||
}
|
||||
|
||||
/// The model row is a row like the others: who serves it on the left, what it is on the right.
|
||||
///
|
||||
/// It used to be the block's headline — the one line in MODEL and SESSION with no label column,
|
||||
/// so its icon sat where every other row's *label* starts and the grid broke at the top. The
|
||||
/// provider is what the column was missing: the one fact about the model its name does not say.
|
||||
#[test]
|
||||
fn the_model_row_is_labeled_by_who_serves_it() {
|
||||
let mut app = app();
|
||||
app.status.model = "claude-sonnet-5".into();
|
||||
app.status.provider = "anthropic".into();
|
||||
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
let model = rendered.iter().find(|row| row.contains("claude-sonnet-5")).expect("a model");
|
||||
assert!(model.starts_with("anthropic"), "{model:?}");
|
||||
assert!(
|
||||
model.ends_with(&crate::glyphs::icon_label(Icon::Model.glyph(), "claude-sonnet-5")),
|
||||
"the value keeps its own mark: {model:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A provider longer than the column is cut rather than allowed to shove the value out of it —
|
||||
/// provider ids are whatever a config names them, and the grid is the whole point of the block.
|
||||
#[test]
|
||||
fn a_long_provider_is_cut_to_its_column() {
|
||||
let mut app = app();
|
||||
app.status.model = "claude-sonnet-5".into();
|
||||
app.status.provider = "a-self-hosted-gateway".into();
|
||||
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
let model = rendered.iter().find(|row| row.contains(Icon::Model.glyph())).expect("a model");
|
||||
let opens_at = model.find(Icon::Model.glyph()).expect("the value's mark");
|
||||
assert_eq!(
|
||||
UnicodeWidthStr::width(&model[..opens_at]),
|
||||
TELEMETRY_LABEL_WIDTH,
|
||||
"the value moved off its column: {model:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A rail dragged wide gives the grid air and the provider its whole name; the default rail
|
||||
/// keeps the column it has always had.
|
||||
#[test]
|
||||
fn a_wide_rail_widens_the_grid_and_seats_a_long_provider() {
|
||||
let mut app = app();
|
||||
app.status.model = "claude-opus-5".into();
|
||||
app.status.provider = "foundry-anthropic".into();
|
||||
app.status.context_window = 1_000_000;
|
||||
let value_column = |app: &App| -> Vec<usize> {
|
||||
telemetry_lines(app)
|
||||
.iter()
|
||||
.map(text)
|
||||
.filter(|row| row.starts_with("foundry-anthropic") || row.starts_with("context"))
|
||||
.map(|row| {
|
||||
let label = row.split_whitespace().next().unwrap_or_default().to_string();
|
||||
let value = row[label.len()..].trim_start();
|
||||
UnicodeWidthStr::width(&row[..row.len() - value.len()])
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
assert_eq!(value_column(&app), [TELEMETRY_LABEL_WIDTH; 2], "the default rail is unchanged");
|
||||
|
||||
app.dock_rail.set(crate::workspace_layout::DOCK_MAX_WIDTH);
|
||||
let wide = value_column(&app);
|
||||
assert_eq!(wide, [21; 2], "seventeen cells of provider, four of air, one grid: {wide:?}");
|
||||
|
||||
app.status.provider = "a-self-hosted-gateway-provider".into();
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
assert!(
|
||||
rendered.iter().any(|row| row.starts_with("a-self-hosted-gateway-provider ")),
|
||||
"a wide rail seats the whole name: {rendered:?}"
|
||||
);
|
||||
for row in &rendered {
|
||||
assert!(UnicodeWidthStr::width(row.as_str()) <= row_width(&app), "{row:?} overruns");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_label_column_grows_only_where_there_is_room() {
|
||||
assert_eq!(telemetry_label_width(40, 17), TELEMETRY_LABEL_WIDTH);
|
||||
assert_eq!(telemetry_label_width(40, 30), TELEMETRY_LABEL_WIDTH, "cut, as it always was");
|
||||
assert_eq!(telemetry_label_width(78, 8), TELEMETRY_LABEL_WIDTH, "short labels keep the floor");
|
||||
assert_eq!(telemetry_label_width(78, 17), 21);
|
||||
assert_eq!(telemetry_label_width(78, 60), 31, "never past two fifths of the row");
|
||||
}
|
||||
|
||||
/// Before the engine has said anything there is no provider to name, and a blank label column
|
||||
/// would leave the value sitting where no other row's value sits.
|
||||
#[test]
|
||||
fn a_model_with_no_provider_yet_still_labels_its_row() {
|
||||
let mut app = app();
|
||||
app.status.model = "claude-sonnet-5".into();
|
||||
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
let model = rendered.iter().find(|row| row.contains("claude-sonnet-5")).expect("a model");
|
||||
assert!(model.starts_with("model"), "{model:?}");
|
||||
}
|
||||
|
||||
/// One block for what the session consumed, so the window is not a section of its own.
|
||||
///
|
||||
/// Three headings over five rows spent as much rail on the badges as on the numbers. What keeps
|
||||
/// the window from reading as more accounting was never the badge — it is the color, which it
|
||||
/// keeps.
|
||||
#[test]
|
||||
fn the_window_is_read_under_session_rather_than_a_heading_of_its_own() {
|
||||
let mut app = app();
|
||||
app.status.model = "claude-sonnet-5".into();
|
||||
app.status.context_window = 200_000;
|
||||
app.status.context_pct = 42.0;
|
||||
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
assert!(!rendered.iter().any(|row| row.contains("CONTEXT")), "{rendered:?}");
|
||||
assert!(!rendered.iter().any(|row| row.starts_with("used")), "{rendered:?}");
|
||||
|
||||
let session = rendered.iter().position(|row| row.contains("SESSION")).expect("a heading");
|
||||
let window = rendered.iter().position(|row| row.starts_with("context")).expect("a window");
|
||||
assert_eq!(window, session + 1, "the window leads the block: {rendered:?}");
|
||||
assert!(rendered[window].ends_with("42% of 200k"), "{:?}", rendered[window]);
|
||||
assert!(rendered[window].contains(Icon::Context.glyph()), "{:?}", rendered[window]);
|
||||
}
|
||||
|
||||
/// Occupancy is a figure, not a chart — the same rule `/context` already holds itself to.
|
||||
///
|
||||
/// A ten-cell bar between the glyph and the number drew what the number already said, and left
|
||||
/// this the one row in the block whose value missed the column its neighbors share. At the
|
||||
/// occupancy a session spends most of its life at it was mostly empty rail, which read as a
|
||||
/// trench rather than a meter. The severity hue survives it, because that part is information.
|
||||
#[test]
|
||||
fn the_window_is_a_figure_rather_than_a_bar() {
|
||||
let mut app = app();
|
||||
app.status.model = "claude-sonnet-5".into();
|
||||
app.status.context_window = 200_000;
|
||||
|
||||
// The section badges are cut from Block Elements themselves, so they are dropped before
|
||||
// the scan rather than exempting their whole row — a gauge smuggled back into a heading
|
||||
// would still be caught.
|
||||
let caps = [crate::widgets::Cap::Open.glyph(), crate::widgets::Cap::Close.glyph()];
|
||||
for percent in [0.0, 12.4, 42.0, 80.0, 95.0, 100.0] {
|
||||
app.status.context_pct = percent;
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
assert!(
|
||||
!rendered.iter().any(|row| row
|
||||
.chars()
|
||||
.filter(|glyph| !caps.contains(&glyph.to_string().as_str()))
|
||||
.any(|glyph| ('\u{2580}'..='\u{259f}').contains(&glyph))),
|
||||
"a block element is drawn at {percent}%: {rendered:?}"
|
||||
);
|
||||
}
|
||||
|
||||
// And the figure opens on the value column, level with the rows underneath it.
|
||||
let rendered: Vec<String> = telemetry_lines(&app).iter().map(text).collect();
|
||||
let window = rendered.iter().find(|row| row.starts_with("context")).expect("a window");
|
||||
let sibling = rendered.iter().find(|row| row.starts_with("thinking")).expect("a sibling");
|
||||
let opens_at = |row: &str, label: &str| {
|
||||
UnicodeWidthStr::width(&row[..row.len() - row.trim_start_matches(label).trim_start().len()])
|
||||
};
|
||||
assert_eq!(
|
||||
opens_at(window, "context"),
|
||||
opens_at(sibling, "thinking"),
|
||||
"{window:?} against {sibling:?}"
|
||||
);
|
||||
}
|
||||
136
crates/luxe-tui/src/view/dock/tests/tree.rs
Normal file
136
crates/luxe-tui/src/view/dock/tests/tree.rs
Normal file
@@ -0,0 +1,136 @@
|
||||
//! Tree — the file tree in the rail, its filter and its commit hint.
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_tree_takes_the_height_the_rest_of_the_rail_leaves() {
|
||||
// A tall dock gives the tree everything else does not use: it is the project, not a list
|
||||
assert_eq!(files_row_cap(40, 8), 40 - 8 - FILES_FIXED_ROWS);
|
||||
|
||||
// A crowded rail keeps a usable window rather than collapsing: the tree scrolls, so the
|
||||
// rows it cannot show are reachable, and the sections underneath it are reached by
|
||||
// scrolling the panel.
|
||||
assert_eq!(files_row_cap(20, 16), FILE_ROWS_MIN);
|
||||
assert_eq!(files_row_cap(40, 36), FILE_ROWS_MIN);
|
||||
|
||||
// The floor scales down with the panel, so a very short dock still spends most of itself
|
||||
// on everything else — a quarter of the rail rather than a flat five rows.
|
||||
assert_eq!(files_row_cap(12, 10), 3);
|
||||
assert_eq!(files_row_cap(6, 4), 1);
|
||||
}
|
||||
|
||||
/// A commit must not take the way into the review with it.
|
||||
///
|
||||
/// This is the loss a real session reported: the agent committed at the end of its turn, the
|
||||
/// diff against `HEAD` went to zero, the section rendered nothing, and the review that was
|
||||
/// about to be walked had no affordance left anywhere on the surface.
|
||||
/// A filter says what it is filtering by and how much it found, takes a row from the tree
|
||||
/// rather than growing the section, and lights the matched characters in the accent.
|
||||
#[test]
|
||||
fn a_filter_says_what_it_matched_and_lights_it() {
|
||||
let mut app = app();
|
||||
let files = ["src/view/dock.rs".to_string(), "src/app.rs".to_string()];
|
||||
crate::fixture::filter_tree(&mut app, &files, "dock");
|
||||
let section = file_lines(None, &app, 8);
|
||||
let lines: Vec<String> = section.lines.iter().map(text).collect();
|
||||
assert!(lines.iter().any(|line| line.starts_with("/ dock▏") && line.ends_with('1')));
|
||||
assert!(lines.iter().any(|line| line.contains("esc clear")), "{lines:?}");
|
||||
let row = section.lines.iter().find(|line| text(line).contains("dock.rs")).unwrap();
|
||||
let lit: String = row
|
||||
.spans
|
||||
.iter()
|
||||
.filter(|span| span.style.fg == app.theme_styles.accent.fg)
|
||||
.map(|span| span.content.as_ref())
|
||||
.collect();
|
||||
assert_eq!(lit, "dock");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_commit_leaves_the_review_reachable_instead_of_an_empty_rail() {
|
||||
let mut app = app();
|
||||
let rendered = |app: &App| -> String {
|
||||
file_lines(None, app, 8).lines.iter().map(text).collect::<Vec<_>>().join("\n")
|
||||
};
|
||||
assert!(!rendered(&app).contains("committed"), "nothing has happened yet");
|
||||
|
||||
app.worktree_emptied = true;
|
||||
assert!(!rendered(&app).contains("committed"), "and nothing is retained to review");
|
||||
|
||||
app.review.last_turn = Some(("session-1".into(), "turn-1".into()));
|
||||
let rendered = rendered(&app);
|
||||
assert!(rendered.contains("FILES"), "{rendered}");
|
||||
assert!(rendered.contains("committed"), "says where the work went: {rendered}");
|
||||
assert!(rendered.contains("still reviewable"), "and that it is not lost: {rendered}");
|
||||
assert!(rendered.contains("ctrl+g review"), "and how to get there: {rendered}");
|
||||
assert!(
|
||||
!rendered.contains("preview"),
|
||||
"and not how to glance, with nothing left in the worktree to glance at: {rendered}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The way into the review is a row of its own that answers a click.
|
||||
#[test]
|
||||
fn the_committed_review_hint_is_a_row_that_opens_the_review() {
|
||||
let mut app = app();
|
||||
app.worktree_emptied = true;
|
||||
app.review.last_turn = Some(("session-1".into(), "turn-1".into()));
|
||||
let section = file_lines(None, &app, 8);
|
||||
let last = section.lines.len() - 1;
|
||||
assert_eq!(text(§ion.lines[last]), "ctrl+t browse · ctrl+g review");
|
||||
assert!(section
|
||||
.hits
|
||||
.iter()
|
||||
.any(|hit| hit.line == last && hit.target == crate::mouse::MouseTarget::DockReviewChanges));
|
||||
}
|
||||
|
||||
/// The file showing in the preview is told apart by its name, accent and bold, and the band is
|
||||
/// left to the row the keyboard is on, so the two never look alike on different rows.
|
||||
#[test]
|
||||
fn the_showing_file_wears_its_name_and_the_keyboard_row_wears_the_band() {
|
||||
let mut app = app();
|
||||
let showing = TreeRow::File {
|
||||
path: "CHANGELOG.md".into(),
|
||||
name: "CHANGELOG.md".into(),
|
||||
depth: 0,
|
||||
change: None,
|
||||
ignored: false,
|
||||
};
|
||||
let line = tree_row_line(&showing, 40, Some("CHANGELOG.md"), None, &app);
|
||||
let name = line.spans.iter().find(|span| span.content.contains("CHANGELOG")).unwrap();
|
||||
assert_eq!(name.style.fg, app.theme_styles.accent.fg, "the name says it is showing");
|
||||
assert!(name.style.add_modifier.contains(Modifier::BOLD));
|
||||
assert_ne!(name.style.bg, app.theme_styles.selected_bg.bg, "but wears no band");
|
||||
|
||||
app.files.focused = true;
|
||||
app.files.cursor = Some("src".into());
|
||||
let keyed = TreeRow::Folder {
|
||||
path: "src".into(),
|
||||
name: "src".into(),
|
||||
depth: 0,
|
||||
open: false,
|
||||
holds_change: false,
|
||||
ignored: false,
|
||||
};
|
||||
let line = tree_row_line(&keyed, 40, Some("CHANGELOG.md"), None, &app);
|
||||
let name = line.spans.iter().find(|span| span.content == "src").unwrap();
|
||||
assert_eq!(name.style.bg, app.theme_styles.selected_bg.bg, "the keyboard's row is banded");
|
||||
}
|
||||
|
||||
/// The tree says how to reach it from the keyboard, and once the keyboard is in it, what the
|
||||
/// keys do there; the hint answers a click by putting the keyboard in.
|
||||
#[test]
|
||||
fn the_tree_says_how_to_move_through_it_with_keys() {
|
||||
let mut app = app();
|
||||
let section = file_lines(None, &app, 8);
|
||||
let last = section.lines.len() - 1;
|
||||
assert_eq!(text(§ion.lines[last]), "ctrl+t browse");
|
||||
assert!(section
|
||||
.hits
|
||||
.iter()
|
||||
.any(|hit| hit.line == last && hit.target == crate::mouse::MouseTarget::DockFocusFiles));
|
||||
|
||||
app.files.focused = true;
|
||||
let section = file_lines(None, &app, 8);
|
||||
let last = section.lines.len() - 1;
|
||||
assert_eq!(text(§ion.lines[last]), "j k move · l open · / filter · esc back");
|
||||
}
|
||||
Reference in New Issue
Block a user