use newts::{App, CellType, Cell};
use std::thread;
use std::time::Duration;
use std::fs;
use std::process::Command;
#[test]
fn test_polling_logic() {
let mut app = App::new(None);
let test_file = "polling_test.txt";
let _ = fs::remove_file(test_file);
app.cells.push(Cell {
id: "1".to_string(),
content: format!("echo 'start' > {}", test_file),
output: "".to_string(),
cell_type: CellType::Shell,
polling_interval: None,
last_run: None,
});
let _ = Command::new("sh").arg("-c").arg(&app.cells[0].content).output();
app.cells.push(Cell {
id: "2".to_string(),
content: format!("echo 'line' >> {}", test_file),
output: "".to_string(),
cell_type: CellType::Shell,
polling_interval: Some(1), last_run: None,
});
for _ in 0..5 {
let indices = app.check_polling();
for i in indices {
let cell = &app.cells[i];
let _ = Command::new("sh").arg("-c").arg(&cell.content).output();
}
thread::sleep(Duration::from_millis(1100));
}
let content = fs::read_to_string(test_file).unwrap();
let lines: Vec<&str> = content.lines().collect();
assert!(lines.len() >= 5, "Expected at least 5 lines, got {}", lines.len());
let _ = fs::remove_file(test_file);
}