tix-tracker 0.11.0

A terminal issue tracker: markdown + YAML frontmatter issues with a kanban TUI and CLI
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
#[allow(clippy::wildcard_imports)]
use super::super::*;
#[allow(clippy::wildcard_imports)]
use super::helpers::*;
use std::fs;

#[test]
fn enter_opens_the_action_menu_then_detail() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(
        matches!(app.mode, Mode::ActionMenu { .. }),
        "Enter opens the action menu, got {:?}",
        app.mode
    );
    assert!(select_menu_action(&mut app, &IssueAction::OpenDetail));
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(matches!(app.mode, Mode::Detail));
    assert!(app.detail.is_some());
}

/// The action menu's `Move to <column>` is a third door into
/// `move_selected_to`, and it was the only one with no test at all.
#[test]
fn a_action_menu_move_of_a_blocked_card_asks_before_it_writes() {
    let (_tmp, mut app) = make_blocked_mouse_app();
    let (sx, sy) = card_cell(&app, 0, 1); // #2 Beta, blocked by #1
    let target = app.board.column_name(done_col(&app)).to_string();

    app.handle_mouse(down_right(sx, sy)).unwrap();
    assert!(
        matches!(app.mode, Mode::ActionMenu { .. }),
        "right-click opens the menu, got {:?}",
        app.mode
    );
    assert!(select_menu_action(
        &mut app,
        &IssueAction::MoveTo { column: target }
    ));
    app.handle_key(press(KeyCode::Enter)).unwrap();

    assert!(
        matches!(app.mode, Mode::ConfirmBlockedMove { .. }),
        "a menu move into done must raise the acknowledgement prompt, got {:?}",
        app.mode
    );
    app.handle_key(press(KeyCode::Esc)).unwrap();
    assert!(
        app.board.column_cards(0).iter().any(|c| c.number == 2),
        "a cancelled menu move must not move the card"
    );
}

#[test]
fn mouse_single_click_opens_the_action_menu() {
    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 0);
    app.handle_mouse(down_left(x, y)).unwrap();
    app.handle_mouse(up_left(x, y)).unwrap();
    assert!(
        matches!(app.mode, Mode::ActionMenu { .. }),
        "a plain single click opens the action menu, got {:?}",
        app.mode
    );
    assert!(app.detail.is_none());
}

#[test]
fn mouse_scroll_scrolls_detail_and_context_menu() {
    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 0);

    app.handle_mouse(down_left(x, y)).unwrap();
    app.handle_mouse(up_left(x, y)).unwrap();
    app.handle_mouse(down_left(x, y)).unwrap();
    assert!(matches!(app.mode, Mode::Detail));
    // The pane's geometry is normally recorded by its own draw; a test that drives
    // the handler supplies it, which is also what makes the clamping visible.
    if let Some(d) = app.detail.as_mut() {
        d.viewport.set(20);
        d.max_scroll.set(8);
    }
    let action = app.handle_mouse(scroll_down(x, y)).unwrap();
    assert_eq!(action, Action::None);
    assert_eq!(app.detail.as_ref().unwrap().scroll_offset, 5);
    // One more notch would be 10, past the last page: it stops at 8 rather than
    // scrolling the pane into emptiness (tix #1442).
    app.handle_mouse(scroll_down(x, y)).unwrap();
    assert_eq!(app.detail.as_ref().unwrap().scroll_offset, 8);
    let action = app.handle_mouse(scroll_up(x, y)).unwrap();
    assert_eq!(action, Action::None);
    assert_eq!(app.detail.as_ref().unwrap().scroll_offset, 3);
    for _ in 0..5 {
        app.handle_mouse(scroll_up(x, y)).unwrap();
    }
    assert_eq!(app.detail.as_ref().unwrap().scroll_offset, 0);

    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 0);
    app.handle_mouse(down_right(x, y)).unwrap();
    assert!(matches!(app.mode, Mode::ActionMenu { .. }));
    let before = app.action_menu.as_ref().unwrap().selected_position();
    let action = app.handle_mouse(scroll_down(x, y)).unwrap();
    assert_eq!(action, Action::None);
    assert_eq!(
        app.action_menu.as_ref().unwrap().selected_position(),
        before + 1
    );
    let action = app.handle_mouse(scroll_up(x, y)).unwrap();
    assert_eq!(action, Action::None);
    assert_eq!(
        app.action_menu.as_ref().unwrap().selected_position(),
        before
    );
}

