use donion::tui::shell::Shell;

#[test]
fn shell_new_has_correct_defaults() {
    let shell = Shell::new(0, "test-shell".to_string());
    assert_eq!(shell.id(), 0);
    assert_eq!(shell.name(), "test-shell");
    assert_eq!(shell.line_count(), 0);
    assert!(shell.is_auto_scroll());
}

#[test]
fn shell_push_line_adds_to_buffer() {
    let mut shell = Shell::new(0, "test".to_string());
    shell.push_raw_line(b"\x1b[32mhello\x1b[0m");
    assert_eq!(shell.line_count(), 1);
}

#[test]
fn shell_respects_max_lines() {
    let mut shell = Shell::new(0, "test".to_string());
    for i in 0..10_001 {
        shell.push_raw_line(format!("line {i}").as_bytes());
    }
    assert_eq!(shell.line_count(), 10_000);
}

#[test]
fn shell_scroll_disables_auto_scroll() {
    let mut shell = Shell::new(0, "test".to_string());
    for i in 0..100 {
        shell.push_raw_line(format!("line {i}").as_bytes());
    }
    shell.scroll_up(1);
    assert!(!shell.is_auto_scroll());
}

#[test]
fn shell_scroll_to_bottom_re_enables_auto_scroll() {
    let mut shell = Shell::new(0, "test".to_string());
    for i in 0..100 {
        shell.push_raw_line(format!("line {i}").as_bytes());
    }
    shell.scroll_up(5);
    assert!(!shell.is_auto_scroll());
    shell.scroll_to_bottom();
    assert!(shell.is_auto_scroll());
}

#[test]
fn shell_color_is_deterministic() {
    let shell1 = Shell::new(0, "my-project".to_string());
    let shell2 = Shell::new(1, "my-project".to_string());
    assert_eq!(shell1.color(), shell2.color());
}
