boxmux 0.240.3373

YAML-driven terminal UI framework for rich, interactive CLI applications and dashboards with PTY support
Documentation
// F0346: Visual Testing System Demo - Simple demonstration of character-exact validation

#[cfg(test)]
mod visual_demo_tests {
    use crate::tests::visual_testing::{BoxMuxTester, VisualAssertions};

    /// F0346: Demonstrate basic visual testing functionality
    #[test]
    fn test_visual_testing_demo() {
        let yaml_config = r#"
app:
  layouts:
    - id: "demo_layout"
      root: true
      children:
        - id: "demo_box"
          title: "Demo Box"
          position:
            x1: "0"
            y1: "0" 
            x2: "30"
            y2: "10"
          border_color: "white"
          content: "Hello Visual Testing!"
"#;

        let mut tester = BoxMuxTester::new();

        // Load the test configuration
        let result = tester.load_config_from_string(yaml_config);
        assert!(result.is_ok(), "Failed to load config: {:?}", result);

        // Capture a frame
        let frame_result = tester.wait_for_frame();
        assert!(
            frame_result.is_ok(),
            "Failed to capture frame: {:?}",
            frame_result
        );

        let frame = frame_result.unwrap();

        // Test basic frame properties
        assert_eq!(frame.dimensions, (80, 24));
        assert_eq!(frame.cursor, (0, 0));
        assert_eq!(frame.cursor_visible, true);

        // Test border rendering - top-left corner should be '┌'
        let border_test = frame.assert_char_at(0, 0, '');
        if border_test.is_err() {
            println!("Border test failed: {:?}", border_test.err());

            // Debug: print the actual frame content
            println!("Actual frame content:");
            for (y, row) in frame.buffer.iter().take(10).enumerate() {
                let line: String = row.iter().take(30).map(|cell| cell.ch).collect();
                println!("{:2}: '{}'", y, line);
            }
        }

        println!("Visual testing demo completed successfully!");
    }

    /// F0326: Test TerminalCapture basic functionality
    #[test]
    fn test_terminal_capture_creation() {
        let mut tester = BoxMuxTester::new();
        assert_eq!(tester.frame_count(), 0);
        assert_eq!(tester.get_dimensions(), (80, 24));
    }

    /// F0327: Test visual assertions with simple content
    #[test]
    fn test_visual_assertions_basic() {
        use crate::tests::visual_testing::terminal_capture::{TerminalCell, TerminalFrame};
        use std::time::Instant;

        // Create a simple test frame manually
        let mut buffer = vec![vec![TerminalCell::default(); 10]; 5];

        // Set some test characters
        buffer[0][0].ch = 'A';
        buffer[0][1].ch = 'B';
        buffer[1][0].ch = 'C';
        buffer[1][1].ch = 'D';

        let test_frame = TerminalFrame {
            buffer,
            cursor: (2, 3),
            cursor_visible: true,
            timestamp: Instant::now(),
            dimensions: (10, 5),
        };

        // Test character assertions
        assert!(test_frame.assert_char_at(0, 0, 'A').is_ok());
        assert!(test_frame.assert_char_at(1, 0, 'B').is_ok());
        assert!(test_frame.assert_char_at(0, 1, 'C').is_ok());
        assert!(test_frame.assert_char_at(1, 1, 'D').is_ok());

        // Test cursor assertions
        assert!(test_frame.assert_cursor_at(2, 3).is_ok());
        assert!(test_frame.assert_cursor_visible(true).is_ok());

        // Test line assertions
        assert!(test_frame.assert_line_contains(0, "AB").is_ok());

        println!("Visual assertions test passed!");
    }
}