tui-file-explorer 3.2.0

Embeddable keyboard-driven multi-pane file explorer for Ratatui
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
//! Tests for the [`super`] ui module and its `overlays`/`panels`/`action_bar`/`modal` siblings.

use super::*;
use crate::Theme;

// ── render_action_bar_spans ───────────────────────────────────────────────

#[test]
fn action_bar_spans_contains_expected_key_labels() {
    let theme = Theme::default();
    let spans = render_action_bar_spans(&theme);
    let text: String = spans.iter().map(|s| s.content.as_ref()).collect();
    assert!(text.contains("Tab"), "missing Tab hint");
    assert!(text.contains('['), "missing [ hint");
    assert!(text.contains('t'), "missing t hint");
    assert!(text.contains('w'), "missing w hint");
    assert!(text.contains("Shift+E"), "missing Shift+E (editor) hint");
    assert!(text.contains("Shift+O"), "missing Shift+O (options) hint");
}

#[test]
fn action_bar_spans_count_is_stable() {
    let theme = Theme::default();
    let spans = render_action_bar_spans(&theme);
    // 6 key spans + 6 description spans = 12 total.
    assert_eq!(
        spans.len(),
        12,
        "span count changed — update this test if the action bar was intentionally modified"
    );
}

#[test]
fn action_bar_spans_key_spans_are_bold() {
    let theme = Theme::default();
    let spans = render_action_bar_spans(&theme);
    let key_labels = ["Tab", "w", "[", "t", "Shift+E", "Shift+O"];
    for label in key_labels {
        let span = spans
            .iter()
            .find(|s| s.content.as_ref() == label)
            .unwrap_or_else(|| panic!("span for key '{label}' not found"));
        assert!(
            span.style.add_modifier.contains(Modifier::BOLD),
            "key span '{label}' should be bold"
        );
    }
}

#[test]
fn action_bar_spans_description_spans_are_not_bold() {
    let theme = Theme::default();
    let spans = render_action_bar_spans(&theme);
    let key_labels = ["Tab", "w", "[", "t", "Shift+E", "Shift+O"];
    for span in &spans {
        if !key_labels.contains(&span.content.as_ref()) {
            assert!(
                !span.style.add_modifier.contains(Modifier::BOLD),
                "description span '{}' should not be bold",
                span.content
            );
        }
    }
}

#[test]
fn action_bar_spans_key_spans_use_accent_colour() {
    let theme = Theme::default();
    let spans = render_action_bar_spans(&theme);
    let key_labels = ["Tab", "w", "[", "t", "Shift+E", "Shift+O"];
    for label in key_labels {
        let span = spans
            .iter()
            .find(|s| s.content.as_ref() == label)
            .unwrap_or_else(|| panic!("span for key '{label}' not found"));
        assert_eq!(
            span.style.fg,
            Some(theme.accent),
            "key span '{label}' should use the accent colour"
        );
    }
}

#[test]
fn action_bar_spans_description_spans_use_dim_colour() {
    let theme = Theme::default();
    let spans = render_action_bar_spans(&theme);
    let key_labels = ["Tab", "w", "[", "t", "Shift+E", "Shift+O"];
    for span in &spans {
        if !key_labels.contains(&span.content.as_ref()) {
            assert_eq!(
                span.style.fg,
                Some(theme.dim),
                "description span '{}' should use the dim colour",
                span.content
            );
        }
    }
}

// ── render_nav_hints_spans ────────────────────────────────────────────────

#[test]
fn nav_hints_spans_contain_arrow_keys() {
    let theme = Theme::default();
    let spans = render_nav_hints_spans(&theme);
    let text: String = spans.iter().map(|s| s.content.as_ref()).collect();
    assert!(text.contains('k'), "missing k (up)");
    assert!(text.contains('j'), "missing j (down)");
    assert!(text.contains('h'), "missing h (ascend)");
    assert!(text.contains('l'), "missing l (confirm)");
    assert!(text.contains("Enter"), "missing Enter");
    assert!(text.contains("Bksp"), "missing Bksp");
}

