quinjet 0.0.50

A fast, live, keyboard-first Git source-control interface for the terminal
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
use super::*;

#[test]
fn text_buffer_edits_unicode_on_character_boundaries() {
    let mut buffer = TextBuffer::new("a🚀b");
    buffer.move_left();
    buffer.backspace();
    assert_eq!(buffer.value, "ab");
    buffer.insert('é');
    assert_eq!(buffer.value, "aéb");
}

#[test]
fn text_buffer_supports_word_and_line_deletion() {
    let mut buffer = TextBuffer::new("first second\nthird word");
    buffer.delete_word_backward();
    assert_eq!(buffer.value, "first second\nthird ");
    buffer.delete_to_line_start();
    assert_eq!(buffer.value, "first second\n");
    buffer.document_start();
    buffer.delete_word_forward();
    assert_eq!(buffer.value, " second\n");
    buffer.document_end();
    buffer.delete_to_line_start();
    assert_eq!(buffer.value, " second\n");
}

#[test]
fn pane_resize_is_clamped_to_usable_bounds() {
    let mut app = App::new("/tmp/repo", "repo");
    app.geometry.main = Rect::new(5, 3, 120, 30);
    app.geometry.content = Rect::new(48, 3, 77, 30);

    app.resize_sidebar(120);
    assert_eq!(app.sidebar_width, 88);
    app.resize_sidebar(6);
    assert_eq!(app.sidebar_width, 22);
    app.resize_diff(49);
    assert_eq!(app.diff_split_percent, 20);
    app.resize_diff(124);
    assert_eq!(app.diff_split_percent, 80);
}

#[test]
fn double_tapping_each_divider_restores_its_default_size() {
    fn mouse(kind: MouseEventKind, column: u16, row: u16) -> MouseEvent {
        MouseEvent {
            kind,
            column,
            row,
            modifiers: KeyModifiers::NONE,
        }
    }

    let mut app = App::new("/tmp/repo", "repo");
    app.geometry.main = Rect::new(5, 3, 120, 30);
    app.geometry.sidebar_divider = Rect::new(82, 3, 1, 30);
    app.geometry.content = Rect::new(48, 3, 77, 30);
    app.geometry.diff_divider = Some(Rect::new(109, 3, 1, 30));
    app.sidebar_width = 77;
    app.diff_split_percent = 80;
    let now = Instant::now();

    app.handle_mouse(mouse(MouseEventKind::Down(MouseButton::Left), 82, 10), now);
    app.handle_mouse(
        mouse(MouseEventKind::Up(MouseButton::Left), 82, 10),
        now + Duration::from_millis(20),
    );
    app.handle_mouse(
        mouse(MouseEventKind::Down(MouseButton::Left), 82, 10),
        now + Duration::from_millis(120),
    );
    assert_eq!(app.sidebar_width, DEFAULT_SIDEBAR_WIDTH);
    assert_eq!(app.resize_target, None);

    app.handle_mouse(
        mouse(MouseEventKind::Down(MouseButton::Left), 109, 10),
        now + Duration::from_millis(600),
    );
    app.handle_mouse(
        mouse(MouseEventKind::Up(MouseButton::Left), 109, 10),
        now + Duration::from_millis(620),
    );
    app.handle_mouse(
        mouse(MouseEventKind::Down(MouseButton::Left), 109, 10),
        now + Duration::from_millis(720),
    );
    assert_eq!(app.diff_split_percent, DEFAULT_DIFF_SPLIT_PERCENT);
    assert_eq!(app.resize_target, None);
}

#[test]
fn filters_changes_without_losing_underlying_index() {
    let mut app = app_with_changes();
    app.filter = "read".to_owned();
    assert_eq!(app.visible_change_indices(), vec![1]);
    assert_eq!(
        app.selected_change().unwrap().path,
        PathBuf::from("README.md")
    );
}

