use std::fs;
use std::path::Path;
use fido::debug_log;
#[test]
fn test_debug_log_creation() {
let log_file = "test_fido_modal_debug.log";
let _ = fs::remove_file(log_file);
let result = fs::File::create(log_file);
assert!(result.is_ok(), "Should be able to create log file");
assert!(Path::new(log_file).exists(), "Log file should exist");
let _ = fs::remove_file(log_file);
}
#[test]
fn test_log_file_constant() {
assert_eq!(debug_log::DEBUG_LOG_FILE, "fido_modal_debug.log");
}
#[test]
fn test_clear_debug_log() {
debug_log::clear_debug_log();
assert!(Path::new(debug_log::DEBUG_LOG_FILE).exists(), "Log file should exist after clear");
let metadata = fs::metadata(debug_log::DEBUG_LOG_FILE).expect("Should be able to read metadata");
assert_eq!(metadata.len(), 0, "Log file should be empty after clear");
}
#[test]
fn test_log_modal_state() {
debug_log::clear_debug_log();
debug_log::log_modal_state(true, true, false, "Reply");
let contents = fs::read_to_string(debug_log::DEBUG_LOG_FILE)
.expect("Should be able to read log file");
assert!(contents.contains("MODAL_STATE"), "Log should contain MODAL_STATE");
assert!(contents.contains("viewing_post_detail=true"), "Log should contain viewing_post_detail=true");
assert!(contents.contains("show_full_post_modal=true"), "Log should contain show_full_post_modal=true");
assert!(contents.contains("composer_open=false"), "Log should contain composer_open=false");
assert!(contents.contains("composer_mode=Reply"), "Log should contain composer_mode=Reply");
}
#[test]
fn test_log_key_event() {
debug_log::clear_debug_log();
debug_log::log_key_event("Enter", "composer_open");
let contents = fs::read_to_string(debug_log::DEBUG_LOG_FILE)
.expect("Should be able to read log file");
assert!(contents.contains("KEY_EVENT"), "Log should contain KEY_EVENT");
assert!(contents.contains("key=Enter"), "Log should contain key=Enter");
assert!(contents.contains("context=composer_open"), "Log should contain context=composer_open");
}
#[test]
fn test_log_debug() {
debug_log::clear_debug_log();
debug_log::log_debug("Test debug message");
let contents = fs::read_to_string(debug_log::DEBUG_LOG_FILE)
.expect("Should be able to read log file");
assert!(contents.contains("Test debug message"), "Log should contain the debug message");
}