Files
telegram-tui/tests/input_field.rs
Mikhail Kilin 433233d766 commit
2026-01-30 17:26:21 +03:00

150 lines
4.5 KiB
Rust

// Input Field UI snapshot tests
mod helpers;
use helpers::app_builder::TestAppBuilder;
use helpers::snapshot_utils::{buffer_to_string, render_to_buffer};
use helpers::test_data::{create_test_chat, TestMessageBuilder};
use insta::assert_snapshot;
#[test]
fn snapshot_empty_input() {
let chat = create_test_chat("Mom", 123);
let app = TestAppBuilder::new()
.with_chat(chat)
.selected_chat(123)
.build();
let buffer = render_to_buffer(80, 24, |f| {
tele_tui::ui::messages::render(f, f.area(), &app);
});
let output = buffer_to_string(&buffer);
assert_snapshot!("empty_input", output);
}
#[test]
fn snapshot_input_with_text() {
let chat = create_test_chat("Mom", 123);
let app = TestAppBuilder::new()
.with_chat(chat)
.selected_chat(123)
.message_input("Hello, how are you?")
.build();
let buffer = render_to_buffer(80, 24, |f| {
tele_tui::ui::messages::render(f, f.area(), &app);
});
let output = buffer_to_string(&buffer);
assert_snapshot!("input_with_text", output);
}
#[test]
fn snapshot_input_long_text_2_lines() {
let chat = create_test_chat("Mom", 123);
// Text that wraps to 2 lines
let long_text = "This is a longer message that will wrap to multiple lines in the input field for testing purposes.";
let app = TestAppBuilder::new()
.with_chat(chat)
.selected_chat(123)
.message_input(long_text)
.build();
let buffer = render_to_buffer(80, 24, |f| {
tele_tui::ui::messages::render(f, f.area(), &app);
});
let output = buffer_to_string(&buffer);
assert_snapshot!("input_long_text_2_lines", output);
}
#[test]
fn snapshot_input_long_text_max_lines() {
let chat = create_test_chat("Mom", 123);
// Very long text that reaches maximum 10 lines
let very_long_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.";
let app = TestAppBuilder::new()
.with_chat(chat)
.selected_chat(123)
.message_input(very_long_text)
.build();
let buffer = render_to_buffer(80, 24, |f| {
tele_tui::ui::messages::render(f, f.area(), &app);
});
let output = buffer_to_string(&buffer);
assert_snapshot!("input_long_text_max_lines", output);
}
#[test]
fn snapshot_input_editing_mode() {
let chat = create_test_chat("Mom", 123);
let message = TestMessageBuilder::new("Original message text", 1)
.outgoing()
.build();
let app = TestAppBuilder::new()
.with_chat(chat)
.with_message(123, message)
.selected_chat(123)
.editing_message(1, 0)
.message_input("Edited text here")
.build();
let buffer = render_to_buffer(80, 24, |f| {
tele_tui::ui::messages::render(f, f.area(), &app);
});
let output = buffer_to_string(&buffer);
assert_snapshot!("input_editing_mode", output);
}
#[test]
fn snapshot_input_reply_mode() {
let chat = create_test_chat("Mom", 123);
let original_msg = TestMessageBuilder::new("What do you think about this?", 1)
.sender("Mom")
.build();
let app = TestAppBuilder::new()
.with_chat(chat)
.with_message(123, original_msg)
.selected_chat(123)
.replying_to(1)
.message_input("I think it's great!")
.build();
let buffer = render_to_buffer(80, 24, |f| {
tele_tui::ui::messages::render(f, f.area(), &app);
});
let output = buffer_to_string(&buffer);
assert_snapshot!("input_reply_mode", output);
}
#[test]
fn snapshot_input_search_mode() {
let chat = create_test_chat("Mom", 123);
let mut app = TestAppBuilder::new()
.with_chat(chat)
.selected_chat(123)
.searching("hello")
.build();
let buffer = render_to_buffer(80, 24, |f| {
tele_tui::ui::chat_list::render(f, f.area(), &mut app);
});
let output = buffer_to_string(&buffer);
assert_snapshot!("input_search_mode", output);
}