#[test]
fn comment_round_trip_via_detail() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    open_detail(&mut app);

    let _ = app.handle_key(press(KeyCode::Char('c'))).unwrap();
    assert!(matches!(app.mode, Mode::Comment { .. }));
    for c in "hello world".chars() {
        let _ = app.handle_key(press(KeyCode::Char(c))).unwrap();
    }
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(matches!(app.mode, Mode::Detail));

    let issue = app
        .store
        .get(IssueSelector::Filename("2026-01-01-a.md".into()))
        .unwrap();
    let comments = issue.comments();
    assert_eq!(comments.len(), 1);
    assert_eq!(comments[0].text.trim(), "hello world");
}

#[test]
fn comment_esc_cancels() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    open_detail(&mut app);
    let _ = app.handle_key(press(KeyCode::Char('c'))).unwrap();
    for c in "partial".chars() {
        let _ = app.handle_key(press(KeyCode::Char(c))).unwrap();
    }
    let _ = app.handle_key(press(KeyCode::Esc)).unwrap();
    assert!(matches!(app.mode, Mode::Detail));
    let issue = app
        .store
        .get(IssueSelector::Filename("2026-01-01-a.md".into()))
        .unwrap();
    assert_eq!(issue.comments(), [] as [crate::model::Comment; 0]);
}

#[test]
fn comment_empty_discarded() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    open_detail(&mut app);
    let _ = app.handle_key(press(KeyCode::Char('c'))).unwrap();
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(matches!(app.mode, Mode::Detail));
    let issue = app
        .store
        .get(IssueSelector::Filename("2026-01-01-a.md".into()))
        .unwrap();
    assert_eq!(issue.comments(), [] as [crate::model::Comment; 0]);
    assert!(
        app.status_msg
            .as_deref()
            .is_some_and(|m| m.contains("empty"))
    );
}

#[test]
fn asset_round_trip_via_detail() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    open_detail(&mut app);

    let asset = tmp.path().join("pic.png");
    fs::write(&asset, b"fake-png").unwrap();

    let _ = app.handle_key(press(KeyCode::Char('a'))).unwrap();
    assert!(matches!(app.mode, Mode::Asset { .. }));
    for c in asset.to_string_lossy().chars() {
        let _ = app.handle_key(press(KeyCode::Char(c))).unwrap();
    }
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(matches!(app.mode, Mode::Detail));

    assert!(
        dir.join("a-assets").join("pic.png").is_file(),
        "asset must be copied into the issue asset dir"
    );
    let issue = app
        .store
        .get(IssueSelector::Filename("2026-01-01-a.md".into()))
        .unwrap();
    assert!(
        issue.body.contains("pic.png"),
        "body must reference the asset, got {:?}",
        issue.body
    );
}

#[test]
fn asset_error_stays_in_mode() {
    let (tmp, mut app) = make_app();
    let dir = tmp.path().join("issues");
    write_issue(&dir, "2026-01-01-a.md", 1, "A", "todo", None);
    let config = app.store.config.clone();
    app.board = BoardState::build(&app.store, config.default_config());
    open_detail(&mut app);
    let _ = app.handle_key(press(KeyCode::Char('a'))).unwrap();
    for c in "/no/such/file.png".chars() {
        let _ = app.handle_key(press(KeyCode::Char(c))).unwrap();
    }
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(
        matches!(app.mode, Mode::Asset { .. }),
        "asset error must stay in entry mode, got {:?}",
        app.mode
    );
    assert!(app.status_msg.is_some());
}

#[test]
fn right_click_card_opens_menu_with_all_actions() {
    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 1);
    app.handle_mouse(down_right(x, y)).unwrap();

    assert_eq!((app.board.active_col, app.board.selected), (0, 1));
    let Some(menu) = app.action_menu.as_ref() else {
        panic!("menu not open");
    };
    assert!(
        matches!(
            menu.selected_item().map(|item| &item.action),
            Some(IssueAction::OpenDetail)
        ),
        "Open detail is preselected even though Move is drawn first"
    );
    let actions = menu_actions(&app);
    let current = app.board.column_name(app.board.active_col).to_string();
    let expected_moves: Vec<String> = app
        .active_board_config()
        .columns
        .iter()
        .filter(|column| **column != current)
        .cloned()
        .collect();
    let moves: Vec<String> = actions
        .iter()
        .filter_map(|action| match action {
            IssueAction::MoveTo { column } => Some(column.clone()),
            _ => None,
        })
        .collect();
    assert_eq!(
        moves, expected_moves,
        "every configured column except the current one is a move target"
    );
    assert!(actions.contains(&IssueAction::Delete));
    assert!(actions.contains(&IssueAction::Archive));
    assert_eq!(
        actions.last(),
        Some(&IssueAction::RefreshBoard),
        "the pointer surface keeps the board footer"
    );
    assert!(matches!(app.mode, Mode::ActionMenu { .. }));
}