#[test]
fn nav_hints_spans_contain_search_and_sort() {
    let theme = Theme::default();
    let spans = render_nav_hints_spans(&theme);
    let text: String = spans.iter().map(|s| s.content.as_ref()).collect();
    assert!(text.contains('/'), "missing / (search)");
    assert!(text.contains('s'), "missing s (sort)");
    assert!(text.contains('.'), "missing . (hidden)");
    assert!(text.contains("Esc"), "missing Esc (dismiss)");
}

#[test]
fn nav_hints_key_spans_are_bold() {
    let theme = Theme::default();
    let spans = render_nav_hints_spans(&theme);
    // '/' appears both as a dim separator (between e.g. "↑" and "k") and as
    // the bold search-activation key.  Exclude it from the simple
    // "first match" check and verify it separately below.
    let key_labels = [
        "↑", "k", "↓", "j", "→", "l", "Enter", "←", "h", "Bksp", "s", ".", "Esc",
    ];
    for label in key_labels {
        let span = spans
            .iter()
            .find(|s| s.content.as_ref() == label)
            .unwrap_or_else(|| panic!("nav hint span for '{label}' not found"));
        assert!(
            span.style.add_modifier.contains(Modifier::BOLD),
            "nav key span '{label}' should be bold"
        );
    }
    // '/' is used both as a separator (dim) and as the search key (bold).
    // Assert that at least one '/' span is bold.
    let slash_bold = spans
        .iter()
        .any(|s| s.content.as_ref() == "/" && s.style.add_modifier.contains(Modifier::BOLD));
    assert!(slash_bold, "the search '/' key span should be bold");
}

#[test]
fn nav_hints_key_spans_use_accent_colour() {
    let theme = Theme::default();
    let spans = render_nav_hints_spans(&theme);
    // Exclude '/' — it appears as both a dim separator and a bold accent key.
    let key_labels = ["↑", "k", "↓", "j", "Enter", "Bksp", "s", ".", "Esc"];
    for label in key_labels {
        let span = spans
            .iter()
            .find(|s| s.content.as_ref() == label)
            .unwrap_or_else(|| panic!("nav hint span for '{label}' not found"));
        assert_eq!(
            span.style.fg,
            Some(theme.accent),
            "nav key span '{label}' should use the accent colour"
        );
    }
    // Verify the search '/' key span (bold one) uses the accent colour.
    let slash_accent = spans.iter().any(|s| {
        s.content.as_ref() == "/"
            && s.style.add_modifier.contains(Modifier::BOLD)
            && s.style.fg == Some(theme.accent)
    });
    assert!(
        slash_accent,
        "the search '/' key span should use the accent colour"
    );
}

#[test]
fn nav_hints_description_spans_use_dim_colour() {
    let theme = Theme::default();
    let spans = render_nav_hints_spans(&theme);
    // Bold key labels — spans carrying these as content must be accent-coloured.
    // '/' is excluded because it also appears as a dim separator between combos.
    let key_labels = [
        "↑", "k", "↓", "j", "→", "l", "Enter", "←", "h", "Bksp", "s", ".", "Esc",
    ];
    for span in &spans {
        let content = span.content.as_ref();
        // Skip bold key spans and '/' (mixed role).
        if key_labels.contains(&content) || content == "/" {
            continue;
        }
        assert_eq!(
            span.style.fg,
            Some(theme.dim),
            "nav description span '{}' should use the dim colour",
            span.content
        );
    }
}

#[test]
fn nav_hints_span_count_is_stable() {
    let theme = Theme::default();
    let spans = render_nav_hints_spans(&theme);
    // 14 key spans + 14 separator/description spans = 28 total.
    assert_eq!(
        spans.len(),
        28,
        "nav hint span count changed — update this test if the nav bar was intentionally modified"
    );
}

// ── render_snackbar ───────────────────────────────────────────────────────

