fixes
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
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
This commit is contained in:
191
tests/account_switcher.rs
Normal file
191
tests/account_switcher.rs
Normal file
@@ -0,0 +1,191 @@
|
||||
// Integration tests for account switcher modal
|
||||
|
||||
mod helpers;
|
||||
|
||||
use helpers::app_builder::TestAppBuilder;
|
||||
use helpers::test_data::create_test_chat;
|
||||
use tele_tui::app::AccountSwitcherState;
|
||||
|
||||
// ============ Open/Close Tests ============
|
||||
|
||||
#[test]
|
||||
fn test_open_account_switcher() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
assert!(app.account_switcher.is_none());
|
||||
|
||||
app.open_account_switcher();
|
||||
|
||||
assert!(app.account_switcher.is_some());
|
||||
match &app.account_switcher {
|
||||
Some(AccountSwitcherState::SelectAccount {
|
||||
accounts,
|
||||
selected_index,
|
||||
current_account,
|
||||
}) => {
|
||||
assert!(!accounts.is_empty());
|
||||
assert_eq!(*selected_index, 0);
|
||||
assert_eq!(current_account, "default");
|
||||
}
|
||||
_ => panic!("Expected SelectAccount state"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_close_account_switcher() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
app.open_account_switcher();
|
||||
assert!(app.account_switcher.is_some());
|
||||
|
||||
app.close_account_switcher();
|
||||
assert!(app.account_switcher.is_none());
|
||||
}
|
||||
|
||||
// ============ Navigation Tests ============
|
||||
|
||||
#[test]
|
||||
fn test_account_switcher_navigate_down() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
app.open_account_switcher();
|
||||
|
||||
// Initially at 0, navigate down to "Add account" item
|
||||
app.account_switcher_select_next();
|
||||
|
||||
match &app.account_switcher {
|
||||
Some(AccountSwitcherState::SelectAccount {
|
||||
selected_index,
|
||||
accounts,
|
||||
..
|
||||
}) => {
|
||||
// Should be at index 1 (the "Add account" item, since default config has 1 account)
|
||||
assert_eq!(*selected_index, accounts.len());
|
||||
}
|
||||
_ => panic!("Expected SelectAccount state"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_switcher_navigate_up() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
app.open_account_switcher();
|
||||
|
||||
// Navigate down first
|
||||
app.account_switcher_select_next();
|
||||
// Navigate back up
|
||||
app.account_switcher_select_prev();
|
||||
|
||||
match &app.account_switcher {
|
||||
Some(AccountSwitcherState::SelectAccount { selected_index, .. }) => {
|
||||
assert_eq!(*selected_index, 0);
|
||||
}
|
||||
_ => panic!("Expected SelectAccount state"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_switcher_navigate_up_at_top() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
app.open_account_switcher();
|
||||
|
||||
// Already at 0, navigate up should stay at 0
|
||||
app.account_switcher_select_prev();
|
||||
|
||||
match &app.account_switcher {
|
||||
Some(AccountSwitcherState::SelectAccount { selected_index, .. }) => {
|
||||
assert_eq!(*selected_index, 0);
|
||||
}
|
||||
_ => panic!("Expected SelectAccount state"),
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Confirm Tests ============
|
||||
|
||||
#[test]
|
||||
fn test_confirm_current_account_closes_modal() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
app.open_account_switcher();
|
||||
|
||||
// Confirm on the current account (default) should just close
|
||||
app.account_switcher_confirm();
|
||||
|
||||
assert!(app.account_switcher.is_none());
|
||||
assert!(app.pending_account_switch.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_confirm_add_account_transitions_to_add_state() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
app.open_account_switcher();
|
||||
|
||||
// Navigate to "+ Add account"
|
||||
app.account_switcher_select_next();
|
||||
|
||||
// Confirm should transition to AddAccount
|
||||
app.account_switcher_confirm();
|
||||
|
||||
match &app.account_switcher {
|
||||
Some(AccountSwitcherState::AddAccount {
|
||||
name_input,
|
||||
cursor_position,
|
||||
error,
|
||||
}) => {
|
||||
assert!(name_input.is_empty());
|
||||
assert_eq!(*cursor_position, 0);
|
||||
assert!(error.is_none());
|
||||
}
|
||||
_ => panic!("Expected AddAccount state"),
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Add Account State Tests ============
|
||||
|
||||
#[test]
|
||||
fn test_start_add_from_select() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
app.open_account_switcher();
|
||||
|
||||
// Use quick shortcut
|
||||
app.account_switcher_start_add();
|
||||
|
||||
match &app.account_switcher {
|
||||
Some(AccountSwitcherState::AddAccount { .. }) => {}
|
||||
_ => panic!("Expected AddAccount state"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_back_from_add_to_select() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
app.open_account_switcher();
|
||||
app.account_switcher_start_add();
|
||||
|
||||
// Go back
|
||||
app.account_switcher_back();
|
||||
|
||||
match &app.account_switcher {
|
||||
Some(AccountSwitcherState::SelectAccount { .. }) => {}
|
||||
_ => panic!("Expected SelectAccount state after back"),
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Footer Tests ============
|
||||
|
||||
#[test]
|
||||
fn test_default_account_name() {
|
||||
let app = TestAppBuilder::new().build();
|
||||
assert_eq!(app.current_account_name, "default");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_custom_account_name() {
|
||||
let mut app = TestAppBuilder::new().build();
|
||||
app.current_account_name = "work".to_string();
|
||||
assert_eq!(app.current_account_name, "work");
|
||||
}
|
||||
|
||||
// ============ Pending Switch Tests ============
|
||||
|
||||
#[test]
|
||||
fn test_pending_switch_initially_none() {
|
||||
let app = TestAppBuilder::new().build();
|
||||
assert!(app.pending_account_switch.is_none());
|
||||
}
|
||||
Reference in New Issue
Block a user