WIP Telegram: modulo akode-telegram (API e impostazioni), in pausa
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
89
akode-rs/tui/src/telegram_panel_tests.rs
Normal file
89
akode-rs/tui/src/telegram_panel_tests.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
fn status() -> TelegramStatus {
|
||||
TelegramStatus {
|
||||
settings: TelegramSettings {
|
||||
enabled: true,
|
||||
allowed_chat_ids: vec![123_456_789],
|
||||
..TelegramSettings::default()
|
||||
},
|
||||
has_token: true,
|
||||
bot_name: Some("akode_bot".to_string()),
|
||||
connected: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn panel(status: TelegramStatus) -> TelegramPanel {
|
||||
let home = std::env::temp_dir().join("akode-telegram-panel-tests-unused");
|
||||
TelegramPanel::new(FrameRequester::test_dummy(), home, status)
|
||||
}
|
||||
|
||||
fn render(panel: &TelegramPanel, width: u16, height: u16) -> String {
|
||||
let area = Rect::new(0, 0, width, height);
|
||||
let mut buf = Buffer::empty(area);
|
||||
panel.render_ref(area, &mut buf);
|
||||
(0..height)
|
||||
.map(|y| {
|
||||
(0..width)
|
||||
.map(|x| buf[(x, y)].symbol().to_string())
|
||||
.collect::<String>()
|
||||
.trim_end()
|
||||
.to_string()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
fn key(code: KeyCode) -> KeyEvent {
|
||||
KeyEvent::new(code, KeyModifiers::NONE)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn telegram_panel_status_snapshots() {
|
||||
let panel = panel(status());
|
||||
for width in [80, 120] {
|
||||
insta::assert_snapshot!(format!("telegram_panel_status_{width}"), render(&panel, width, 16));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn telegram_panel_unconfigured_snapshots() {
|
||||
let panel = panel(TelegramStatus::default());
|
||||
for width in [80, 120] {
|
||||
insta::assert_snapshot!(
|
||||
format!("telegram_panel_unconfigured_{width}"),
|
||||
render(&panel, width, 16)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn telegram_panel_token_is_masked() {
|
||||
let mut panel = panel(TelegramStatus::default());
|
||||
panel.handle_key_event(key(KeyCode::Enter));
|
||||
panel.handle_paste("123456:SEGRETO-del-bot".to_string());
|
||||
for width in [80, 120] {
|
||||
let text = render(&panel, width, 16);
|
||||
assert!(!text.contains("SEGRETO"), "{text}");
|
||||
insta::assert_snapshot!(format!("telegram_panel_token_{width}"), text);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn telegram_panel_pairing_snapshots() {
|
||||
let mut panel = panel(status());
|
||||
panel.mode = Mode::Pairing("482913".to_string());
|
||||
for width in [80, 120] {
|
||||
insta::assert_snapshot!(
|
||||
format!("telegram_panel_pairing_{width}"),
|
||||
render(&panel, width, 16)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn menu_offers_remove_only_with_a_token() {
|
||||
assert_eq!(panel(TelegramStatus::default()).actions().len(), 3);
|
||||
assert_eq!(panel(status()).actions().len(), 4);
|
||||
}
|
||||
Reference in New Issue
Block a user