Add visual TUI test coverage

This commit is contained in:
Mikhail Kilin
2026-05-17 23:09:33 +03:00
parent 51e9cf5c10
commit ceca8ab67e
27 changed files with 3435 additions and 23 deletions

81
tests/style_snapshots.rs Normal file
View File

@@ -0,0 +1,81 @@
// Focused style snapshot tests.
mod helpers;
use helpers::app_builder::TestAppBuilder;
use helpers::snapshot_utils::{buffer_to_style_snapshot, render_to_buffer};
use helpers::test_data::{TestChatBuilder, TestMessageBuilder};
use insta::assert_snapshot;
#[test]
fn snapshot_style_selected_chat() {
let chats = vec![
TestChatBuilder::new("Mom", 101).build(),
TestChatBuilder::new("Work Group", 102).build(),
TestChatBuilder::new("Boss", 103).build(),
];
let mut app = TestAppBuilder::new().with_chats(chats).build();
app.chat_list_state.select(Some(1));
let buffer = render_to_buffer(36, 12, |f| {
tele_tui::ui::chat_list::render(f, f.area(), &mut app);
});
assert_snapshot!("style_selected_chat", buffer_to_style_snapshot(&buffer));
}
#[test]
fn snapshot_style_selected_message() {
let chat = TestChatBuilder::new("Mom", 101).build();
let messages = vec![
TestMessageBuilder::new("First message", 201)
.sender("Mom")
.build(),
TestMessageBuilder::new("Selected message", 202)
.sender("Mom")
.build(),
];
let mut app = TestAppBuilder::new()
.with_chat(chat)
.selected_chat(101)
.with_messages(101, messages)
.selecting_message(1)
.build();
let buffer = render_to_buffer(70, 18, |f| {
tele_tui::ui::messages::render(f, f.area(), &mut app);
});
assert_snapshot!("style_selected_message", buffer_to_style_snapshot(&buffer));
}
#[test]
fn snapshot_style_reaction_picker_selection() {
let chat = TestChatBuilder::new("Mom", 101).build();
let message = TestMessageBuilder::new("React to this", 201)
.sender("Mom")
.build();
let mut app = TestAppBuilder::new()
.with_chat(chat)
.selected_chat(101)
.with_message(101, message)
.reaction_picker(
201,
vec![
"👍".to_string(),
"❤️".to_string(),
"😂".to_string(),
"🔥".to_string(),
],
)
.build();
if let tele_tui::app::ChatState::ReactionPicker { selected_index, .. } = &mut app.chat_state {
*selected_index = 2;
}
let buffer = render_to_buffer(70, 18, |f| {
tele_tui::ui::messages::render(f, f.area(), &mut app);
});
assert_snapshot!("style_reaction_picker_selection", buffer_to_style_snapshot(&buffer));
}