#[test]
fn discard_on_a_conflict_opens_resolution_instead() {
    let mut app = app_with_changes();
    app.status.changes[0].area = ChangeArea::Conflict;
    app.status.changes[0].status = ChangeStatus::Conflicted;

    let effects = app.handle_key(
        KeyEvent::new(KeyCode::Char('x'), KeyModifiers::NONE),
        Instant::now(),
    );

    assert!(effects.is_empty());
    assert!(matches!(app.modal, Some(Modal::Conflict { .. })));
}

#[test]
fn a_section_checkbox_checks_and_clears_its_whole_group() {
    let mut app = app_with_changes();
    let mut effects = Vec::new();

    app.handle_scm_action(
        ScmAction::ToggleCheckSection(ChangeSection::Unstaged),
        &mut effects,
    );
    assert_eq!(app.checked_change_count(), 1);
    assert_eq!(app.section_check_label(ChangeSection::Unstaged), "[x]");
    assert_eq!(app.section_check_label(ChangeSection::Staged), "[ ]");

    app.handle_scm_action(
        ScmAction::ToggleCheckSection(ChangeSection::Staged),
        &mut effects,
    );
    app.status.changes.push(Change {
        path: PathBuf::from("docs/notes.md"),
        original_path: None,
        area: ChangeArea::Staged,
        status: ChangeStatus::Modified,
    });
    assert_eq!(app.section_check_label(ChangeSection::Staged), "[-]");

    app.handle_scm_action(
        ScmAction::ToggleCheckSection(ChangeSection::Staged),
        &mut effects,
    );
    assert_eq!(app.section_check_label(ChangeSection::Staged), "[x]");
    assert_eq!(app.checked_change_count(), 3);

    app.handle_scm_action(
        ScmAction::ToggleCheckSection(ChangeSection::Staged),
        &mut effects,
    );
    assert_eq!(app.section_check_label(ChangeSection::Staged), "[ ]");
    assert_eq!(app.checked_change_count(), 1);
    assert!(effects.is_empty());
}

#[test]
fn the_revert_button_asks_about_the_checked_files() {
    let mut app = app_with_changes();
    let mut effects = Vec::new();
    app.handle_scm_action(
        ScmAction::ToggleCheckSection(ChangeSection::Unstaged),
        &mut effects,
    );

    app.handle_scm_action(ScmAction::RevertChecked, &mut effects);

    let Some(Modal::Confirm { title, action, .. }) = app.modal else {
        panic!("the revert button must ask first");
    };
    assert_eq!(title, "Revert Checked Files?");
    let ConfirmAction::Operate(GitOperation::Discard(changes)) = action else {
        panic!("the confirmation must carry a discard operation");
    };
    assert_eq!(changes.len(), 1);
    assert_eq!(changes[0].path, PathBuf::from("src/main.rs"));
    assert!(effects.is_empty());
}

#[test]
fn shift_x_asks_to_remove_the_selected_file() {
    let mut app = app_with_changes();

    let effects = app.handle_key(
        KeyEvent::new(KeyCode::Char('X'), KeyModifiers::SHIFT),
        Instant::now(),
    );

    assert!(effects.is_empty());
    let Some(Modal::Confirm { title, action, .. }) = app.modal else {
        panic!("removing the selected file must ask first");
    };
    assert_eq!(title, "Remove File?");
    let ConfirmAction::Operate(GitOperation::Remove(paths)) = action else {
        panic!("the confirmation must carry a remove operation");
    };
    assert_eq!(paths, vec![PathBuf::from("src/main.rs")]);
}

#[test]
fn checked_files_drive_revert_and_remove() {
    let mut app = app_with_changes();
    app.checked_change_paths
        .extend([PathBuf::from("src/main.rs"), PathBuf::from("README.md")]);

    let items = app.scm_menu_items();
    assert!(items.contains(&ScmMenuItem::RemoveChecked));
    assert!(items.contains(&ScmMenuItem::DiscardChecked));
    assert!(!items.contains(&ScmMenuItem::RemoveSelected));
    assert_eq!(
        app.scm_menu_label(ScmMenuItem::RemoveChecked),
        "Remove Checked Files (2)"
    );

    let effects = app.handle_key(
        KeyEvent::new(KeyCode::Char('x'), KeyModifiers::NONE),
        Instant::now(),
    );

    assert!(effects.is_empty());
    let Some(Modal::Confirm { title, action, .. }) = app.modal else {
        panic!("reverting the checked files must ask first");
    };
    assert_eq!(title, "Revert Checked Files?");
    let ConfirmAction::Operate(GitOperation::Discard(changes)) = action else {
        panic!("the confirmation must carry a discard operation");
    };
    assert_eq!(changes.len(), 2);
}

