Handle absent media and selection state safely
This commit is contained in:
@@ -2,8 +2,12 @@
|
||||
|
||||
mod helpers;
|
||||
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use helpers::app_builder::TestAppBuilder;
|
||||
use helpers::fake_tdclient::FakeTdClient;
|
||||
use helpers::test_data::TestMessageBuilder;
|
||||
use tele_tui::config::Command;
|
||||
use tele_tui::input::handlers::chat::handle_message_selection;
|
||||
use tele_tui::types::ChatId;
|
||||
|
||||
/// Test: Добавление реакции к сообщению
|
||||
@@ -32,6 +36,25 @@ async fn test_add_reaction_to_message() {
|
||||
assert!(messages[0].reactions()[0].is_chosen);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_react_without_selected_chat_does_not_panic() {
|
||||
let msg = TestMessageBuilder::new("React safely", 100).build();
|
||||
let mut app = TestAppBuilder::new()
|
||||
.with_message(123, msg)
|
||||
.selecting_message(0)
|
||||
.build();
|
||||
*app.td_client.current_chat_id.lock().unwrap() = Some(123);
|
||||
|
||||
handle_message_selection(
|
||||
&mut app,
|
||||
KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE),
|
||||
Some(Command::ReactMessage),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(app.error_message.as_deref(), Some("Чат не выбран"));
|
||||
}
|
||||
|
||||
/// Test: Удаление реакции (toggle) - вторичное нажатие
|
||||
#[tokio::test]
|
||||
async fn test_toggle_reaction_removes_it() {
|
||||
|
||||
Reference in New Issue
Block a user