Files
telegram-tui/tests/profile.rs
Mikhail Kilin 126c7482af
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
fixes
2026-01-29 01:22:57 +03:00

134 lines
4.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Integration tests for profile flow
mod helpers;
use helpers::fake_tdclient::FakeTdClient;
use helpers::test_data::create_test_chat;
use tele_tui::tdlib::ProfileInfo;
/// Test: Открытие профиля в личном чате (i)
#[test]
fn test_open_profile_in_private_chat() {
let client = FakeTdClient::new();
let chat = create_test_chat("Alice", 123);
let _client = client.with_chat(chat);
// Пользователь открыл чат и нажал 'i'
let profile_mode = true;
assert!(profile_mode);
// В реальном App загрузится ProfileInfo для этого чата
}
/// Test: Профиль показывает имя, username, телефон
#[test]
fn test_profile_shows_user_info() {
let profile = ProfileInfo {
chat_id: 123,
title: "Alice Johnson".to_string(),
username: Some("alice".to_string()),
phone_number: Some("+1234567890".to_string()),
bio: None,
chat_type: "Личный чат".to_string(),
member_count: None,
description: None,
invite_link: None,
is_group: false,
online_status: Some("Online".to_string()),
};
assert_eq!(profile.title, "Alice Johnson");
assert_eq!(profile.username.as_ref().unwrap(), "alice");
assert_eq!(profile.phone_number.as_ref().unwrap(), "+1234567890");
assert_eq!(profile.chat_type, "Личный чат");
}
/// Test: Профиль в группе показывает количество участников
#[test]
fn test_profile_shows_group_member_count() {
let profile = ProfileInfo {
chat_id: 456,
title: "Work Team".to_string(),
username: None,
phone_number: None,
bio: Some("Our work group".to_string()),
chat_type: "Группа".to_string(),
member_count: Some(25),
description: None,
invite_link: None,
is_group: true,
online_status: None,
};
assert_eq!(profile.title, "Work Team");
assert_eq!(profile.chat_type, "Группа");
assert_eq!(profile.member_count, Some(25));
assert_eq!(profile.bio.as_ref().unwrap(), "Our work group");
}
/// Test: Профиль в канале
#[test]
fn test_profile_shows_channel_info() {
let profile = ProfileInfo {
chat_id: 789,
title: "News Channel".to_string(),
username: Some("news_channel".to_string()),
phone_number: None,
bio: Some("Latest news updates".to_string()),
chat_type: "Канал".to_string(),
member_count: Some(1000),
description: Some("Latest news updates".to_string()),
invite_link: Some("t.me/news_channel".to_string()),
is_group: false,
online_status: None,
};
assert_eq!(profile.title, "News Channel");
assert_eq!(profile.username.as_ref().unwrap(), "news_channel");
assert_eq!(profile.chat_type, "Канал");
assert_eq!(profile.member_count, Some(1000)); // Subscribers
}
/// Test: Закрытие профиля (Esc)
#[test]
fn test_close_profile_with_esc() {
// Профиль открыт
let profile_mode = true;
// Пользователь нажал Esc
let profile_mode = false;
assert!(!profile_mode);
}
/// Test: Профиль без username и phone
#[test]
fn test_profile_without_optional_fields() {
let profile = ProfileInfo {
chat_id: 999,
title: "Anonymous User".to_string(),
username: None,
phone_number: None,
bio: None,
chat_type: "Личный чат".to_string(),
member_count: None,
description: None,
invite_link: None,
is_group: false,
online_status: None,
};
// Обязательные поля заполнены
assert_eq!(profile.title, "Anonymous User");
assert_eq!(profile.chat_type, "Личный чат");
// Опциональные поля None
assert_eq!(profile.username, None);
assert_eq!(profile.phone_number, None);
assert_eq!(profile.bio, None);
// В UI будут отображаться только доступные поля
}