/// Build a minimal `Snackbar` without going through `App` helpers so the
/// tests stay pure (no `Instant::now()` drift issues in CI).
fn make_snackbar(message: &str, is_error: bool) -> Snackbar {
    use std::time::{Duration, Instant};
    Snackbar {
        message: message.to_string(),
        expires_at: Instant::now() + Duration::from_secs(10),
        is_error,
    }
}

#[test]
fn snackbar_geometry_height_is_three() {
    // render_snackbar always uses height = 3 (top border + content + bottom border).
    // We verify the computed Rect indirectly by checking that a short message
    // still produces a snackbar_area with height == 3.
    // Since render_snackbar is not pure (it takes a Frame), we test the
    // height constant through the public geometry formula used in the function.
    let height: u16 = 3;
    assert_eq!(height, 3);
}

#[test]
fn snackbar_info_uses_success_colour() {
    let theme = Theme::default();
    let sb = make_snackbar("info message", false);
    // For an info snackbar the border / text colour must be theme.success.
    let expected = theme.success;
    let actual = if sb.is_error {
        theme.brand
    } else {
        theme.success
    };
    assert_eq!(actual, expected, "info snackbar should use success colour");
}

#[test]
fn snackbar_error_uses_brand_colour() {
    let theme = Theme::default();
    let sb = make_snackbar("error message", true);
    let expected = theme.brand;
    let actual = if sb.is_error {
        theme.brand
    } else {
        theme.success
    };
    assert_eq!(actual, expected, "error snackbar should use brand colour");
}

#[test]
fn snackbar_info_and_error_colours_are_distinct() {
    let theme = Theme::default();
    // Sanity check: the two colour paths must differ so the tests above
    // are actually meaningful.
    assert_ne!(
        theme.success, theme.brand,
        "success and brand colours must differ for snackbar colour tests to be meaningful"
    );
}

#[test]
fn snackbar_message_is_preserved() {
    let msg = "No editor set — open Options (Shift + O) and press e to pick one";
    let sb = make_snackbar(msg, true);
    assert_eq!(sb.message, msg);
}

#[test]
fn snackbar_width_at_least_minimum() {
    // The width formula: desired = msg.len() + 4, clamped to area_width - 4,
    // then max(20).  For any message the result must be >= 20.
    let msg = "hi"; // very short message
    let area_width: u16 = 200;
    let desired = (msg.len() as u16)
        .saturating_add(4)
        .min(area_width.saturating_sub(4));
    let width = desired.max(20);
    assert!(width >= 20, "snackbar width must be at least 20 columns");
}

#[test]
fn snackbar_width_capped_to_area() {
    // A very long message should not exceed area_width - 4.
    let msg = "a".repeat(300);
    let area_width: u16 = 120;
    let desired = (msg.len() as u16)
        .saturating_add(4)
        .min(area_width.saturating_sub(4));
    let width = desired.max(20);
    assert!(
        width <= area_width,
        "snackbar must not exceed the terminal width"
    );
}

#[test]
fn snackbar_is_not_expired_when_fresh() {
    let sb = make_snackbar("fresh", false);
    assert!(
        !sb.is_expired(),
        "a newly created snackbar must not be expired"
    );
}

#[test]
fn snackbar_is_expired_after_deadline() {
    use std::time::{Duration, Instant};
    let sb = Snackbar {
        message: "old".into(),
        expires_at: Instant::now() - Duration::from_millis(1),
        is_error: false,
    };
    assert!(
        sb.is_expired(),
        "snackbar past its deadline must be expired"
    );
}

// ── Debug log panel ───────────────────────────────────────────────────────

fn make_app_in(dir: std::path::PathBuf) -> App {
    App::new(crate::app::AppOptions {
        pane_dirs: vec![dir.clone(), dir],
        ..crate::app::AppOptions::default()
    })
}

fn make_verbose_app_in(dir: std::path::PathBuf) -> App {
    App::new(crate::app::AppOptions {
        pane_dirs: vec![dir.clone(), dir],
        verbose: true,
        ..crate::app::AppOptions::default()
    })
}