#[test]
fn the_changes_menu_offers_reverting_the_working_tree() {
    let mut app = app_with_changes();

    let items = app.scm_menu_items();
    assert!(items.contains(&ScmMenuItem::DiscardUnstaged));
    assert!(items.contains(&ScmMenuItem::DiscardAll));
    assert!(items.contains(&ScmMenuItem::RemoveSelected));

    let position = items
        .iter()
        .position(|item| *item == ScmMenuItem::DiscardAll)
        .expect("the menu must offer reverting every change");
    app.scm_menu_open = true;
    app.scm_menu_selected = position;
    let effects = app.handle_key(
        KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE),
        Instant::now(),
    );

    assert!(effects.is_empty());
    assert!(!app.scm_menu_open);
    let Some(Modal::Confirm { title, action, .. }) = app.modal else {
        panic!("reverting every change must ask first");
    };
    assert_eq!(title, "Revert All Changes?");
    let ConfirmAction::Operate(GitOperation::Discard(changes)) = action else {
        panic!("the confirmation must carry a discard operation");
    };
    assert_eq!(changes.len(), 2);
}

#[test]
fn enter_toggles_focus_between_sidebar_and_content() {
    let mut app = app_with_changes();
    let now = Instant::now();

    let effects = app.handle_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE), now);
    assert_eq!(app.focus, Focus::Content);
    assert!(app.mouse_capture);
    assert!(effects.is_empty());

    let effects = app.handle_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE), now);
    assert_eq!(app.focus, Focus::Sidebar);
    assert!(app.mouse_capture);
    assert!(effects.is_empty());
}

#[test]
fn enter_moves_focus_without_folding_files_or_check_steps() {
    let now = Instant::now();
    let mut diff = App::new("/tmp/repo", "repo");
    diff.document = indexed_document(&["src/main.rs", "src/lib.rs"]);
    diff.selected_preview_file = Some(PathBuf::from("src/main.rs"));
    diff.focus = Focus::Content;

    diff.handle_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE), now);

    assert_eq!(diff.focus, Focus::Sidebar);
    assert!(!diff.preview_file_collapsed("src/main.rs"));

    let mut log = App::new("/tmp/repo", "repo");
    log.view = View::PullRequests;
    log.pull_request_section = PullRequestSection::Overview;
    log.pull_request_check_cursor = Some(0);
    log.pull_request_step_cursor = 4;
    let _ = log.expanded_check_steps.insert(4);
    log.focus = Focus::Content;

    log.handle_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE), now);

    assert_eq!(log.focus, Focus::Sidebar);
    assert!(log.check_step_expanded(4));
}

#[test]
fn preview_focus_preserves_an_explicit_no_mouse_setting() {
    let mut app = app_with_changes();
    let now = Instant::now();
    app.configure_mouse_capture(false);

    let effects = app.handle_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE), now);
    assert_eq!(app.focus, Focus::Content);
    assert!(!app.mouse_capture);
    assert!(effects.is_empty());

    let effects = app.handle_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE), now);
    assert_eq!(app.focus, Focus::Sidebar);
    assert!(!app.mouse_capture);
    assert!(effects.is_empty());
}

#[test]
fn expanded_preview_files_are_selectable_from_the_content_pane() {
    let mut app = App::new("/tmp/repo", "repo");
    app.document = indexed_document(&["src/main.rs", "src/lib.rs"]);
    app.selected_preview_file = Some(PathBuf::from("src/main.rs"));
    app.focus = Focus::Content;

    app.handle_key(
        KeyEvent::new(KeyCode::Char('j'), KeyModifiers::NONE),
        Instant::now(),
    );

    assert_eq!(app.selected_preview_file, Some(PathBuf::from("src/lib.rs")));
    assert_eq!(app.preview_file_cursor, 1);
    assert!(app.content_scroll > 0);
}

