(177665) Add ls command
This commit is contained in:
+177
@@ -0,0 +1,177 @@
|
||||
use assert_cmd::Command;
|
||||
use assert_fs::TempDir;
|
||||
use assert_fs::fixture::{PathChild, PathCreateDir};
|
||||
use std::fs;
|
||||
|
||||
const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane");
|
||||
|
||||
fn setup_worklane(temp: &TempDir) -> std::path::PathBuf {
|
||||
let worklane = temp.child(".worklane");
|
||||
worklane.create_dir_all().unwrap();
|
||||
|
||||
for dir in ["backlog", "committed", "reviewing", "done"] {
|
||||
worklane.child(dir).create_dir_all().unwrap();
|
||||
}
|
||||
|
||||
worklane.path().to_path_buf()
|
||||
}
|
||||
|
||||
fn create_ticket(
|
||||
worklane_dir: &std::path::PathBuf,
|
||||
status: &str,
|
||||
title: &str,
|
||||
owner: &str,
|
||||
due: &str,
|
||||
) {
|
||||
let ticket_body = format!(
|
||||
"# {}\n\
|
||||
\n\
|
||||
## Description\n\
|
||||
test desc\n\
|
||||
\n\
|
||||
## Acceptance Criteria\n\
|
||||
- [ ] test\n\
|
||||
\n\
|
||||
## Implementation Plan\n\
|
||||
- test\n\
|
||||
\n\
|
||||
## Metadata\n\
|
||||
\n\
|
||||
- **ID**: 00000000-0000-0000-0000-000000000001\n\
|
||||
- **Tags**: test\n\
|
||||
- **Due**: {}\n\
|
||||
- **Owner**: {}\n\
|
||||
- **Status**: {}\n\
|
||||
",
|
||||
title, due, owner, status
|
||||
);
|
||||
let slug = title
|
||||
.to_lowercase()
|
||||
.chars()
|
||||
.filter(|c| c.is_alphanumeric() || *c == ' ' || *c == '-' || *c == '_')
|
||||
.map(|c| if c == ' ' { '-' } else { c })
|
||||
.collect::<String>();
|
||||
let filename = format!("00000000-0000-0000-0000-000000000001_{}.md", slug);
|
||||
fs::write(worklane_dir.join(status).join(&filename), ticket_body).unwrap();
|
||||
}
|
||||
|
||||
fn get_stdout(cmd: &mut Command) -> String {
|
||||
let assert = cmd.assert();
|
||||
String::from_utf8(assert.get_output().stdout.clone()).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_without_status_shows_overview() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
create_ticket(&worklane, "backlog", "Feature A", "alice", "2026-06-01");
|
||||
create_ticket(&worklane, "backlog", "Feature B", "bob", "2026-07-01");
|
||||
create_ticket(&worklane, "committed", "Feature C", "charlie", "2026-08-01");
|
||||
create_ticket(&worklane, "done", "Feature D", "dave", "2026-09-01");
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path()).arg("ls").assert().success();
|
||||
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert!(stdout.contains("BACKLOG"));
|
||||
assert!(stdout.contains("2 tickets"));
|
||||
assert!(stdout.contains("COMMITTED"));
|
||||
assert!(stdout.contains("1 ticket"));
|
||||
assert!(stdout.contains("DONE"));
|
||||
assert!(stdout.contains("Feature A"));
|
||||
assert!(stdout.contains("Feature B"));
|
||||
assert!(stdout.contains("Feature C"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_with_status_filters_tickets() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
create_ticket(&worklane, "backlog", "Feature A", "alice", "2026-06-01");
|
||||
create_ticket(&worklane, "committed", "Feature B", "bob", "2026-07-01");
|
||||
create_ticket(&worklane, "reviewing", "Feature C", "charlie", "2026-08-01");
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path())
|
||||
.arg("ls")
|
||||
.args(["--status", "committed"]);
|
||||
|
||||
cmd.assert().success();
|
||||
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert!(stdout.contains("Feature B"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_with_invalid_status_fails() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path())
|
||||
.arg("ls")
|
||||
.args(["--status", "nonexistent"])
|
||||
.assert()
|
||||
.failure();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_listed_tickets_sorted_alphabetically() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
create_ticket(&worklane, "backlog", "Zebra", "alice", "2026-06-01");
|
||||
create_ticket(&worklane, "backlog", "Apple", "bob", "2026-07-01");
|
||||
create_ticket(&worklane, "backlog", "Mango", "charlie", "2026-08-01");
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path())
|
||||
.arg("ls")
|
||||
.args(["--status", "backlog"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
let apple_pos = stdout.find("Apple");
|
||||
let mango_pos = stdout.find("Mango");
|
||||
let zebra_pos = stdout.find("Zebra");
|
||||
assert!(apple_pos.is_some() && mango_pos.is_some() && zebra_pos.is_some());
|
||||
assert!(apple_pos.unwrap() < mango_pos.unwrap());
|
||||
assert!(mango_pos.unwrap() < zebra_pos.unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_empty_status_shows_message() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
|
||||
// Intentionally leave "done" empty
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path())
|
||||
.arg("ls")
|
||||
.args(["--status", "done"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert!(stdout.contains("No tickets in 'done'"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_displays_owner_and_due() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
create_ticket(&worklane, "backlog", "Test ticket", "alice", "2026-12-31");
|
||||
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path())
|
||||
.arg("ls")
|
||||
.args(["--status", "backlog"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let stdout = get_stdout(&mut cmd);
|
||||
assert!(stdout.contains("alice"));
|
||||
assert!(stdout.contains("2026-12-31"));
|
||||
}
|
||||
Reference in New Issue
Block a user