#[test]
fn default_app_verbose_is_false() {
    let app = make_app_in(std::env::temp_dir());
    assert!(!app.verbose);
}

#[test]
fn default_app_debug_log_is_empty() {
    let app = make_app_in(std::env::temp_dir());
    assert!(app.debug_log.is_empty());
}

#[test]
fn verbose_app_has_verbose_true() {
    let app = make_verbose_app_in(std::env::temp_dir());
    assert!(app.verbose);
}

#[test]
fn verbose_app_log_accumulates() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    app.log("first");
    app.log("second");
    assert_eq!(app.debug_log.len(), 2);
    assert_eq!(app.debug_log[0], "first");
    assert_eq!(app.debug_log[1], "second");
}

#[test]
fn non_verbose_app_log_is_noop() {
    let mut app = make_app_in(std::env::temp_dir());
    app.log("ignored");
    assert!(app.debug_log.is_empty());
}

#[test]
fn startup_log_transferred_into_debug_log() {
    let app = App::new(crate::app::AppOptions {
        pane_dirs: vec![std::env::temp_dir(), std::env::temp_dir()],
        verbose: true,
        startup_log: vec!["boot 1".into(), "boot 2".into()],
        ..crate::app::AppOptions::default()
    });
    assert_eq!(app.debug_log.len(), 2);
    assert_eq!(app.debug_log[0], "boot 1");
    assert_eq!(app.debug_log[1], "boot 2");
}

#[test]
fn startup_log_followed_by_runtime_log_preserves_order() {
    let mut app = App::new(crate::app::AppOptions {
        pane_dirs: vec![std::env::temp_dir(), std::env::temp_dir()],
        verbose: true,
        startup_log: vec!["startup".into()],
        ..crate::app::AppOptions::default()
    });
    app.log("runtime");
    assert_eq!(app.debug_log, vec!["startup", "runtime"]);
}

#[test]
fn draw_without_verbose_does_not_panic() {
    let mut app = make_app_in(std::env::temp_dir());
    let backend = ratatui::backend::TestBackend::new(80, 24);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal.draw(|frame| draw(&mut app, frame)).unwrap();
    // No debug panel should have been rendered — just verify no panic.
}

#[test]
fn draw_with_verbose_does_not_panic() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    app.log("test log line");
    let backend = ratatui::backend::TestBackend::new(80, 30);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal.draw(|frame| draw(&mut app, frame)).unwrap();
    // Debug panel should have been rendered — just verify no panic.
}

#[test]
fn draw_with_verbose_empty_log_does_not_panic() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    let backend = ratatui::backend::TestBackend::new(80, 30);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal.draw(|frame| draw(&mut app, frame)).unwrap();
}

#[test]
fn draw_with_verbose_many_log_lines_does_not_panic() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    for i in 0..100 {
        app.log(format!("line {i}"));
    }
    let backend = ratatui::backend::TestBackend::new(80, 30);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal.draw(|frame| draw(&mut app, frame)).unwrap();
}

#[test]
fn draw_with_verbose_small_terminal_does_not_panic() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    app.log("log line");
    // Very small terminal — layout must not crash.
    let backend = ratatui::backend::TestBackend::new(40, 10);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal.draw(|frame| draw(&mut app, frame)).unwrap();
}

#[test]
fn draw_with_verbose_tall_terminal_does_not_panic() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    app.log("tall terminal log");
    // height >= 30 → full debug panel (Length(10))
    let backend = ratatui::backend::TestBackend::new(80, 40);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal.draw(|frame| draw(&mut app, frame)).unwrap();
}

#[test]
fn draw_with_verbose_medium_terminal_does_not_panic() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    app.log("medium terminal log");
    // 20 <= height < 30 → compact debug panel (Length(6))
    let backend = ratatui::backend::TestBackend::new(80, 25);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal.draw(|frame| draw(&mut app, frame)).unwrap();
}

