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>
218 lines
7.6 KiB
Rust
218 lines
7.6 KiB
Rust
// Integration tests for reply and forward flow
|
||
|
||
mod helpers;
|
||
|
||
use helpers::fake_tdclient::FakeTdClient;
|
||
use helpers::test_data::TestMessageBuilder;
|
||
use tele_tui::tdlib::ReplyInfo;
|
||
use tele_tui::tdlib::types::ForwardInfo;
|
||
use tele_tui::types::{ChatId, MessageId};
|
||
|
||
/// Test: Reply создаёт сообщение с reply_to
|
||
#[tokio::test]
|
||
async fn test_reply_creates_message_with_reply_to() {
|
||
let client = FakeTdClient::new();
|
||
|
||
// Входящее сообщение от собеседника
|
||
let original_msg = TestMessageBuilder::new("Question?", 100)
|
||
.sender("Alice")
|
||
.build();
|
||
|
||
let client = client.with_message(123, original_msg);
|
||
|
||
// Создаём reply info
|
||
let reply_info = ReplyInfo {
|
||
message_id: MessageId::new(100),
|
||
sender_name: "Alice".to_string(),
|
||
text: "Question?".to_string(),
|
||
};
|
||
|
||
// Отвечаем на него
|
||
let reply_msg = client.send_message(ChatId::new(123), "Answer!".to_string(), Some(MessageId::new(100)), Some(reply_info)).await.unwrap();
|
||
|
||
// Проверяем что ответ отправлен с reply_to
|
||
assert_eq!(client.get_sent_messages().len(), 1);
|
||
assert_eq!(client.get_sent_messages()[0].reply_to, Some(MessageId::new(100)));
|
||
|
||
// Проверяем что в списке 2 сообщения
|
||
let messages = client.get_messages(123);
|
||
assert_eq!(messages.len(), 2);
|
||
assert_eq!(messages[1].id(), reply_msg.id());
|
||
assert_eq!(messages[1].content.text, "Answer!");
|
||
}
|
||
|
||
/// Test: Reply отображает превью оригинального сообщения
|
||
#[tokio::test]
|
||
async fn test_reply_shows_original_preview() {
|
||
let client = FakeTdClient::new();
|
||
|
||
// Создаём сообщение с reply info
|
||
let reply_msg = TestMessageBuilder::new("Reply text", 101)
|
||
.outgoing()
|
||
.reply_to(100, "Alice", "Original")
|
||
.build();
|
||
|
||
let client = client.with_message(123, reply_msg);
|
||
|
||
// Проверяем что reply_to сохранено
|
||
let messages = client.get_messages(123);
|
||
assert_eq!(messages.len(), 1);
|
||
assert!(messages[0].reply_to().is_some());
|
||
|
||
let reply = messages[0].reply_to().unwrap();
|
||
assert_eq!(reply.message_id, MessageId::new(100));
|
||
assert_eq!(reply.sender_name, "Alice");
|
||
assert_eq!(reply.text, "Original");
|
||
}
|
||
|
||
/// Test: Отмена reply mode (Esc) - сообщение отправляется без reply_to
|
||
#[tokio::test]
|
||
async fn test_cancel_reply_sends_without_reply_to() {
|
||
let client = FakeTdClient::new();
|
||
|
||
// Входящее сообщение
|
||
let original = TestMessageBuilder::new("Question?", 100)
|
||
.sender("Alice")
|
||
.build();
|
||
|
||
let client = client.with_message(123, original);
|
||
|
||
// Пользователь начал reply (r), потом отменил (Esc), затем отправил
|
||
// Это эмулируется отправкой без reply_to
|
||
client.send_message(ChatId::new(123), "Regular message".to_string(), None, None).await.unwrap();
|
||
|
||
// Проверяем что отправилось без reply_to
|
||
assert_eq!(client.get_sent_messages()[0].reply_to, None);
|
||
|
||
let messages = client.get_messages(123);
|
||
assert_eq!(messages[1].content.text, "Regular message");
|
||
}
|
||
|
||
/// Test: Forward создаёт сообщение с forward_from
|
||
#[tokio::test]
|
||
async fn test_forward_creates_message_with_forward_from() {
|
||
let client = FakeTdClient::new();
|
||
|
||
// Создаём пересланное сообщение
|
||
let forwarded_msg = TestMessageBuilder::new("Forwarded text", 200)
|
||
.forwarded_from("Bob")
|
||
.build();
|
||
|
||
let client = client.with_message(456, forwarded_msg);
|
||
|
||
// Проверяем что forward_from сохранено
|
||
let messages = client.get_messages(456);
|
||
assert_eq!(messages.len(), 1);
|
||
assert!(messages[0].forward_from().is_some());
|
||
|
||
let forward = messages[0].forward_from().unwrap();
|
||
assert_eq!(forward.sender_name, "Bob");
|
||
}
|
||
|
||
/// Test: Forward показывает "↪ Переслано от ..."
|
||
/// Проверяем что у пересланного сообщения есть forward_from
|
||
#[tokio::test]
|
||
async fn test_forward_displays_sender_name() {
|
||
let client = FakeTdClient::new();
|
||
|
||
let msg = TestMessageBuilder::new("Important info", 300)
|
||
.forwarded_from("Charlie")
|
||
.build();
|
||
|
||
let client = client.with_message(789, msg);
|
||
|
||
let messages = client.get_messages(789);
|
||
let forward = messages[0].forward_from().unwrap();
|
||
|
||
// В UI это будет отображаться как "↪ Переслано от Charlie"
|
||
assert_eq!(forward.sender_name, "Charlie");
|
||
}
|
||
|
||
/// Test: Forward в другой чат
|
||
#[tokio::test]
|
||
async fn test_forward_to_different_chat() {
|
||
let client = FakeTdClient::new();
|
||
|
||
// Исходное сообщение в чате 123
|
||
let original = TestMessageBuilder::new("Share this", 100)
|
||
.sender("Alice")
|
||
.build();
|
||
|
||
let client = client.with_message(123, original);
|
||
|
||
// Пересылаем в чат 456
|
||
let forwarded = TestMessageBuilder::new("Share this", 101)
|
||
.forwarded_from("Alice")
|
||
.build();
|
||
|
||
let client = client.with_message(456, forwarded);
|
||
|
||
// Проверяем что в первом чате 1 сообщение
|
||
assert_eq!(client.get_messages(123).len(), 1);
|
||
|
||
// Проверяем что во втором чате тоже 1 сообщение (пересланное)
|
||
assert_eq!(client.get_messages(456).len(), 1);
|
||
assert!(client.get_messages(456)[0].forward_from().is_some());
|
||
}
|
||
|
||
/// Test: Reply + Forward комбинация (ответ на пересланное сообщение)
|
||
#[tokio::test]
|
||
async fn test_reply_to_forwarded_message() {
|
||
let client = FakeTdClient::new();
|
||
|
||
// Пересланное сообщение
|
||
let forwarded = TestMessageBuilder::new("Forwarded", 100)
|
||
.forwarded_from("Bob")
|
||
.build();
|
||
|
||
let client = client.with_message(123, forwarded);
|
||
|
||
// Создаём reply info
|
||
let reply_info = ReplyInfo {
|
||
message_id: MessageId::new(100),
|
||
sender_name: "Bob".to_string(),
|
||
text: "Forwarded".to_string(),
|
||
};
|
||
|
||
// Отвечаем на пересланное сообщение
|
||
let reply_msg = client.send_message(ChatId::new(123), "Thanks for sharing!".to_string(), Some(MessageId::new(100)), Some(reply_info)).await.unwrap();
|
||
|
||
// Проверяем что reply содержит reply_to
|
||
assert_eq!(client.get_sent_messages()[0].reply_to, Some(MessageId::new(100)));
|
||
|
||
let messages = client.get_messages(123);
|
||
assert_eq!(messages.len(), 2);
|
||
assert_eq!(messages[1].id(), reply_msg.id());
|
||
}
|
||
|
||
/// Test: Forward множества сообщений (batch forward)
|
||
#[tokio::test]
|
||
async fn test_forward_multiple_messages() {
|
||
let client = FakeTdClient::new();
|
||
|
||
// Создаём 3 пересланных сообщения
|
||
let msg1 = TestMessageBuilder::new("Message 1", 100)
|
||
.forwarded_from("Alice")
|
||
.build();
|
||
|
||
let msg2 = TestMessageBuilder::new("Message 2", 101)
|
||
.forwarded_from("Alice")
|
||
.build();
|
||
|
||
let msg3 = TestMessageBuilder::new("Message 3", 102)
|
||
.forwarded_from("Alice")
|
||
.build();
|
||
|
||
let client = client
|
||
.with_message(456, msg1)
|
||
.with_message(456, msg2)
|
||
.with_message(456, msg3);
|
||
|
||
// Проверяем что все 3 сообщения пересланы
|
||
let messages = client.get_messages(456);
|
||
assert_eq!(messages.len(), 3);
|
||
assert!(messages[0].forward_from().is_some());
|
||
assert!(messages[1].forward_from().is_some());
|
||
assert!(messages[2].forward_from().is_some());
|
||
}
|