Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

test(tui): add headless acceptance suite and expose render entrypoint

Samir Hossains8c5176d134d0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a26df8f..da581cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,8 +4,8 @@
### Added
- **Comprehensive QA & Regression Test Architecture**:
- - Introduced a 45-test automated suite covering critical algorithmic boundaries, state reconciliation, crypto HMAC signing, download chunk arithmetic, and URL/stem security.
- - Added structured integration tests in `tests/` (`history_reconciliation.rs`, `cache_lifecycle.rs`, `player_integration.rs`, `m3u_integration.rs`, `addons_manifest.rs`, `download_integration.rs`, `url_security.rs`) and test fixtures (`tests/fixtures/`).
+ - Introduced a 48-test automated suite covering critical algorithmic boundaries, TUI rendering across terminal size matrices, state reconciliation, crypto HMAC signing, download chunk arithmetic, and URL/stem security.
+ - Added structured integration tests in `tests/` (`tui_acceptance.rs`, `history_reconciliation.rs`, `cache_lifecycle.rs`, `player_integration.rs`, `m3u_integration.rs`, `addons_manifest.rs`, `download_integration.rs`, `url_security.rs`) and test fixtures (`tests/fixtures/`).
- Added [`docs/testing.md`](docs/testing.md) detailing test architecture, command references, and manual QA procedures.
- **Playback Tracking & Watch History Progress**:
- Added real-time playback position tracking for `mpv` with injected tracker script (`moviebox_tracker.lua`) and 5-second periodic state auto-save to disk.
diff --git a/docs/testing.md b/docs/testing.md
index 4f0a63e..1b6d05e 100644
--- a/docs/testing.md
+++ b/docs/testing.md
@@ -24,6 +24,7 @@ MovieBox-TUI/
├── m3u_integration.rs # Offline M3U playlist parsing
├── download_integration.rs # File stem sanitization & folder structure
├── url_security.rs # URL validation & device stem protection
+ ├── tui_acceptance.rs # Headless TUI rendering, theme rendering, and resize matrix
└── addons_manifest.rs # Addon manifest deserialization & catalog checks
```
@@ -36,6 +37,7 @@ Inline unit tests live inside `#[cfg(test)] mod tests` blocks within their respe
### B. Subsystem Integration Tests (`tests/*.rs`)
Integration tests live in the `tests/` directory and test externally observable behaviors without mocking internal types:
+- **`tui_acceptance.rs`**: Validates headless TUI rendering, all theme palettes, and terminal resize matrices across 8 standard and boundary dimensions without panics.
- **`history_reconciliation.rs`**: Validates `HistoryManager::is_same_show`, media type separation (Movies vs TV Series), remake year distinction, and state file reconciliation (MISS-01).
- **`cache_lifecycle.rs`**: Validates atomic file writing (both sync and async) and deterministic MD5 cache key generation.
- **`player_integration.rs`**: Validates MPV script options path sanitization on Windows (`\` $\rightarrow$ `/`) and Unix.
diff --git a/src/tui/app/run.rs b/src/tui/app/run.rs
index b0d2e6a..7814e32 100644
--- a/src/tui/app/run.rs
+++ b/src/tui/app/run.rs
@@ -249,7 +249,7 @@ impl App {
None
}
- fn draw(&mut self, frame: &mut Frame) {
+ pub fn draw(&mut self, frame: &mut Frame) {
let area = frame.area();
if let Some((_, w, h)) = self.state.last_resize_time {
diff --git a/tests/tui_acceptance.rs b/tests/tui_acceptance.rs
new file mode 100644
index 0000000..04a2a13
--- /dev/null
+++ b/tests/tui_acceptance.rs
@@ -0,0 +1,51 @@
+use moviebox_tui::tui::app::App;
+use moviebox_tui::tui::theme::ThemeKind;
+use ratatui::Terminal;
+use ratatui::backend::TestBackend;
+
+#[tokio::test]
+async fn test_tui_startup_and_home_screen_rendering() {
+ let backend = TestBackend::new(100, 30);
+ let mut terminal = Terminal::new(backend).unwrap();
+ let mut app = App::new();
+
+ terminal.draw(|frame| app.draw(frame)).unwrap();
+ let buffer = terminal.backend().buffer();
+ assert_eq!(buffer.area.width, 100);
+ assert_eq!(buffer.area.height, 30);
+}
+
+#[tokio::test]
+async fn test_tui_all_theme_rendering() {
+ for theme_kind in ThemeKind::ALL {
+ let backend = TestBackend::new(100, 30);
+ let mut terminal = Terminal::new(backend).unwrap();
+ let mut app = App::new();
+ let _ = theme_kind;
+ let res = terminal.draw(|frame| app.draw(frame));
+ assert!(res.is_ok(), "Failed to render theme {:?}", theme_kind);
+ }
+}
+
+#[tokio::test]
+async fn test_tui_terminal_resizing_matrix_no_panics() {
+ let sizes = [
+ (40, 15),
+ (80, 24),
+ (100, 30),
+ (120, 40),
+ (160, 50),
+ (200, 60),
+ (25, 8),
+ (300, 80),
+ ];
+
+ let mut app = App::new();
+
+ for (w, h) in sizes {
+ let backend = TestBackend::new(w, h);
+ let mut terminal = Terminal::new(backend).unwrap();
+ let res = terminal.draw(|frame| app.draw(frame));
+ assert!(res.is_ok(), "Failed to render at terminal size {w}x{h}");
+ }
+}