#[test]
fn reading_a_pull_request_never_pushes_your_own_branch() {
    let mut app = app_with_changes();
    let now = Instant::now();
    app.view = View::PullRequests;

    for character in ['p', 'f'] {
        let effects = app.handle_key(
            KeyEvent::new(KeyCode::Char(character), KeyModifiers::NONE),
            now,
        );
        assert!(
            effects.is_empty(),
            "{character} queued work from inside the pull-request view"
        );
        assert!(app.busy.is_none(), "{character} started a git operation");
    }

    app.view = View::Changes;
    app.handle_key(KeyEvent::new(KeyCode::Char('f'), KeyModifiers::NONE), now);
    assert!(app.busy.is_some(), "fetch still runs from the changes view");
}

#[test]
fn shift_o_opens_branches_commits_pull_requests_and_checks() {
    let mut app = app_with_changes();
    let now = Instant::now();
    app.local_github_repository = Some(GitHubRepository {
        name_with_owner: "o/r".to_owned(),
        url: "https://github.com/o/r".to_owned(),
        remotes: vec!["origin".to_owned()],
    });
    app.status.branch.head = "feature/right-pane".to_owned();

    let effects = app.handle_key(KeyEvent::new(KeyCode::Char('O'), KeyModifiers::NONE), now);
    assert!(matches!(
        effects.as_slice(),
        [AppEffect::Open(OpenTarget::Browser(url))]
            if url == "https://github.com/o/r/tree/feature/right-pane"
    ));

    app.view = View::History;
    app.history.push(Commit {
        id: "abc123".to_owned(),
        short_id: "abc123".to_owned(),
        parent_ids: Vec::new(),
        author: String::new(),
        author_email: String::new(),
        authored_at: String::new(),
        committer: String::new(),
        committer_email: String::new(),
        committed_at: String::new(),
        relative_date: String::new(),
        subject: "Selectable commit".to_owned(),
        decorations: Vec::new(),
    });
    let effects = app.handle_key(KeyEvent::new(KeyCode::Char('O'), KeyModifiers::NONE), now);
    assert!(matches!(
        effects.as_slice(),
        [AppEffect::Open(OpenTarget::Browser(url))]
            if url == "https://github.com/o/r/commit/abc123"
    ));

    app.view = View::PullRequests;

    let effects = app.handle_key(KeyEvent::new(KeyCode::Char('O'), KeyModifiers::NONE), now);
    assert!(effects.is_empty(), "nothing is open, so nothing to open");

    app.pull_request = Some(PullRequest {
        url: "https://github.com/o/r/pull/8".to_owned(),
        ..PullRequest::default()
    });
    let effects = app.handle_key(KeyEvent::new(KeyCode::Char('O'), KeyModifiers::NONE), now);
    assert!(matches!(
        effects.as_slice(),
        [AppEffect::Open(OpenTarget::Browser(url))]
            if url == "https://github.com/o/r/pull/8"
    ));

    app.pull_request_checks = vec![PullRequestCheck {
        name: "build".to_owned(),
        workflow: "CI".to_owned(),
        state: "SUCCESS".to_owned(),
        status: PullRequestCheckStatus::Passed,
        description: String::new(),
        link: "https://github.com/o/r/actions/runs/1/job/2".to_owned(),
        started_at: String::new(),
        completed_at: String::new(),
    }];
    app.set_check_cursor(Some(0));
    let effects = app.handle_key(KeyEvent::new(KeyCode::Char('O'), KeyModifiers::NONE), now);
    assert!(
        matches!(
            effects.as_slice(),
            [AppEffect::Open(OpenTarget::Browser(url))]
                if url.contains("/actions/runs/1/job/2")
        ),
        "a selected check opens the run it names, not the pull request"
    );
}