added: INFO-level snapshot + popup_area unit tests; rename narrow_frame test

This commit is contained in:
objz committed 2026-05-26 21:00:06 +02:00
1 parent 05bea59ef1
commit 2163fef175
3 files changed
+63 -1

No files matched your search

+54 -1
View File
@@ -138,6 +138,14 @@ mod render_tests {
insta::assert_snapshot!(term.backend());
}
// info-level events hit the catch-all `_` arm in the label match; previously
// there was no test covering it.
#[test]
fn info_level_renders() {
let term = render(event(Level::INFO, "Reloaded config"), 40, 5);
insta::assert_snapshot!(term.backend());
}
#[test]
fn long_message_wraps() {
let msg = "The Minecraft launcher could not reach the Mojang version manifest \
@@ -147,8 +155,53 @@ mod render_tests {
}
#[test]
fn narrow_frame_clamps() {
fn narrow_frame_renders() {
let term = render(event(Level::WARN, "Short message"), 18, 5);
insta::assert_snapshot!(term.backend());
}
}
#[cfg(test)]
mod area_tests {
use super::popup_area;
use crate::config::SETTINGS;
use ratatui::layout::Rect;
fn frame() -> Rect {
Rect::new(0, 0, 80, 24)
}
#[test]
fn returns_none_after_dismiss_timeout() {
let past_dismiss = SETTINGS.ui.error_auto_dismiss_ms as u128 + 1;
assert!(popup_area(frame(), "msg", 0, past_dismiss).is_none());
}
#[test]
fn returns_some_inside_dismiss_window() {
assert!(popup_area(frame(), "msg", 0, 0).is_some());
}
#[test]
fn returns_none_when_vertical_room_too_small() {
// base_y = 22 leaves only height 24 - 22 - 1 = 1 row of usable space,
// less than the minimum 3 needed for border + content + border.
assert!(popup_area(frame(), "msg", 22, 0).is_none());
}
#[test]
fn clamps_popup_width_to_frame() {
// a wider-than-the-frame message gets clamped so the popup fits
// inside frame.width minus the right-edge padding (saturating_sub(4)).
let huge = "x".repeat(200);
let area = popup_area(frame(), &huge, 0, 0).unwrap();
assert!(area.width <= frame().width.saturating_sub(4));
}
#[test]
fn anchors_popup_to_right_edge() {
let area = popup_area(frame(), "msg", 0, 0).unwrap();
// popup_w is added to base_x to reach frame.width - 2 (right-edge gutter)
assert_eq!(area.x + area.width + 2, frame().width);
}
}
@@ -0,0 +1,9 @@
---
source: src/tui/widgets/popups/error.rs
expression: term.backend()
---
"╭ INFO ────────────────────────────────╮"
"│Reloaded config │"
"│ │"
"│ │"
"╰──────────────────────────────────────╯"