|
|
|
@@ -30,6 +30,19 @@ pub struct Column {
|
|
|
|
|
pub tickets: Vec<TicketItem>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// What the detail view holds while it is open: the ticket it belongs to, then its
|
|
|
|
|
/// body and comments as one plain text.
|
|
|
|
|
///
|
|
|
|
|
/// The title travels beside the text rather than inside it, because it does not
|
|
|
|
|
/// scroll: it names the overlay from the border, where no amount of reading can
|
|
|
|
|
/// carry it off the screen.
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct Detail {
|
|
|
|
|
pub title: String,
|
|
|
|
|
pub id: String,
|
|
|
|
|
pub text: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// What is on screen.
|
|
|
|
|
pub struct Board {
|
|
|
|
|
pub columns: Vec<Column>,
|
|
|
|
@@ -38,10 +51,13 @@ pub struct Board {
|
|
|
|
|
/// First visible line of each column, counted in card lines. Parallel to
|
|
|
|
|
/// `columns`, so a tick that reshapes the board resizes it in step.
|
|
|
|
|
pub offsets: Vec<u16>,
|
|
|
|
|
/// The body and comments of the selected ticket, when the detail view is open.
|
|
|
|
|
pub detail: Option<String>,
|
|
|
|
|
/// The open detail view, when one is open.
|
|
|
|
|
pub detail: Option<Detail>,
|
|
|
|
|
/// First visible line of the detail view, counted in wrapped lines.
|
|
|
|
|
pub offset: u16,
|
|
|
|
|
/// Whether the done column is drawn. Off at startup, and not remembered between
|
|
|
|
|
/// runs: worklane has no config file, and one flag is not a reason to start one.
|
|
|
|
|
pub show_done: bool,
|
|
|
|
|
pub should_quit: bool,
|
|
|
|
|
worklane_dir: PathBuf,
|
|
|
|
|
digest: u64,
|
|
|
|
@@ -56,6 +72,7 @@ impl Board {
|
|
|
|
|
offsets: Vec::new(),
|
|
|
|
|
detail: None,
|
|
|
|
|
offset: 0,
|
|
|
|
|
show_done: false,
|
|
|
|
|
should_quit: false,
|
|
|
|
|
worklane_dir: worklane_dir.to_path_buf(),
|
|
|
|
|
digest: 0,
|
|
|
|
@@ -109,15 +126,63 @@ impl Board {
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The columns that are drawn: all of them, or everything up to done.
|
|
|
|
|
///
|
|
|
|
|
/// A prefix rather than a filter, which is what keeps `column` and `offsets` usable
|
|
|
|
|
/// as indices into either. Taken from where done actually is instead of assuming the
|
|
|
|
|
/// last slot, with a test pinning done as last so the two cannot drift apart.
|
|
|
|
|
pub fn visible(&self) -> &[Column] {
|
|
|
|
|
&self.columns[..self.visible_count()]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn visible_count(&self) -> usize {
|
|
|
|
|
if self.show_done {
|
|
|
|
|
return self.columns.len();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
match self.columns.iter().position(|column| column.status == DONE) {
|
|
|
|
|
Some(index) => index,
|
|
|
|
|
None => self.columns.len(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Show or hide the done column.
|
|
|
|
|
///
|
|
|
|
|
/// `ls` already holds this opinion: it counts done in its summary and leaves it out
|
|
|
|
|
/// of the listing. Done only grows, so a quarter of the width goes to the column
|
|
|
|
|
/// least often read while the three being worked get squeezed for it.
|
|
|
|
|
///
|
|
|
|
|
/// Hiding is a change to what is drawn, never to what is read. The directory stays
|
|
|
|
|
/// scanned and stays in the digest, so the count in the footer is right and revealing
|
|
|
|
|
/// the column needs no rescan.
|
|
|
|
|
pub fn toggle_done(&mut self, screen: Size) {
|
|
|
|
|
self.show_done = !self.show_done;
|
|
|
|
|
|
|
|
|
|
// Showing done again appends a column, so nothing below is reached and the
|
|
|
|
|
// selection stays exactly where it was.
|
|
|
|
|
if self.column < self.visible_count() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hiding the column the selection is in moves it to the last one still drawn.
|
|
|
|
|
// An open detail closes with it: it is showing a ticket that is no longer on the
|
|
|
|
|
// board, and quietly swapping it for a different ticket is worse than closing.
|
|
|
|
|
self.clamp();
|
|
|
|
|
self.detail = None;
|
|
|
|
|
self.offset = 0;
|
|
|
|
|
self.follow_selection(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Keep the selection on a card that exists, after the board changes under it.
|
|
|
|
|
fn clamp(&mut self) {
|
|
|
|
|
if self.columns.is_empty() {
|
|
|
|
|
let visible = self.visible_count();
|
|
|
|
|
if visible == 0 {
|
|
|
|
|
self.column = 0;
|
|
|
|
|
self.card = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.column = self.column.min(self.columns.len() - 1);
|
|
|
|
|
self.column = self.column.min(visible - 1);
|
|
|
|
|
let count = self.columns[self.column].tickets.len();
|
|
|
|
|
self.card = match count {
|
|
|
|
|
0 => 0,
|
|
|
|
@@ -133,11 +198,12 @@ impl Board {
|
|
|
|
|
|
|
|
|
|
/// Move between columns, keeping the card index where it can land.
|
|
|
|
|
pub fn select_column(&mut self, delta: isize, screen: Size) {
|
|
|
|
|
if self.columns.is_empty() {
|
|
|
|
|
if self.visible_count() == 0 {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let last = self.columns.len() as isize - 1;
|
|
|
|
|
// Bounded by what is drawn, so the selection cannot walk into a hidden column.
|
|
|
|
|
let last = self.visible_count() as isize - 1;
|
|
|
|
|
let next = (self.column as isize + delta).clamp(0, last);
|
|
|
|
|
self.column = next as usize;
|
|
|
|
|
self.clamp();
|
|
|
|
@@ -221,7 +287,7 @@ impl Board {
|
|
|
|
|
let text = detail_text_area(Rect::new(0, 0, screen.width, screen.height));
|
|
|
|
|
// A screenful less a line, so the eye has something to land on after the jump.
|
|
|
|
|
let step = text.height.saturating_sub(1).max(1) as isize;
|
|
|
|
|
let last = last_offset(detail, text) as isize;
|
|
|
|
|
let last = last_offset(&detail.text, text) as isize;
|
|
|
|
|
|
|
|
|
|
self.offset = (self.offset as isize + pages.saturating_mul(step)).clamp(0, last) as u16;
|
|
|
|
|
}
|
|
|
|
@@ -236,11 +302,12 @@ impl Board {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The whole ticket as plain text: the body as `show` renders it, then the comments.
|
|
|
|
|
/// The ticket as the detail view holds it: its name and short id, then the body as
|
|
|
|
|
/// `show` renders it and the comments.
|
|
|
|
|
///
|
|
|
|
|
/// Plain rather than coloured, since ratatui draws styled spans and an escape sequence
|
|
|
|
|
/// in a paragraph would be printed as literal bytes.
|
|
|
|
|
fn detail_of(ticket: &TicketItem) -> String {
|
|
|
|
|
fn detail_of(ticket: &TicketItem) -> Detail {
|
|
|
|
|
let content = std::fs::read_to_string(&ticket.path).unwrap_or_default();
|
|
|
|
|
let mut out = content_trim(&content, false);
|
|
|
|
|
|
|
|
|
@@ -254,7 +321,11 @@ fn detail_of(ticket: &TicketItem) -> String {
|
|
|
|
|
|
|
|
|
|
out.push('\n');
|
|
|
|
|
out.push_str(&format_comments_with(&comments, false));
|
|
|
|
|
out
|
|
|
|
|
Detail {
|
|
|
|
|
title: ticket.title.clone(),
|
|
|
|
|
id: ticket.id.clone(),
|
|
|
|
|
text: out,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A fingerprint of every ticket and comment file: name, length and modified time.
|
|
|
|
@@ -326,10 +397,12 @@ pub fn draw(frame: &mut Frame, board: &Board) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) {
|
|
|
|
|
let widths: Vec<Constraint> = board
|
|
|
|
|
.columns
|
|
|
|
|
// Only the drawn columns are measured, so hiding done gives its width back to the
|
|
|
|
|
// three that are left rather than leaving a gap where it was.
|
|
|
|
|
let columns = board.visible();
|
|
|
|
|
let widths: Vec<Constraint> = columns
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|_| Constraint::Ratio(1, board.columns.len().max(1) as u32))
|
|
|
|
|
.map(|_| Constraint::Ratio(1, columns.len().max(1) as u32))
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
let areas = Layout::default()
|
|
|
|
@@ -337,7 +410,7 @@ fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) {
|
|
|
|
|
.constraints(widths)
|
|
|
|
|
.split(area);
|
|
|
|
|
|
|
|
|
|
for (index, column) in board.columns.iter().enumerate() {
|
|
|
|
|
for (index, column) in columns.iter().enumerate() {
|
|
|
|
|
let focused = index == board.column;
|
|
|
|
|
let title = format!(" {} ({}) ", column.status, column.tickets.len());
|
|
|
|
|
|
|
|
|
@@ -464,9 +537,16 @@ fn card_lines(ticket: &TicketItem, selected: bool) -> Vec<Line<'static>> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
|
|
|
|
|
// While done is hidden its count goes here, which is the board's version of the
|
|
|
|
|
// summary line `ls` prints above a listing that leaves done out.
|
|
|
|
|
let done = match board.show_done {
|
|
|
|
|
true => "d hide done".to_string(),
|
|
|
|
|
false => format!("d show done ({})", done_count(board)),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let keys = match board.detail {
|
|
|
|
|
Some(_) => " ←→↑↓ select pgup/pgdn scroll enter close q quit ",
|
|
|
|
|
None => " ←→ column ↑↓ card enter detail q quit ",
|
|
|
|
|
Some(_) => format!(" ←→↑↓ select pgup/pgdn scroll enter close {done} q quit "),
|
|
|
|
|
None => format!(" ←→ column ↑↓ card enter detail {done} q quit "),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
frame.render_widget(
|
|
|
|
@@ -475,6 +555,15 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// How many tickets are in done, drawn or not.
|
|
|
|
|
fn done_count(board: &Board) -> usize {
|
|
|
|
|
board
|
|
|
|
|
.columns
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|column| column.status == DONE)
|
|
|
|
|
.map_or(0, |column| column.tickets.len())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Where the detail overlay sits in the frame.
|
|
|
|
|
///
|
|
|
|
|
/// Inset, so the board stays visible around the edges and the overlay reads as one.
|
|
|
|
@@ -510,24 +599,24 @@ fn last_offset(detail: &str, text: Rect) -> u16 {
|
|
|
|
|
.saturating_sub(text.height)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw_detail(frame: &mut Frame, detail: &str, offset: u16, area: Rect) {
|
|
|
|
|
fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
|
|
|
|
|
let overlay = detail_overlay(area);
|
|
|
|
|
|
|
|
|
|
// Clamped here as well as on the keypress: the terminal may have been resized since,
|
|
|
|
|
// and a ticket read to its end can grow shorter under a tick.
|
|
|
|
|
let offset = offset.min(last_offset(detail, detail_text_area(area)));
|
|
|
|
|
let offset = offset.min(last_offset(&detail.text, detail_text_area(area)));
|
|
|
|
|
|
|
|
|
|
let block = Block::default()
|
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
|
.border_style(Style::default().fg(Color::Cyan.into()))
|
|
|
|
|
.title(Span::styled(
|
|
|
|
|
" ticket ",
|
|
|
|
|
detail_title(detail, overlay.width),
|
|
|
|
|
Style::default().fg(Color::Orange.into()),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
frame.render_widget(Clear, overlay);
|
|
|
|
|
frame.render_widget(
|
|
|
|
|
Paragraph::new(detail.to_string())
|
|
|
|
|
Paragraph::new(detail.text.to_string())
|
|
|
|
|
.block(block)
|
|
|
|
|
.wrap(Wrap { trim: false })
|
|
|
|
|
.scroll((offset, 0)),
|
|
|
|
@@ -535,6 +624,35 @@ fn draw_detail(frame: &mut Frame, detail: &str, offset: u16, area: Rect) {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The overlay's title: the short id and the name of the ticket it has open.
|
|
|
|
|
///
|
|
|
|
|
/// The id goes first because that is how every other view addresses a ticket, and the
|
|
|
|
|
/// name after it because that is what the id is shorthand for. Both sit on the border
|
|
|
|
|
/// rather than at the head of the paragraph, so reading to the end of a long ticket
|
|
|
|
|
/// cannot carry them off the screen.
|
|
|
|
|
///
|
|
|
|
|
/// The string is cut here rather than left to the renderer, which truncates an
|
|
|
|
|
/// overlong title at whatever cell it reaches and would take the id with it. Cut
|
|
|
|
|
/// against the inner width — a border column on either side is not the title's to
|
|
|
|
|
/// write on — the id survives whole and the name ends in an ellipsis where it was
|
|
|
|
|
/// trimmed. On an overlay too narrow for even the id, what fits is what shows.
|
|
|
|
|
fn detail_title(detail: &Detail, overlay_width: u16) -> String {
|
|
|
|
|
let room = overlay_width.saturating_sub(2) as usize;
|
|
|
|
|
let full = format!(" ({}) · {} ", detail.id, detail.title);
|
|
|
|
|
if full.chars().count() <= room {
|
|
|
|
|
return full;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let prefix = format!(" ({}) · ", detail.id);
|
|
|
|
|
match room.checked_sub(prefix.chars().count() + 1) {
|
|
|
|
|
Some(keep) if keep > 0 => {
|
|
|
|
|
let name: String = detail.title.chars().take(keep).collect();
|
|
|
|
|
format!("{prefix}{name}…")
|
|
|
|
|
}
|
|
|
|
|
_ => full.chars().take(room).collect(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
@@ -596,20 +714,213 @@ mod tests {
|
|
|
|
|
.collect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The column headings, which sit on the top border row.
|
|
|
|
|
///
|
|
|
|
|
/// That row alone, because the footer names done as well: a whole-screen search for
|
|
|
|
|
/// `done (0)` passes on the footer whether the column is drawn or not, which is how
|
|
|
|
|
/// three of these tests came to be vacuous the moment done was hidden.
|
|
|
|
|
fn headings(board: &Board, width: u16, height: u16) -> String {
|
|
|
|
|
render(board, width, height).remove(0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn footer(board: &Board, width: u16, height: u16) -> String {
|
|
|
|
|
render(board, width, height).pop().expect("no rows rendered")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The overlay's top border row, where the block title sits.
|
|
|
|
|
///
|
|
|
|
|
/// Counted in characters rather than bytes: the rows carry multi-byte glyphs.
|
|
|
|
|
fn overlay_title_row(lines: &[String], width: u16, height: u16) -> String {
|
|
|
|
|
let overlay = detail_overlay(Rect::new(0, 0, width, height));
|
|
|
|
|
lines[overlay.y as usize]
|
|
|
|
|
.chars()
|
|
|
|
|
.skip(overlay.x as usize)
|
|
|
|
|
.take(overlay.width as usize)
|
|
|
|
|
.collect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_board_draws_the_four_statuses_as_columns() {
|
|
|
|
|
fn the_board_draws_the_four_statuses_as_columns_once_done_is_shown() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
|
|
|
|
|
write_ticket(&dir, "committed", "22222222-0000-4000-8000-000000000000", "Second one", "");
|
|
|
|
|
|
|
|
|
|
let board = Board::new(&dir).unwrap();
|
|
|
|
|
let screen = render(&board, 120, 20).join("\n");
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
let row = headings(&board, 120, 20);
|
|
|
|
|
|
|
|
|
|
for heading in ["backlog (1)", "committed (1)", "reviewing (0)", "done (0)"] {
|
|
|
|
|
assert!(screen.contains(heading), "no {heading:?} in:\n{screen}");
|
|
|
|
|
assert!(row.contains(heading), "no {heading:?} in:\n{row}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Done only grows, and it is the column least often read. `ls` already leaves it
|
|
|
|
|
/// out of its listing while counting it in the summary; this is the same opinion.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_board_opens_with_the_done_column_hidden() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
|
|
|
|
|
write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished one", "");
|
|
|
|
|
|
|
|
|
|
let board = Board::new(&dir).unwrap();
|
|
|
|
|
assert!(!board.show_done, "done was drawn at startup");
|
|
|
|
|
|
|
|
|
|
let row = headings(&board, 120, 20);
|
|
|
|
|
for heading in ["backlog (1)", "committed (0)", "reviewing (0)"] {
|
|
|
|
|
assert!(row.contains(heading), "no {heading:?} in:\n{row}");
|
|
|
|
|
}
|
|
|
|
|
assert!(!row.contains("done"), "done is still a column:\n{row}");
|
|
|
|
|
|
|
|
|
|
// Hidden, not unread: the count is right and revealing it needs no rescan.
|
|
|
|
|
assert_eq!(board.columns.len(), 4);
|
|
|
|
|
assert_eq!(board.visible().len(), 3);
|
|
|
|
|
assert_eq!(done_count(&board), 1);
|
|
|
|
|
assert!(
|
|
|
|
|
!render(&board, 120, 20).join("\n").contains("Finished one"),
|
|
|
|
|
"a hidden done ticket was drawn"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The three that are left take the width done was using, rather than leaving a gap.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_visible_columns_share_the_full_width() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
|
|
|
|
|
let hidden = headings(&board, 120, 20);
|
|
|
|
|
assert_eq!(hidden.matches('┌').count(), 3, "{hidden}");
|
|
|
|
|
assert!(hidden.ends_with('┐'), "the columns stop short of the edge:\n{hidden}");
|
|
|
|
|
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
let shown = headings(&board, 120, 20);
|
|
|
|
|
assert_eq!(shown.matches('┌').count(), 4, "{shown}");
|
|
|
|
|
assert!(shown.ends_with('┐'), "{shown}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Hiding is a prefix of the columns, which only holds while done is last. The
|
|
|
|
|
/// board leans on that, so the assumption is pinned rather than assumed.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_done_column_is_last() {
|
|
|
|
|
assert_eq!(status_dirs().last(), Some(&DONE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_footer_names_the_key_and_carries_the_count_while_done_is_hidden() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
for (n, title) in [("44444444", "One"), ("55555555", "Two")] {
|
|
|
|
|
write_ticket(&dir, "done", &format!("{n}-0000-4000-8000-000000000000"), title, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
let hidden = footer(&board, 120, 20);
|
|
|
|
|
assert!(hidden.contains("d show done (2)"), "{hidden}");
|
|
|
|
|
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
let shown = footer(&board, 120, 20);
|
|
|
|
|
assert!(shown.contains("d hide done"), "{shown}");
|
|
|
|
|
// With the column drawn, its own heading carries the count.
|
|
|
|
|
assert!(!shown.contains("(2)"), "the count is printed twice:\n{shown}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The modal footer names it too, since the key works with a ticket open.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_detail_footer_also_names_the_done_key() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
|
|
|
|
|
let row = footer(&board, 120, 20);
|
|
|
|
|
assert!(row.contains("d show done (0)"), "{row}");
|
|
|
|
|
assert!(row.contains("pgup/pgdn scroll"), "{row}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Hiding the column under the selection has to move it, or it points at nothing.
|
|
|
|
|
#[test]
|
|
|
|
|
fn hiding_done_under_the_selection_moves_it_to_the_last_visible_column() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(&dir, "reviewing", "33333333-0000-4000-8000-000000000000", "Ready", "");
|
|
|
|
|
write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", "");
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
board.select_column(3, SCREEN);
|
|
|
|
|
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Finished".to_string()));
|
|
|
|
|
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
assert_eq!(board.column, 2, "the selection stayed on a column that is gone");
|
|
|
|
|
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Ready".to_string()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// And an open detail of a done ticket goes with it: showing a ticket that is no
|
|
|
|
|
/// longer on the board is worse than closing, and swapping it for a different
|
|
|
|
|
/// ticket without saying so is worse than both.
|
|
|
|
|
#[test]
|
|
|
|
|
fn hiding_done_closes_a_detail_view_of_a_done_ticket() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(&dir, "reviewing", "33333333-0000-4000-8000-000000000000", "Ready", "");
|
|
|
|
|
write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", "");
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
board.select_column(3, SCREEN);
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
assert!(board.detail.is_some());
|
|
|
|
|
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
assert!(board.detail.is_none(), "{:?}", board.detail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A ticket being read in a column that is not going anywhere stays open.
|
|
|
|
|
#[test]
|
|
|
|
|
fn hiding_done_leaves_a_detail_view_of_another_ticket_open() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
|
|
|
|
|
assert!(board.detail.is_some(), "an unrelated detail view was closed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Done is appended rather than inserted, so showing it moves nothing.
|
|
|
|
|
#[test]
|
|
|
|
|
fn showing_done_again_leaves_the_selection_where_it_was() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(&dir, "committed", "22222222-0000-4000-8000-000000000000", "Alpha", "");
|
|
|
|
|
write_ticket(&dir, "committed", "33333333-0000-4000-8000-000000000000", "Beta", "");
|
|
|
|
|
write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", "");
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.select_column(1, SCREEN);
|
|
|
|
|
board.select_card(1, SCREEN);
|
|
|
|
|
let (column, card) = (board.column, board.card);
|
|
|
|
|
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
assert_eq!((board.column, board.card), (column, card));
|
|
|
|
|
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The selection cannot walk into a column that is not drawn.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_selection_stops_at_the_last_visible_column() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", "");
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.select_column(9, SCREEN);
|
|
|
|
|
assert_eq!(board.column, 2);
|
|
|
|
|
assert!(board.selected().is_none(), "the selection reached the done column");
|
|
|
|
|
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
board.select_column(9, SCREEN);
|
|
|
|
|
assert_eq!(board.column, 3);
|
|
|
|
|
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Finished".to_string()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The card has to carry enough to identify the ticket without opening it.
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_card_shows_the_short_id_title_owner_and_due() {
|
|
|
|
@@ -630,12 +941,13 @@ mod tests {
|
|
|
|
|
fn an_empty_status_renders_as_an_empty_column() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
|
|
|
|
|
let board = Board::new(&dir).unwrap();
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
assert_eq!(board.columns.len(), 4);
|
|
|
|
|
|
|
|
|
|
let screen = render(&board, 120, 20).join("\n");
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
let row = headings(&board, 120, 20);
|
|
|
|
|
for status in status_dirs() {
|
|
|
|
|
assert!(screen.contains(&format!("{status} (0)")), "{screen}");
|
|
|
|
|
assert!(row.contains(&format!("{status} (0)")), "{row}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -643,11 +955,13 @@ mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_missing_status_directory_is_still_a_column() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
std::fs::remove_dir_all(dir.join("done")).unwrap();
|
|
|
|
|
std::fs::remove_dir_all(dir.join(DONE)).unwrap();
|
|
|
|
|
|
|
|
|
|
let board = Board::new(&dir).unwrap();
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
assert_eq!(board.columns.len(), 4);
|
|
|
|
|
assert!(render(&board, 120, 20).join("\n").contains("done (0)"));
|
|
|
|
|
|
|
|
|
|
board.toggle_done(SCREEN);
|
|
|
|
|
assert!(headings(&board, 120, 20).contains("done (0)"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
@@ -974,20 +1288,98 @@ mod tests {
|
|
|
|
|
assert!(board.detail.is_none());
|
|
|
|
|
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
let detail = board.detail.clone().expect("no detail");
|
|
|
|
|
let detail = board.detail.as_ref().expect("no detail");
|
|
|
|
|
|
|
|
|
|
assert!(detail.contains("A description."), "{detail}");
|
|
|
|
|
assert!(detail.contains("Crit one"), "{detail}");
|
|
|
|
|
assert!(detail.contains("A note from elsewhere."), "{detail}");
|
|
|
|
|
assert!(detail.contains("bob"), "{detail}");
|
|
|
|
|
assert!(detail.text.contains("A description."), "{}", detail.text);
|
|
|
|
|
assert!(detail.text.contains("Crit one"), "{}", detail.text);
|
|
|
|
|
assert!(detail.text.contains("A note from elsewhere."), "{}", detail.text);
|
|
|
|
|
assert!(detail.text.contains("bob"), "{}", detail.text);
|
|
|
|
|
|
|
|
|
|
// Plain text, since ratatui would print an escape as literal bytes
|
|
|
|
|
assert!(!detail.contains('\x1b'), "escapes reached the detail view: {detail:?}");
|
|
|
|
|
assert!(
|
|
|
|
|
!detail.text.contains('\x1b'),
|
|
|
|
|
"escapes reached the detail view: {:?}",
|
|
|
|
|
detail.text
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
assert!(board.detail.is_none());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The reported bug: the modal showed a description, criteria and a metadata
|
|
|
|
|
/// table belonging to a ticket it never named.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_detail_view_names_the_ticket_it_has_open() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
|
|
|
|
|
let screen = render(&board, SCREEN.width, SCREEN.height);
|
|
|
|
|
let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
|
|
|
|
|
assert!(row.contains("(1111111)"), "no short id on the border:\n{row}");
|
|
|
|
|
assert!(row.contains("First one"), "no title on the border:\n{row}");
|
|
|
|
|
|
|
|
|
|
// The heading stays out of the text: `show` prints it and here the border
|
|
|
|
|
// carries it, so it is on screen once rather than twice.
|
|
|
|
|
assert!(
|
|
|
|
|
!board.detail.as_ref().unwrap().text.contains("First one"),
|
|
|
|
|
"{:?}",
|
|
|
|
|
board.detail
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Scrolled to the end of a long ticket, the name is still where it started.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_name_stays_on_screen_at_the_end_of_a_long_ticket() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
write_ticket(
|
|
|
|
|
&dir,
|
|
|
|
|
"backlog",
|
|
|
|
|
"11111111-0000-4000-8000-000000000000",
|
|
|
|
|
"First one",
|
|
|
|
|
&long_section(60),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
for _ in 0..20 {
|
|
|
|
|
board.scroll_detail(1, SCREEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let screen = render(&board, SCREEN.width, SCREEN.height);
|
|
|
|
|
assert!(screen.join("\n").contains("Line 060"), "nothing scrolled:\n{}", screen.join("\n"));
|
|
|
|
|
|
|
|
|
|
let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
|
|
|
|
|
assert!(row.contains("(1111111)"), "the id scrolled away:\n{row}");
|
|
|
|
|
assert!(row.contains("First one"), "the title scrolled away:\n{row}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A title longer than the overlay is cut to the border — corners intact, id
|
|
|
|
|
/// whole, ellipsis where the name gave up — not overrun and not dropped whole.
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_long_title_is_cut_to_the_border_it_sits_on() {
|
|
|
|
|
let dir = board_dir();
|
|
|
|
|
// Long enough to pass the overlay's inner width many times over, short enough
|
|
|
|
|
// that its slug still fits a filename.
|
|
|
|
|
let title = format!("Head {} tailmarker", "filler ".repeat(20));
|
|
|
|
|
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", &title, "");
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
|
|
|
|
|
let screen = render(&board, SCREEN.width, SCREEN.height);
|
|
|
|
|
let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
|
|
|
|
|
|
|
|
|
|
assert!(row.starts_with('┌'), "the left corner gave way:\n{row}");
|
|
|
|
|
assert!(row.ends_with('┐'), "the right corner gave way:\n{row}");
|
|
|
|
|
assert!(row.contains("(1111111)"), "the id did not survive the cut:\n{row}");
|
|
|
|
|
assert!(row.contains("Head"), "the border was left blank:\n{row}");
|
|
|
|
|
assert!(row.contains('…'), "the cut read as a complete title:\n{row}");
|
|
|
|
|
assert!(!row.contains("tailmarker"), "the title overran the border:\n{row}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A comment added while the detail view is open shows up on the next tick.
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_tick_picks_up_a_comment_added_under_an_open_detail_view() {
|
|
|
|
@@ -997,7 +1389,7 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
assert!(!board.detail.clone().unwrap().contains("A late note."));
|
|
|
|
|
assert!(!board.detail.as_ref().unwrap().text.contains("A late note."));
|
|
|
|
|
|
|
|
|
|
let comments = dir.join("comments").join(uuid);
|
|
|
|
|
std::fs::create_dir_all(&comments).unwrap();
|
|
|
|
@@ -1008,7 +1400,11 @@ mod tests {
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
assert!(board.tick().unwrap(), "the tick saw no change");
|
|
|
|
|
assert!(board.detail.clone().unwrap().contains("A late note."), "{:?}", board.detail);
|
|
|
|
|
assert!(
|
|
|
|
|
board.detail.as_ref().unwrap().text.contains("A late note."),
|
|
|
|
|
"{:?}",
|
|
|
|
|
board.detail
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
@@ -1129,13 +1525,21 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
let mut board = Board::new(&dir).unwrap();
|
|
|
|
|
board.toggle_detail();
|
|
|
|
|
// By id rather than title: the body leaves the title to the caller that prints
|
|
|
|
|
// the heading, so the detail text does not carry it.
|
|
|
|
|
assert!(board.detail.clone().unwrap().contains("11111111"), "{:?}", board.detail);
|
|
|
|
|
// By id in the text: the heading is stripped from the body, and the title
|
|
|
|
|
// travels beside it for the block title instead.
|
|
|
|
|
assert!(
|
|
|
|
|
board.detail.as_ref().unwrap().text.contains("11111111"),
|
|
|
|
|
"{:?}",
|
|
|
|
|
board.detail
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
board.select_card(1, SCREEN);
|
|
|
|
|
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string()));
|
|
|
|
|
assert!(board.detail.clone().unwrap().contains("22222222"), "{:?}", board.detail);
|
|
|
|
|
assert!(
|
|
|
|
|
board.detail.as_ref().unwrap().text.contains("22222222"),
|
|
|
|
|
"{:?}",
|
|
|
|
|
board.detail
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A newly selected ticket starts at its own top, not where the last one was left.
|
|
|
|
@@ -1244,4 +1648,5 @@ mod tests {
|
|
|
|
|
assert_ne!(tui, ratatui::style::Color::Reset, "level {level} has no colour");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|