commit
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
use ratatui::widgets::ListState;
|
||||
use std::collections::HashMap;
|
||||
use tele_tui::app::{App, AppScreen};
|
||||
use tele_tui::app::{App, AppScreen, ChatState};
|
||||
use tele_tui::config::Config;
|
||||
use tele_tui::tdlib::client::AuthState;
|
||||
use tele_tui::tdlib::{ChatInfo, MessageInfo};
|
||||
@@ -21,17 +21,8 @@ pub struct TestAppBuilder {
|
||||
message_input: String,
|
||||
is_searching: bool,
|
||||
search_query: String,
|
||||
editing_message_id: Option<i64>,
|
||||
replying_to_message_id: Option<i64>,
|
||||
is_reaction_picker_mode: bool,
|
||||
is_profile_mode: bool,
|
||||
confirm_delete_message_id: Option<i64>,
|
||||
chat_state: Option<ChatState>,
|
||||
messages: HashMap<i64, Vec<MessageInfo>>,
|
||||
selected_message_index: Option<usize>,
|
||||
message_search_mode: bool,
|
||||
message_search_query: String,
|
||||
forwarding_message_id: Option<i64>,
|
||||
is_selecting_forward_chat: bool,
|
||||
status_message: Option<String>,
|
||||
auth_state: Option<AuthState>,
|
||||
phone_input: Option<String>,
|
||||
@@ -55,17 +46,8 @@ impl TestAppBuilder {
|
||||
message_input: String::new(),
|
||||
is_searching: false,
|
||||
search_query: String::new(),
|
||||
editing_message_id: None,
|
||||
replying_to_message_id: None,
|
||||
is_reaction_picker_mode: false,
|
||||
is_profile_mode: false,
|
||||
confirm_delete_message_id: None,
|
||||
chat_state: None,
|
||||
messages: HashMap::new(),
|
||||
selected_message_index: None,
|
||||
message_search_mode: false,
|
||||
message_search_query: String::new(),
|
||||
forwarding_message_id: None,
|
||||
is_selecting_forward_chat: false,
|
||||
status_message: None,
|
||||
auth_state: None,
|
||||
phone_input: None,
|
||||
@@ -118,32 +100,43 @@ impl TestAppBuilder {
|
||||
}
|
||||
|
||||
/// Режим редактирования сообщения
|
||||
pub fn editing_message(mut self, message_id: i64) -> Self {
|
||||
self.editing_message_id = Some(message_id);
|
||||
pub fn editing_message(mut self, message_id: i64, selected_index: usize) -> Self {
|
||||
self.chat_state = Some(ChatState::Editing {
|
||||
message_id,
|
||||
selected_index,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Режим ответа на сообщение
|
||||
pub fn replying_to(mut self, message_id: i64) -> Self {
|
||||
self.replying_to_message_id = Some(message_id);
|
||||
self.chat_state = Some(ChatState::Reply { message_id });
|
||||
self
|
||||
}
|
||||
|
||||
/// Режим выбора реакции
|
||||
pub fn reaction_picker(mut self) -> Self {
|
||||
self.is_reaction_picker_mode = true;
|
||||
pub fn reaction_picker(mut self, message_id: i64, available_reactions: Vec<String>) -> Self {
|
||||
self.chat_state = Some(ChatState::ReactionPicker {
|
||||
message_id,
|
||||
available_reactions,
|
||||
selected_index: 0,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Режим профиля
|
||||
pub fn profile_mode(mut self) -> Self {
|
||||
self.is_profile_mode = true;
|
||||
pub fn profile_mode(mut self, info: tele_tui::tdlib::ProfileInfo) -> Self {
|
||||
self.chat_state = Some(ChatState::Profile {
|
||||
info,
|
||||
selected_action: 0,
|
||||
leave_group_confirmation_step: 0,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Подтверждение удаления
|
||||
pub fn delete_confirmation(mut self, message_id: i64) -> Self {
|
||||
self.confirm_delete_message_id = Some(message_id);
|
||||
self.chat_state = Some(ChatState::DeleteConfirmation { message_id });
|
||||
self
|
||||
}
|
||||
|
||||
@@ -166,22 +159,27 @@ impl TestAppBuilder {
|
||||
}
|
||||
|
||||
/// Установить выбранное сообщение (режим selection)
|
||||
pub fn selecting_message(mut self, message_index: usize) -> Self {
|
||||
self.selected_message_index = Some(message_index);
|
||||
pub fn selecting_message(mut self, selected_index: usize) -> Self {
|
||||
self.chat_state = Some(ChatState::MessageSelection { selected_index });
|
||||
self
|
||||
}
|
||||
|
||||
/// Режим поиска по сообщениям в чате
|
||||
pub fn message_search(mut self, query: &str) -> Self {
|
||||
self.message_search_mode = true;
|
||||
self.message_search_query = query.to_string();
|
||||
self.chat_state = Some(ChatState::SearchInChat {
|
||||
query: query.to_string(),
|
||||
results: Vec::new(),
|
||||
selected_index: 0,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Режим пересылки сообщения
|
||||
pub fn forward_mode(mut self, message_id: i64) -> Self {
|
||||
self.forwarding_message_id = Some(message_id);
|
||||
self.is_selecting_forward_chat = true;
|
||||
self.chat_state = Some(ChatState::Forward {
|
||||
message_id,
|
||||
selecting_chat: true,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
@@ -229,16 +227,10 @@ impl TestAppBuilder {
|
||||
app.message_input = self.message_input;
|
||||
app.is_searching = self.is_searching;
|
||||
app.search_query = self.search_query;
|
||||
app.editing_message_id = self.editing_message_id;
|
||||
app.replying_to_message_id = self.replying_to_message_id;
|
||||
app.is_reaction_picker_mode = self.is_reaction_picker_mode;
|
||||
app.is_profile_mode = self.is_profile_mode;
|
||||
app.confirm_delete_message_id = self.confirm_delete_message_id;
|
||||
app.selected_message_index = self.selected_message_index;
|
||||
app.is_message_search_mode = self.message_search_mode;
|
||||
app.message_search_query = self.message_search_query;
|
||||
app.forwarding_message_id = self.forwarding_message_id;
|
||||
app.is_selecting_forward_chat = self.is_selecting_forward_chat;
|
||||
// Применяем chat_state если он установлен
|
||||
if let Some(chat_state) = self.chat_state {
|
||||
app.chat_state = chat_state;
|
||||
}
|
||||
|
||||
// Применяем status_message
|
||||
if let Some(status) = self.status_message {
|
||||
@@ -325,11 +317,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_builder_editing_mode() {
|
||||
let app = TestAppBuilder::new()
|
||||
.editing_message(999)
|
||||
.editing_message(999, 0)
|
||||
.message_input("Edited text")
|
||||
.build();
|
||||
|
||||
assert_eq!(app.editing_message_id, Some(999));
|
||||
assert!(app.is_editing());
|
||||
assert_eq!(app.chat_state.selected_message_id(), Some(999));
|
||||
assert_eq!(app.message_input, "Edited text");
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ fn snapshot_input_editing_mode() {
|
||||
.with_chat(chat)
|
||||
.with_message(123, message)
|
||||
.selected_chat(123)
|
||||
.editing_message(1)
|
||||
.editing_message(1, 0)
|
||||
.message_input("Edited text here")
|
||||
.build();
|
||||
|
||||
|
||||
@@ -34,11 +34,13 @@ fn snapshot_emoji_picker_default() {
|
||||
let chat = create_test_chat("Mom", 123);
|
||||
let message = TestMessageBuilder::new("React to this", 1).build();
|
||||
|
||||
let reactions = vec!["👍".to_string(), "👎".to_string(), "❤️".to_string(), "🔥".to_string(), "😊".to_string(), "😢".to_string(), "😮".to_string(), "🎉".to_string()];
|
||||
|
||||
let app = TestAppBuilder::new()
|
||||
.with_chat(chat)
|
||||
.with_message(123, message)
|
||||
.selected_chat(123)
|
||||
.reaction_picker()
|
||||
.reaction_picker(1, reactions)
|
||||
.build();
|
||||
|
||||
let buffer = render_to_buffer(80, 24, |f| {
|
||||
@@ -54,15 +56,19 @@ fn snapshot_emoji_picker_with_selection() {
|
||||
let chat = create_test_chat("Mom", 123);
|
||||
let message = TestMessageBuilder::new("React to this", 1).build();
|
||||
|
||||
let reactions = vec!["👍".to_string(), "👎".to_string(), "❤️".to_string(), "🔥".to_string(), "😊".to_string(), "😢".to_string(), "😮".to_string(), "🎉".to_string()];
|
||||
|
||||
let mut app = TestAppBuilder::new()
|
||||
.with_chat(chat)
|
||||
.with_message(123, message)
|
||||
.selected_chat(123)
|
||||
.reaction_picker()
|
||||
.reaction_picker(1, reactions)
|
||||
.build();
|
||||
|
||||
// Выбираем 5-ю реакцию (индекс 4)
|
||||
app.selected_reaction_index = 4;
|
||||
if let tele_tui::app::ChatState::ReactionPicker { selected_index, .. } = &mut app.chat_state {
|
||||
*selected_index = 4;
|
||||
}
|
||||
|
||||
let buffer = render_to_buffer(80, 24, |f| {
|
||||
tele_tui::ui::messages::render(f, f.area(), &app);
|
||||
@@ -77,14 +83,12 @@ fn snapshot_profile_personal_chat() {
|
||||
let chat = create_test_chat("Alice", 123);
|
||||
let profile = create_test_profile("Alice", 123);
|
||||
|
||||
let mut app = TestAppBuilder::new()
|
||||
let app = TestAppBuilder::new()
|
||||
.with_chat(chat)
|
||||
.selected_chat(123)
|
||||
.profile_mode()
|
||||
.profile_mode(profile)
|
||||
.build();
|
||||
|
||||
app.profile_info = Some(profile);
|
||||
|
||||
let buffer = render_to_buffer(80, 24, |f| {
|
||||
tele_tui::ui::messages::render(f, f.area(), &app);
|
||||
});
|
||||
@@ -103,14 +107,12 @@ fn snapshot_profile_group_chat() {
|
||||
profile.member_count = Some(25);
|
||||
profile.description = Some("Work discussion group".to_string());
|
||||
|
||||
let mut app = TestAppBuilder::new()
|
||||
let app = TestAppBuilder::new()
|
||||
.with_chat(chat)
|
||||
.selected_chat(456)
|
||||
.profile_mode()
|
||||
.profile_mode(profile)
|
||||
.build();
|
||||
|
||||
app.profile_info = Some(profile);
|
||||
|
||||
let buffer = render_to_buffer(80, 24, |f| {
|
||||
tele_tui::ui::messages::render(f, f.area(), &app);
|
||||
});
|
||||
@@ -157,8 +159,10 @@ fn snapshot_search_in_chat() {
|
||||
.build();
|
||||
|
||||
// Устанавливаем результаты поиска
|
||||
app.message_search_results = vec![msg1, msg2];
|
||||
app.selected_search_result_index = 0;
|
||||
if let tele_tui::app::ChatState::SearchInChat { results, selected_index, .. } = &mut app.chat_state {
|
||||
*results = vec![msg1, msg2];
|
||||
*selected_index = 0;
|
||||
}
|
||||
|
||||
let buffer = render_to_buffer(80, 24, |f| {
|
||||
tele_tui::ui::messages::render(f, f.area(), &app);
|
||||
|
||||
@@ -9,7 +9,7 @@ expression: output
|
||||
│ ──────── 02.01.2022 ──────── │
|
||||
│ │
|
||||
│ Вы ──────────────── │
|
||||
│ Original message text (14:33 ✓✓) │
|
||||
│ ▶ Original message text (14:33 ✓✓) │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
|
||||
@@ -11,9 +11,9 @@ expression: output
|
||||
│User ──────────────── │
|
||||
│ (14:33) React to this │
|
||||
│ │
|
||||
│ │
|
||||
│ ┌ Выбери реакцию ────────────────────────────────┐ │
|
||||
│ │ │ │
|
||||
│ │ 👍 👎 ❤️ 🔥 😊 😢 😮 🎉 │ │
|
||||
│ │ │ │
|
||||
│ └────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
|
||||
@@ -11,9 +11,9 @@ expression: output
|
||||
│User ──────────────── │
|
||||
│ (14:33) React to this │
|
||||
│ │
|
||||
│ │
|
||||
│ ┌ Выбери реакцию ────────────────────────────────┐ │
|
||||
│ │ │ │
|
||||
│ │ 👍 👎 ❤️ 🔥 😊 😢 😮 🎉 │ │
|
||||
│ │ │ │
|
||||
│ └────────────────────────────────────────────────┘ │
|
||||
│ │
|
||||
|
||||
Reference in New Issue
Block a user