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>
240 lines
6.4 KiB
Rust
240 lines
6.4 KiB
Rust
// Test data builders and fixtures
|
|
|
|
use tele_tui::tdlib::{ChatInfo, MessageInfo, ProfileInfo, ReplyInfo};
|
|
use tele_tui::tdlib::types::{ForwardInfo, ReactionInfo};
|
|
use tele_tui::types::{ChatId, MessageId};
|
|
|
|
/// Builder для создания тестового чата
|
|
pub struct TestChatBuilder {
|
|
id: i64,
|
|
title: String,
|
|
username: Option<String>,
|
|
last_message: String,
|
|
last_message_date: i32,
|
|
unread_count: i32,
|
|
unread_mention_count: i32,
|
|
is_pinned: bool,
|
|
order: i64,
|
|
last_read_outbox_message_id: i64,
|
|
folder_ids: Vec<i32>,
|
|
is_muted: bool,
|
|
draft_text: Option<String>,
|
|
}
|
|
|
|
impl TestChatBuilder {
|
|
pub fn new(title: &str, id: i64) -> Self {
|
|
Self {
|
|
id,
|
|
title: title.to_string(),
|
|
username: None,
|
|
last_message: "".to_string(),
|
|
last_message_date: 1640000000,
|
|
unread_count: 0,
|
|
unread_mention_count: 0,
|
|
is_pinned: false,
|
|
order: id,
|
|
last_read_outbox_message_id: 0,
|
|
folder_ids: vec![0],
|
|
is_muted: false,
|
|
draft_text: None,
|
|
}
|
|
}
|
|
|
|
pub fn username(mut self, username: &str) -> Self {
|
|
self.username = Some(username.to_string());
|
|
self
|
|
}
|
|
|
|
pub fn last_message(mut self, text: &str) -> Self {
|
|
self.last_message = text.to_string();
|
|
self
|
|
}
|
|
|
|
pub fn unread_count(mut self, count: i32) -> Self {
|
|
self.unread_count = count;
|
|
self
|
|
}
|
|
|
|
pub fn unread_mentions(mut self, count: i32) -> Self {
|
|
self.unread_mention_count = count;
|
|
self
|
|
}
|
|
|
|
pub fn pinned(mut self) -> Self {
|
|
self.is_pinned = true;
|
|
self
|
|
}
|
|
|
|
pub fn muted(mut self) -> Self {
|
|
self.is_muted = true;
|
|
self
|
|
}
|
|
|
|
pub fn draft(mut self, text: &str) -> Self {
|
|
self.draft_text = Some(text.to_string());
|
|
self
|
|
}
|
|
|
|
pub fn folder(mut self, folder_id: i32) -> Self {
|
|
self.folder_ids = vec![folder_id];
|
|
self
|
|
}
|
|
|
|
pub fn build(self) -> ChatInfo {
|
|
ChatInfo {
|
|
id: ChatId::new(self.id),
|
|
title: self.title,
|
|
username: self.username,
|
|
last_message: self.last_message,
|
|
last_message_date: self.last_message_date,
|
|
unread_count: self.unread_count,
|
|
unread_mention_count: self.unread_mention_count,
|
|
is_pinned: self.is_pinned,
|
|
order: self.order,
|
|
last_read_outbox_message_id: MessageId::new(self.last_read_outbox_message_id),
|
|
folder_ids: self.folder_ids,
|
|
is_muted: self.is_muted,
|
|
draft_text: self.draft_text,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Builder для создания тестового сообщения
|
|
pub struct TestMessageBuilder {
|
|
id: i64,
|
|
sender_name: String,
|
|
is_outgoing: bool,
|
|
content: String,
|
|
entities: Vec<tdlib_rs::types::TextEntity>,
|
|
date: i32,
|
|
edit_date: i32,
|
|
is_read: bool,
|
|
can_be_edited: bool,
|
|
can_be_deleted_only_for_self: bool,
|
|
can_be_deleted_for_all_users: bool,
|
|
reply_to: Option<ReplyInfo>,
|
|
forward_from: Option<ForwardInfo>,
|
|
reactions: Vec<ReactionInfo>,
|
|
}
|
|
|
|
impl TestMessageBuilder {
|
|
pub fn new(content: &str, id: i64) -> Self {
|
|
Self {
|
|
id,
|
|
sender_name: "User".to_string(),
|
|
is_outgoing: false,
|
|
content: content.to_string(),
|
|
entities: vec![],
|
|
date: 1640000000,
|
|
edit_date: 0,
|
|
is_read: true,
|
|
can_be_edited: false,
|
|
can_be_deleted_only_for_self: true,
|
|
can_be_deleted_for_all_users: false,
|
|
reply_to: None,
|
|
forward_from: None,
|
|
reactions: vec![],
|
|
}
|
|
}
|
|
|
|
pub fn outgoing(mut self) -> Self {
|
|
self.is_outgoing = true;
|
|
self.sender_name = "You".to_string();
|
|
self.can_be_edited = true;
|
|
self.can_be_deleted_for_all_users = true;
|
|
self
|
|
}
|
|
|
|
pub fn sender(mut self, name: &str) -> Self {
|
|
self.sender_name = name.to_string();
|
|
self
|
|
}
|
|
|
|
pub fn date(mut self, timestamp: i32) -> Self {
|
|
self.date = timestamp;
|
|
self
|
|
}
|
|
|
|
pub fn edited(mut self) -> Self {
|
|
self.edit_date = self.date + 60;
|
|
self
|
|
}
|
|
|
|
pub fn unread(mut self) -> Self {
|
|
self.is_read = false;
|
|
self
|
|
}
|
|
|
|
pub fn reply_to(mut self, message_id: i64, sender: &str, text: &str) -> Self {
|
|
self.reply_to = Some(ReplyInfo {
|
|
message_id: MessageId::new(message_id),
|
|
sender_name: sender.to_string(),
|
|
text: text.to_string(),
|
|
});
|
|
self
|
|
}
|
|
|
|
pub fn forwarded_from(mut self, sender: &str) -> Self {
|
|
self.forward_from = Some(ForwardInfo {
|
|
sender_name: sender.to_string(),
|
|
});
|
|
self
|
|
}
|
|
|
|
pub fn reaction(mut self, emoji: &str, count: i32, chosen: bool) -> Self {
|
|
self.reactions
|
|
.push(ReactionInfo { emoji: emoji.to_string(), count, is_chosen: chosen });
|
|
self
|
|
}
|
|
|
|
pub fn build(self) -> MessageInfo {
|
|
MessageInfo::new(
|
|
MessageId::new(self.id),
|
|
self.sender_name,
|
|
self.is_outgoing,
|
|
self.content,
|
|
self.entities,
|
|
self.date,
|
|
self.edit_date,
|
|
self.is_read,
|
|
self.can_be_edited,
|
|
self.can_be_deleted_only_for_self,
|
|
self.can_be_deleted_for_all_users,
|
|
self.reply_to,
|
|
self.forward_from,
|
|
self.reactions,
|
|
)
|
|
}
|
|
}
|
|
|
|
/// Хелперы для быстрого создания тестовых данных
|
|
|
|
pub fn create_test_chat(title: &str, id: i64) -> ChatInfo {
|
|
TestChatBuilder::new(title, id).build()
|
|
}
|
|
|
|
pub fn create_test_message(content: &str, id: i64) -> MessageInfo {
|
|
TestMessageBuilder::new(content, id).build()
|
|
}
|
|
|
|
pub fn create_test_user(name: &str, id: i64) -> (i64, String) {
|
|
(id, name.to_string())
|
|
}
|
|
|
|
/// Хелпер для создания профиля
|
|
pub fn create_test_profile(title: &str, chat_id: i64) -> ProfileInfo {
|
|
ProfileInfo {
|
|
chat_id: ChatId::new(chat_id),
|
|
title: title.to_string(),
|
|
username: None,
|
|
bio: None,
|
|
phone_number: None,
|
|
chat_type: "Личный чат".to_string(),
|
|
member_count: None,
|
|
description: None,
|
|
invite_link: None,
|
|
is_group: false,
|
|
online_status: None,
|
|
}
|
|
}
|