#[test]
fn action_menu_open_detail_matches_enter_key() {
    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 1);
    let issue_before = app.board.column_cards(0)[1].number;
    app.handle_mouse(down_right(x, y)).unwrap();
    assert!(select_menu_action(&mut app, &IssueAction::OpenDetail));
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();

    assert!(!matches!(app.mode, Mode::ActionMenu { .. }));
    assert!(app.action_menu.is_none());
    let Some(detail) = &app.detail else {
        panic!("menu Open detail should open the detail view");
    };
    assert_eq!(detail.issue.number, issue_before);

    // Board `Enter` opens the menu; selecting Open detail and pressing Enter
    // is the same two-step path the old `Enter` reached in one step.
    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 1);
    let _ = app.handle_mouse(down_left(x, y)).unwrap();
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();
    assert!(matches!(app.mode, Mode::ActionMenu { .. }));
    assert!(select_menu_action(&mut app, &IssueAction::OpenDetail));
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();
    assert_eq!(
        app.detail.as_ref().map(|d| d.issue.number),
        Some(issue_before),
        "menu Open detail and board Enter + Open detail open the same issue"
    );
}

#[test]
fn action_menu_edit_in_editor_matches_e_key() {
    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 1);
    app.handle_mouse(down_right(x, y)).unwrap();
    assert!(select_menu_action(&mut app, &IssueAction::EditInEditor));
    let action = app.handle_key(press(KeyCode::Enter)).unwrap();

    let selected = app.board.get_selected_card().cloned().unwrap().filename;
    assert_eq!(
        action,
        Action::OpenEditor(selected.clone()),
        "menu Edit in editor returns OpenEditor for the selected card"
    );

    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 1);
    let _ = app.handle_mouse(down_left(x, y)).unwrap();
    let key_action = app.handle_key(press(KeyCode::Char('e'))).unwrap();
    let key_filename = match app.board.get_selected_card() {
        Some(card) => card.filename.clone(),
        None => String::new(),
    };
    assert_eq!(
        key_action,
        Action::OpenEditor(key_filename),
        "board 'e' returns OpenEditor for the same card"
    );
}

#[test]
fn action_menu_move_to_matches_cardinal_move_key() {
    // Menu `Move to in review` on the first card must produce the same file
    // state as '>' twice (0 -> 1 -> 2) on a matching board.
    fn moved_via_menu() -> Status {
        let (_tmp, mut app) = make_mouse_app();
        let target = app.board.column_name(2).to_string();
        let (x, y) = card_cell(&app, 0, 0);
        app.handle_mouse(down_right(x, y)).unwrap();
        assert!(select_menu_action(
            &mut app,
            &IssueAction::MoveTo {
                column: target.clone()
            }
        ));
        app.handle_key(press(KeyCode::Enter)).unwrap();
        app.store
            .get(IssueSelector::Filename("a.md".to_string()))
            .unwrap()
            .status
    }

    fn moved_via_keys() -> Status {
        let (_tmp, mut app) = make_mouse_app();
        let (x, y) = card_cell(&app, 0, 0);
        let _ = app.handle_mouse(down_left(x, y)).unwrap();
        let _ = app.handle_key(press(KeyCode::Char('>'))).unwrap();
        let _ = app.handle_key(press(KeyCode::Char('>'))).unwrap();
        app.store
            .get(IssueSelector::Filename("a.md".to_string()))
            .unwrap()
            .status
    }

    assert_eq!(moved_via_menu(), moved_via_keys());
}

#[test]
fn action_menu_delete_sets_up_confirm() {
    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 1);
    app.handle_mouse(down_right(x, y)).unwrap();
    assert!(select_menu_action(&mut app, &IssueAction::Delete));
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();

    assert_eq!(app.mode, Mode::ConfirmDelete);
    assert_eq!(
        app.confirm_delete_target.as_deref(),
        Some("b.md"),
        "delete targets the right-clicked card"
    );
    assert!(!matches!(&app.mode, Mode::ActionMenu { .. }));
}

