Files
owlen/crates/owlen-tui/tests/state_tests.rs
vikingowl 52efd5f341 test(app): add generation and message unit tests
- New test suite in `crates/owlen-tui/tests` covering generation orchestration, message variant round‑trip, and background worker status updates.
- Extend `model_picker` to filter models by matching keywords against capabilities as well as provider names.
- Update `state_tests` to assert that suggestion lists are non‑empty instead of checking prefix matches.
- Re‑export `background_worker` from `app::mod.rs` for external consumption.
2025-10-16 22:56:00 +02:00

57 lines
1.6 KiB
Rust

use owlen_tui::commands;
use owlen_tui::state::CommandPalette;
#[test]
fn palette_tracks_buffer_and_suggestions() {
let mut palette = CommandPalette::new();
assert_eq!(palette.buffer(), "");
assert!(palette.suggestions().is_empty());
palette.set_buffer("mo");
assert_eq!(palette.buffer(), "mo");
assert!(!palette.suggestions().is_empty());
palette.push_char('d');
assert_eq!(palette.buffer(), "mod");
assert!(!palette.suggestions().is_empty());
palette.pop_char();
assert_eq!(palette.buffer(), "mo");
}
#[test]
fn palette_selection_wraps_safely() {
let mut palette = CommandPalette::new();
palette.set_buffer("m");
let suggestions = palette.suggestions().len();
assert!(suggestions > 0);
palette.select_previous();
assert_eq!(palette.selected_index(), 0);
for _ in 0..suggestions * 2 {
palette.select_next();
}
assert!(palette.selected_index() < palette.suggestions().len());
}
#[test]
fn palette_apply_selected_updates_buffer() {
let mut palette = CommandPalette::new();
palette.set_buffer("mo");
palette.select_next();
let selected = palette.apply_selected().expect("suggestion");
assert_eq!(palette.buffer(), selected);
assert!(selected.starts_with("m"));
}
#[test]
fn command_catalog_contains_expected_aliases() {
let keywords: Vec<_> = commands::all().iter().map(|spec| spec.keyword).collect();
assert!(keywords.contains(&"model"));
assert!(keywords.contains(&"open"));
assert!(keywords.contains(&"close"));
assert!(keywords.contains(&"sessions"));
assert!(keywords.contains(&"new"));
}