229 lines
6.3 KiB
Rust
229 lines
6.3 KiB
Rust
// Screen 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, TestChatBuilder, TestMessageBuilder};
|
|
use insta::assert_snapshot;
|
|
use tele_tui::accounts::AccountProfile;
|
|
use tele_tui::app::AccountSwitcherState;
|
|
use tele_tui::app::AppScreen;
|
|
use tele_tui::tdlib::AuthState;
|
|
|
|
#[test]
|
|
fn snapshot_loading_screen_default() {
|
|
let mut app = TestAppBuilder::new().screen(AppScreen::Loading).build();
|
|
|
|
let buffer = render_to_buffer(80, 24, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("loading_screen_default", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_loading_screen_with_status() {
|
|
let mut app = TestAppBuilder::new()
|
|
.screen(AppScreen::Loading)
|
|
.status_message("Подключение к Telegram...")
|
|
.build();
|
|
|
|
let buffer = render_to_buffer(80, 24, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("loading_screen_with_status", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_auth_screen_phone() {
|
|
let mut app = TestAppBuilder::new()
|
|
.screen(AppScreen::Auth)
|
|
.auth_state(AuthState::WaitPhoneNumber)
|
|
.phone_input("+7")
|
|
.build();
|
|
|
|
let buffer = render_to_buffer(80, 24, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("auth_screen_phone", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_auth_screen_code() {
|
|
let mut app = TestAppBuilder::new()
|
|
.screen(AppScreen::Auth)
|
|
.auth_state(AuthState::WaitCode)
|
|
.code_input("1234")
|
|
.build();
|
|
|
|
let buffer = render_to_buffer(80, 24, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("auth_screen_code", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_auth_screen_password() {
|
|
let mut app = TestAppBuilder::new()
|
|
.screen(AppScreen::Auth)
|
|
.auth_state(AuthState::WaitPassword)
|
|
.password_input("pass")
|
|
.build();
|
|
|
|
let buffer = render_to_buffer(80, 24, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("auth_screen_password", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_main_screen_empty() {
|
|
let mut app = TestAppBuilder::new().screen(AppScreen::Main).build();
|
|
|
|
let buffer = render_to_buffer(80, 24, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("main_screen_empty", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_main_screen_terminal_too_small() {
|
|
let chat = create_test_chat("Mom", 123);
|
|
|
|
let mut app = TestAppBuilder::new()
|
|
.screen(AppScreen::Main)
|
|
.with_chat(chat)
|
|
.build();
|
|
|
|
// Use smaller terminal size (30x8) - below minimum 40x10
|
|
let buffer = render_to_buffer(30, 8, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("main_screen_terminal_too_small", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_main_screen_chat_list_loaded() {
|
|
let mut app = TestAppBuilder::new()
|
|
.screen(AppScreen::Main)
|
|
.with_chats(sample_chats())
|
|
.build();
|
|
|
|
let buffer = render_to_buffer(100, 30, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("main_screen_chat_list_loaded", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_main_screen_chat_open_with_messages() {
|
|
let mut app = TestAppBuilder::new()
|
|
.screen(AppScreen::Main)
|
|
.with_chats(sample_chats())
|
|
.selected_chat(102)
|
|
.with_messages(102, sample_work_messages())
|
|
.message_input("Draft reply")
|
|
.insert_mode()
|
|
.build();
|
|
|
|
let buffer = render_to_buffer(100, 30, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("main_screen_chat_open_with_messages", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_main_screen_chat_open_narrow_valid() {
|
|
let mut app = TestAppBuilder::new()
|
|
.screen(AppScreen::Main)
|
|
.with_chats(sample_chats())
|
|
.selected_chat(102)
|
|
.with_messages(102, sample_work_messages())
|
|
.build();
|
|
|
|
let buffer = render_to_buffer(60, 16, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("main_screen_chat_open_narrow_valid", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_main_screen_account_switcher_overlay() {
|
|
let mut app = TestAppBuilder::new()
|
|
.screen(AppScreen::Main)
|
|
.with_chats(sample_chats())
|
|
.build();
|
|
app.current_account_name = "personal".to_string();
|
|
app.account_switcher = Some(AccountSwitcherState::SelectAccount {
|
|
accounts: vec![
|
|
AccountProfile {
|
|
name: "personal".to_string(),
|
|
display_name: "Personal".to_string(),
|
|
},
|
|
AccountProfile {
|
|
name: "work".to_string(),
|
|
display_name: "Work".to_string(),
|
|
},
|
|
],
|
|
selected_index: 1,
|
|
current_account: "personal".to_string(),
|
|
});
|
|
|
|
let buffer = render_to_buffer(100, 30, |f| {
|
|
tele_tui::ui::render(f, &mut app);
|
|
});
|
|
|
|
let output = buffer_to_string(&buffer);
|
|
assert_snapshot!("main_screen_account_switcher_overlay", output);
|
|
}
|
|
|
|
fn sample_chats() -> Vec<tele_tui::tdlib::ChatInfo> {
|
|
vec![
|
|
TestChatBuilder::new("Mom", 101)
|
|
.last_message("Dinner at 7?")
|
|
.unread_count(2)
|
|
.build(),
|
|
TestChatBuilder::new("Work Group", 102)
|
|
.last_message("Standup notes are ready")
|
|
.unread_mentions(1)
|
|
.build(),
|
|
TestChatBuilder::new("Boss", 103)
|
|
.last_message("Please review the deck")
|
|
.build(),
|
|
]
|
|
}
|
|
|
|
fn sample_work_messages() -> Vec<tele_tui::tdlib::MessageInfo> {
|
|
vec![
|
|
TestMessageBuilder::new("Morning, team", 201)
|
|
.sender("Alice")
|
|
.build(),
|
|
TestMessageBuilder::new("Standup notes are ready", 202)
|
|
.sender("Bob")
|
|
.build(),
|
|
TestMessageBuilder::new("Thanks, I will review them after lunch", 203)
|
|
.outgoing()
|
|
.build(),
|
|
]
|
|
}
|