#[test]
fn action_menu_refresh_rebuilds_board() {
    let (_tmp, mut app) = make_mouse_app();
    let (x, y) = card_cell(&app, 0, 0);
    app.handle_mouse(down_right(x, y)).unwrap();
    assert!(select_menu_action(&mut app, &IssueAction::RefreshBoard));
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();

    assert_eq!(app.mode, Mode::Board);
    assert_eq!(app.status_msg.as_deref(), Some("Refreshed"));
    assert!(app.action_menu.is_none());
}

#[test]
fn action_menu_esc_closes_without_side_effects() {
    let (_tmp, mut app) = make_mouse_app();
    let (card_x, card_y) = card_cell(&app, 0, 1);
    app.handle_mouse(down_right(card_x, card_y)).unwrap();
    let status_before = app
        .store
        .get(IssueSelector::Filename("b.md".to_string()))
        .unwrap()
        .status
        .clone();

    let _ = app.handle_key(press(KeyCode::Esc)).unwrap();

    assert_eq!(app.mode, Mode::Board);
    assert!(app.action_menu.is_none());
    assert_eq!((app.board.active_col, app.board.selected), (0, 1));
    assert!(app.confirm_delete_target.is_none());
    assert_eq!(
        app.store
            .get(IssueSelector::Filename("b.md".to_string()))
            .unwrap()
            .status,
        status_before,
        "Esc closes the menu without mutating any issue"
    );
}

#[test]
fn action_menu_outside_click_closes_menu() {
    let (_tmp, mut app) = make_mouse_app();
    let (card_x, card_y) = card_cell(&app, 0, 1);
    app.handle_mouse(down_right(card_x, card_y)).unwrap();

    // Click far below the board area (outside the popup).
    let action = app.handle_mouse(down_left(40, 39)).unwrap();
    assert_eq!(action, Action::None);
    assert!(app.action_menu.is_none());
    assert_eq!(app.mode, Mode::Board);
    assert!(
        app.mouse.drag.is_none(),
        "the dismissing click must not start a drag"
    );
}

#[test]
fn action_menu_item_click_activates() {
    let (_tmp, mut app) = make_mouse_app();
    let (card_x, card_y) = card_cell(&app, 0, 1);
    app.handle_mouse(down_right(card_x, card_y)).unwrap();
    let menu = app.action_menu.as_ref().unwrap();
    let bounds = menu.bounds(app.frame_size.get());
    let row = menu
        .rows()
        .iter()
        .position(|row| {
            matches!(
                row,
                crate::ui::action_menu::Row::Item(index)
                    if menu.item(*index).is_some_and(|item| item.action == IssueAction::Delete)
            )
        })
        .expect("Delete is in the menu");
    let item_x = bounds.x + 2;
    let item_y = bounds.y + 1 + u16::try_from(row).unwrap();
    let _ = app.handle_mouse(down_left(item_x, item_y)).unwrap();

    assert_eq!(app.mode, Mode::ConfirmDelete);
    assert_eq!(app.confirm_delete_target.as_deref(), Some("b.md"));
    assert!(app.action_menu.is_none());
}

/// A configured column hidden by `hidden_columns` is still a move target in
/// the dialog, and moving there keeps the cursor on the visible column.
#[test]
fn action_menu_moves_to_a_hidden_column_by_name() {
    let (_tmp, mut app) = make_mouse_app();
    let board = app
        .store
        .config
        .kanban
        .configurations
        .get_mut("default")
        .unwrap();
    board.hidden_columns = vec!["in progress".into()];
    app.refresh_corpus().unwrap();
    assert!(
        app.board
            .hidden
            .iter()
            .any(|column| column.name == "in progress"),
        "the fixture hides the column"
    );
    let before = app.board.active_col;

    let (x, y) = card_cell(&app, 0, 0);
    app.handle_mouse(down_right(x, y)).unwrap();
    assert!(select_menu_action(
        &mut app,
        &IssueAction::MoveTo {
            column: "in progress".into()
        }
    ));
    let _ = app.handle_key(press(KeyCode::Enter)).unwrap();

    let issue = app
        .store
        .get(IssueSelector::Filename("a.md".into()))
        .unwrap();
    assert_eq!(issue.status.to_string(), "in progress");
    assert_eq!(
        app.board.active_col, before,
        "a hidden target has no visible cursor, so the cursor stays put"
    );
    assert!(
        app.board
            .hidden
            .iter()
            .flat_map(|column| column.cards.iter())
            .any(|card| card.number == 1),
        "the card is in the hidden column"
    );
}