// 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, 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, is_muted: bool, draft_text: Option, } 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, 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, forward_from: Option, reactions: Vec, } 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, } }