#[test]
fn draw_with_verbose_tiny_terminal_does_not_panic() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    app.log("tiny terminal log");
    // height < 20 → minimal debug panel (Length(3))
    let backend = ratatui::backend::TestBackend::new(80, 15);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal.draw(|frame| draw(&mut app, frame)).unwrap();
}

/// Read all cell symbols from a test backend buffer into a single string.
fn buffer_text(terminal: &ratatui::Terminal<ratatui::backend::TestBackend>) -> String {
    let buf = terminal.backend().buffer().clone();
    let mut text = String::new();
    for y in 0..buf.area.height {
        for x in 0..buf.area.width {
            text.push_str(buf[(x, y)].symbol());
        }
    }
    text
}

#[test]
fn render_debug_panel_contains_log_line() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    app.log("hello from debug");
    let theme = Theme::default();
    let backend = ratatui::backend::TestBackend::new(80, 12);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal
        .draw(|frame| {
            let area = frame.area();
            render_debug_panel(frame, area, &app, &theme);
        })
        .unwrap();
    let text = buffer_text(&terminal);
    assert!(
        text.contains("hello from debug"),
        "debug panel should contain the log message"
    );
}

#[test]
fn render_debug_panel_shows_line_count() {
    let mut app = make_verbose_app_in(std::env::temp_dir());
    app.log("a");
    app.log("b");
    app.log("c");
    let theme = Theme::default();
    let backend = ratatui::backend::TestBackend::new(80, 12);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal
        .draw(|frame| {
            let area = frame.area();
            render_debug_panel(frame, area, &app, &theme);
        })
        .unwrap();
    let text = buffer_text(&terminal);
    assert!(
        text.contains("3 lines"),
        "debug panel title should show the line count"
    );
}

#[test]
fn draw_in_does_not_touch_cells_outside_area() {
    let mut app = make_app_in(std::env::temp_dir());
    let backend = ratatui::backend::TestBackend::new(80, 24);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    let area = Rect::new(10, 4, 50, 16);
    terminal
        .draw(|frame| {
            let background = Paragraph::new(vec![Line::from("x".repeat(80)); 24]);
            frame.render_widget(background, frame.area());
            draw_in(&mut app, frame, area);
        })
        .unwrap();
    let buffer = terminal.backend().buffer();
    assert_eq!(buffer[(0, 0)].symbol(), "x");
    assert_eq!(buffer[(79, 23)].symbol(), "x");
    assert_ne!(buffer[(area.x, area.y)].symbol(), "x");
}

#[test]
fn draw_in_handles_tiny_areas_with_overlays() {
    let mut app = make_app_in(std::env::temp_dir());
    app.modal = Some(crate::Modal::Delete {
        path: std::path::PathBuf::from("tiny.txt"),
    });
    app.snackbar = Some(crate::Snackbar::info("tiny"));
    app.copy_progress = Some(crate::CopyProgress::new("tiny", 1));
    let backend = ratatui::backend::TestBackend::new(8, 4);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal
        .draw(|frame| draw_in(&mut app, frame, Rect::new(2, 1, 3, 2)))
        .unwrap();
}

#[test]
fn draw_in_options_can_hide_action_bar() {
    let mut app = make_app_in(std::env::temp_dir());
    let backend = ratatui::backend::TestBackend::new(80, 24);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal
        .draw(|frame| {
            draw_in_with_options(
                &mut app,
                frame,
                frame.area(),
                AppViewOptions {
                    show_action_bar: false,
                    ..AppViewOptions::default()
                },
            );
        })
        .unwrap();
    let text = buffer_text(&terminal);
    assert!(!text.contains("Navigate"));
}

#[test]
fn hint_layout_auto_adapts_to_width() {
    assert_eq!(HintLayout::Auto.resolve(89), HintLayout::Vertical);
    assert_eq!(HintLayout::Auto.resolve(90), HintLayout::Horizontal);
    assert_eq!(HintLayout::Horizontal.action_bar_rows(20), 6);
    assert_eq!(HintLayout::Vertical.action_bar_rows(200), 12);
}

