#[cfg(test)]
mod animation_demo_tests {
use crate::tests::visual_testing::{
AnimationConfig, AnimationTesting, BoxMuxTester, DynamicContentSimulator, VisualAssertions,
};
use std::time::Duration;
#[test]
fn test_animation_capture_system() {
let config = AnimationConfig {
frame_interval: Duration::from_millis(50),
total_duration: Duration::from_millis(200),
expected_frames: Some(4),
comparison_tolerance: 0.1,
};
let mut tester = BoxMuxTester::new();
assert!(tester.start_animation_capture(config.clone()).is_ok());
assert!(tester.stop_animation_capture().is_ok());
println!("✅ Animation capture system working");
}
#[test]
fn test_dynamic_content_generation() {
let mut simulator = DynamicContentSimulator::new(Duration::from_millis(10));
let content1 = simulator.generate_content();
assert!(content1.contains("Dynamic content:"));
std::thread::sleep(Duration::from_millis(15));
let content2 = simulator.generate_content();
assert_ne!(content1, content2);
let bar1 = simulator.generate_progress_bar(20);
std::thread::sleep(Duration::from_millis(15));
let bar2 = simulator.generate_progress_bar(20);
assert!(bar1.contains("["));
assert!(bar1.contains("]"));
assert!(bar1.contains("%"));
assert_ne!(bar1, bar2);
println!("✅ Dynamic content generation working");
println!("Content examples:");
println!(" Text: {}", content2);
println!(" Progress: {}", bar2);
}
#[test]
fn test_animation_workflow() {
let yaml_config = r#"
app:
layouts:
- id: "animation_layout"
root: true
children:
- id: "progress_box"
title: "Progress Demo"
position:
x1: "0"
y1: "0"
x2: "40"
y2: "6"
border_color: "white"
content: "Loading: [#### ] 40%"
"#;
let mut tester = BoxMuxTester::new();
assert!(tester.load_config_from_string(yaml_config).is_ok());
let initial_frame = tester.wait_for_frame();
assert!(initial_frame.is_ok());
let animation_config = AnimationConfig {
frame_interval: Duration::from_millis(25),
total_duration: Duration::from_millis(100), expected_frames: Some(4),
comparison_tolerance: 0.2,
};
let animation_result = tester.capture_animation(animation_config);
assert!(animation_result.is_ok());
let animation = animation_result.unwrap();
assert!(!animation.frames.is_empty());
assert!(!animation.timestamps.is_empty());
assert_eq!(animation.frames.len(), animation.timestamps.len());
println!("✅ Animation workflow complete");
println!(
"Captured {} frames over {:?}",
animation.frames.len(),
animation.config.total_duration
);
}
#[test]
fn test_frame_difference_analysis() {
let mut tester = BoxMuxTester::new();
let frame1 = tester.create_test_frame_with_content("Hello World");
let frame2 = tester.create_test_frame_with_content("Hello World");
let frame3 = tester.create_test_frame_with_content("Different Content");
let config = AnimationConfig::default();
let frames = vec![frame1, frame2, frame3];
let capture = crate::tests::visual_testing::AnimationCapture {
frames,
timestamps: vec![],
config,
};
let smoothness_result = tester.assert_animation_smooth(&capture, 0.1);
let identical_capture = crate::tests::visual_testing::AnimationCapture {
frames: vec![
tester.create_test_frame_with_content("Same"),
tester.create_test_frame_with_content("Same"),
],
timestamps: vec![],
config: AnimationConfig::default(),
};
let identical_result = tester.assert_animation_smooth(&identical_capture, 0.1);
assert!(identical_result.is_ok());
println!("✅ Frame difference analysis working");
}
}
impl crate::tests::visual_testing::BoxMuxTester {
fn create_test_frame_with_content(
&mut self,
content: &str,
) -> Vec<Vec<crate::tests::visual_testing::terminal_capture::TerminalCell>> {
let (width, height) = self.get_dimensions();
let mut frame = Vec::new();
for y in 0..height {
let mut row = Vec::new();
for x in 0..width {
let cell = if y == 2 && (x as usize) < content.len() {
let ch = content.chars().nth(x as usize).unwrap_or(' ');
crate::tests::visual_testing::terminal_capture::TerminalCell {
ch,
fg_color: Some(7), bg_color: Some(0), attributes:
crate::tests::visual_testing::terminal_capture::CellAttributes::default(
),
}
} else {
crate::tests::visual_testing::terminal_capture::TerminalCell {
ch: ' ',
fg_color: Some(7), bg_color: Some(0), attributes:
crate::tests::visual_testing::terminal_capture::CellAttributes::default(
),
}
};
row.push(cell);
}
frame.push(row);
}
frame
}
}