Files
logbuch/tests/models_integration.rs
itsscb 755bdb063e refactor: extract actions module and keycode helpers
- Created actions/ module with save, load, delete business logic
- Created inputs/keycodes.rs with 30+ keybinding helper functions
- Separated business logic from UI/event handling
- Added 28 new unit tests and 8 integration tests
- Fixed bug: save now requires ctrl+s not just 's'
- Reduced ui/mod.rs from 618 to ~290 lines total
2026-01-07 02:38:15 +01:00

55 lines
1.7 KiB
Rust

use logbuch::models::{Entry, SortField, SortOrder};
#[test]
fn entry_display_title_with_subject() {
let entry = Entry::new(
"This is the message body that should be truncated if too long".to_string(),
Some("My Subject".to_string()),
);
assert_eq!(entry.display_title(), "My Subject");
}
#[test]
fn entry_display_title_without_subject_short_message() {
let entry = Entry::new("Short message".to_string(), None);
assert_eq!(entry.display_title(), "Short message");
}
#[test]
fn sort_order_toggle_bidirectional() {
let asc = SortOrder::Ascending;
let desc = SortOrder::Descending;
assert_eq!(asc.toggle(), SortOrder::Descending);
assert_eq!(desc.toggle(), SortOrder::Ascending);
}
#[test]
fn sort_field_as_str_values() {
assert_eq!(SortField::Subject.as_str(), "subject");
assert_eq!(SortField::Created.as_str(), "created_at");
}
#[test]
fn entry_with_all_fields() {
let mut entry = Entry::new("Test message".to_string(), Some("Test subject".to_string()));
entry.tags.push("rust".to_string());
entry.tags.push("programming".to_string());
entry.mentions.push("user".to_string());
assert_eq!(entry.message, "Test message");
assert_eq!(entry.subject, Some("Test subject".to_string()));
assert_eq!(entry.tags, vec!["rust", "programming"]);
assert_eq!(entry.mentions, vec!["user"]);
}
#[test]
fn entry_clone_preserves_data() {
let mut entry = Entry::new("original".to_string(), Some("subject".to_string()));
entry.tags.push("tag1".to_string());
let cloned = entry.clone();
assert_eq!(cloned.message, "original");
assert_eq!(cloned.subject, Some("subject".to_string()));
assert_eq!(cloned.tags, vec!["tag1"]);
}