#[test]
fn vertical_hint_layout_stacks_each_pair() {
    let app = make_app_in(std::env::temp_dir());
    let theme = Theme::default();
    let backend = ratatui::backend::TestBackend::new(50, 12);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal
        .draw(|frame| {
            render_nav_hints_with_layout(
                frame,
                Rect::new(0, 0, 50, 6),
                Rect::new(0, 6, 50, 6),
                &app,
                &theme,
                HintLayout::Vertical,
            );
        })
        .unwrap();
    let buffer = terminal.backend().buffer();
    let row = |y| (0..50).map(|x| buffer[(x, y)].symbol()).collect::<String>();
    assert!(row(0).contains("Navigate"));
    assert!(row(3).contains("File Ops"));
    assert!(row(6).contains("Global"));
    assert!(row(10).contains("No pending operations"));
}

// ── Delete modal wording ──────────────────────────────────────────────────

fn modal_text(modal: &crate::Modal, to_trash: bool) -> String {
    let backend = ratatui::backend::TestBackend::new(80, 24);
    let mut terminal = ratatui::Terminal::new(backend).unwrap();
    terminal
        .draw(|frame| render_modal_for(frame, frame.area(), modal, &Theme::default(), to_trash))
        .unwrap();
    terminal
        .backend()
        .buffer()
        .content()
        .iter()
        .map(|c| c.symbol())
        .collect()
}

#[test]
fn delete_modal_says_delete_by_default() {
    let modal = crate::Modal::Delete {
        path: std::path::PathBuf::from("notes.txt"),
    };
    let text = modal_text(&modal, false);
    assert!(text.contains("Delete 'notes.txt'"));
    assert!(!text.contains("trash"));
}

#[test]
fn delete_modal_says_trash_when_trashing() {
    let modal = crate::Modal::Delete {
        path: std::path::PathBuf::from("notes.txt"),
    };
    assert!(modal_text(&modal, true).contains("Move 'notes.txt' to trash?"));
}

#[test]
fn multi_delete_modal_says_trash_when_trashing() {
    let modal = crate::Modal::MultiDelete {
        paths: vec!["a".into(), "b".into()],
    };
    assert!(modal_text(&modal, true).contains("Move 2 item(s) to trash?"));
    assert!(modal_text(&modal, false).contains("Delete 2 item(s)?"));
}

#[test]
fn app_without_trash_support_never_enables_it() {
    let app = App::new(crate::AppOptions {
        use_trash: true,
        ..crate::AppOptions::default()
    });
    assert_eq!(app.use_trash, crate::TRASH_SUPPORTED);
}

// ── side panels (render smoke tests) ──────────────────────────────────────

fn render_panel(f: impl Fn(&mut ratatui::Frame, ratatui::layout::Rect, &crate::App)) -> String {
    use ratatui::{backend::TestBackend, Terminal};
    let app = crate::App::new(crate::AppOptions::default());
    let mut term = Terminal::new(TestBackend::new(60, 40)).unwrap();
    term.draw(|frame| f(frame, frame.area(), &app)).unwrap();
    term.backend()
        .buffer()
        .content()
        .iter()
        .map(|c| c.symbol())
        .collect()
}

#[test]
fn theme_panel_renders_without_panic() {
    assert!(!render_panel(render_theme_panel).trim().is_empty());
}

#[test]
fn editor_panel_renders_without_panic() {
    assert!(!render_panel(render_editor_panel).trim().is_empty());
}

#[test]
fn options_panel_renders_without_panic() {
    assert!(!render_panel(render_options_panel).trim().is_empty());
}

#[test]
fn panels_survive_tiny_areas() {
    use ratatui::{backend::TestBackend, layout::Rect, Terminal};
    let app = crate::App::new(crate::AppOptions::default());
    let mut term = Terminal::new(TestBackend::new(10, 3)).unwrap();
    term.draw(|f| {
        let a = Rect::new(0, 0, 10, 3);
        render_theme_panel(f, a, &app);
        render_editor_panel(f, a, &app);
        render_options_panel(f, a, &app);
    })
    .unwrap();
}