Some checks failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
Comprehensive cleanup of unused methods, dead code, and compiler warnings:
## Removed Methods (15):
- Duplicate delegation methods: is_authenticated, get_typing_text, get_user_name from TdClient
- Obsolete methods: TdClient::init() (duplicated in main.rs)
- Unused getters: UserCache::{get_username, get_name, get_user_id_by_chat}
- Unused builder methods: MessageBuilder::{edited, add_reaction}
- Unused utility: ChatState::is_normal()
- Dead code: HotkeysConfig::{matches, key_matches} (kept for tests)
- Unused method: UserCache::register_private_chat()
- Getter replaced with direct field access: MessageInfo::edit_date()
## Removed Module:
- error.rs - Unused error handling module (TeletuiError, ErrorVariant, IntoTeletuiError)
## Removed Constants (8):
- EMOJI_PICKER_COLUMNS, EMOJI_PICKER_ROWS, MAX_INPUT_HEIGHT
- MIN_TERMINAL_WIDTH, MIN_TERMINAL_HEIGHT
- TDLIB_CHAT_LIMIT, MAX_USERNAME_DISPLAY_LENGTH, MESSAGE_TEXT_INDENT
## Fixed Warnings:
- Removed unused imports (8 instances)
- Fixed unreachable patterns (10 instances)
- Fixed irrefutable if let patterns (2 instances)
- Fixed unused variables (1 instance)
- Removed dead_code annotations where appropriate
## Improvements:
- Integrated Config::load_credentials() into TdClient::new() for better credential management
- Replaced edit_date() getter with direct field access (message.metadata.edit_date)
- Updated tests to use direct field access instead of removed getters
## Test Results:
All tests passing: 499 passed, 0 failed
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
195 lines
5.4 KiB
Rust
195 lines
5.4 KiB
Rust
// Chat list 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, TestChatBuilder};
|
|
use insta::assert_snapshot;
|
|
|
|
#[test]
|
|
fn snapshot_empty_chat_list() {
|
|
let mut app = TestAppBuilder::new().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!("empty_chat_list", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_chat_list_with_three_chats() {
|
|
let chat1 = create_test_chat("Mom", 123);
|
|
let chat2 = create_test_chat("Boss", 456);
|
|
let chat3 = create_test_chat("Rust Community", 789);
|
|
|
|
let mut app = TestAppBuilder::new()
|
|
.with_chats(vec![chat1, chat2, chat3])
|
|
.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!("chat_list_three_chats", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_chat_with_unread_count() {
|
|
let chat = TestChatBuilder::new("Mom", 123)
|
|
.unread_count(5)
|
|
.last_message("Привет, как дела?")
|
|
.build();
|
|
|
|
let mut app = TestAppBuilder::new().with_chat(chat).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!("chat_with_unread", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_chat_with_pinned() {
|
|
let chat = TestChatBuilder::new("Important Chat", 123)
|
|
.pinned()
|
|
.last_message("Pinned message")
|
|
.build();
|
|
|
|
let mut app = TestAppBuilder::new().with_chat(chat).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!("chat_pinned", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_chat_with_muted() {
|
|
let chat = TestChatBuilder::new("Spam Group", 123)
|
|
.muted()
|
|
.unread_count(99)
|
|
.last_message("Too many messages")
|
|
.build();
|
|
|
|
let mut app = TestAppBuilder::new().with_chat(chat).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!("chat_muted", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_chat_with_mentions() {
|
|
let chat = TestChatBuilder::new("Work Group", 123)
|
|
.unread_count(10)
|
|
.unread_mentions(2)
|
|
.last_message("@me check this out")
|
|
.build();
|
|
|
|
let mut app = TestAppBuilder::new().with_chat(chat).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!("chat_with_mentions", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_selected_chat() {
|
|
let chat1 = create_test_chat("Mom", 123);
|
|
let chat2 = create_test_chat("Boss", 456);
|
|
|
|
let mut app = TestAppBuilder::new()
|
|
.with_chats(vec![chat1, chat2])
|
|
.selected_chat(123)
|
|
.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!("chat_selected", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_chat_long_title() {
|
|
let chat = TestChatBuilder::new("Very Long Chat Title That Should Be Truncated", 123)
|
|
.last_message("Test message")
|
|
.build();
|
|
|
|
let mut app = TestAppBuilder::new().with_chat(chat).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!("chat_long_title", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_chat_search_mode() {
|
|
let chat1 = create_test_chat("Mom", 123);
|
|
let chat2 = create_test_chat("Boss", 456);
|
|
let chat3 = create_test_chat("Rust Community", 789);
|
|
|
|
let mut app = TestAppBuilder::new()
|
|
.with_chats(vec![chat1, chat2, chat3])
|
|
.searching("Mom")
|
|
.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!("chat_list_search_mode", output);
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_chat_with_online_status() {
|
|
use tele_tui::tdlib::UserOnlineStatus;
|
|
use tele_tui::types::ChatId;
|
|
|
|
let chat = TestChatBuilder::new("Alice", 123)
|
|
.last_message("Hey there!")
|
|
.build();
|
|
|
|
let mut app = TestAppBuilder::new()
|
|
.with_chat(chat)
|
|
.selected_chat(123)
|
|
.build();
|
|
|
|
// Устанавливаем онлайн-статус для чата напрямую
|
|
let chat_id = ChatId::new(123);
|
|
let user_id = tele_tui::types::UserId::new(123);
|
|
|
|
// Регистрируем чат как приватный
|
|
app.td_client.user_cache.chat_user_ids.insert(chat_id, user_id);
|
|
|
|
// Устанавливаем онлайн-статус
|
|
app.td_client.user_cache.user_statuses.insert(user_id, UserOnlineStatus::Online);
|
|
|
|
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!("chat_with_online_status", output);
|
|
}
|
|
|