ratado 0.2.0

A fast, keyboard-driven terminal task manager built with Rust and 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
//! End-to-End Tests for Ratado
//!
//! These tests spawn the actual Ratado binary in a PTY and verify behaviour
//! using two complementary strategies:
//! - **UI verification** (`expect_text`) while the app is running
//! - **Database verification** (`DbVerifier`) after the app exits
//!
//! # Running E2E Tests
//!
//! ```bash
//! cargo test --test e2e_tests
//! ```

mod e2e;

use e2e::RatadoTest;
use expectrl::Expect;
use std::time::Duration;

// ============================================================================
// Application Lifecycle Tests
// ============================================================================

#[test]
fn test_app_starts_and_shows_empty_state() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    // UI: verify empty state message is shown
    app.expect_text("Ready for liftoff");

    // Verify database was created on disk
    assert!(app.database_exists(), "Database file should exist");

    // DB: verify no tasks after quit
    let db = app.quit();
    db.assert_task_count(0);
}

// ============================================================================
// Task Creation Tests
// ============================================================================

#[test]
fn test_add_single_task() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Buy groceries");

    // UI: the task title should appear in the task list
    app.expect_text("Buy groceries");

    // DB: verify task was persisted
    let db = app.quit();
    db.assert_task_count(1);
    db.assert_task_exists("Buy groceries");
    db.assert_task_pending("Buy groceries");
}

#[test]
fn test_add_multiple_tasks() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Task One");
    app.expect_text("Task One");

    app.add_task("Task Two");
    app.expect_text("Task Two");

    app.add_task("Task Three");
    app.expect_text("Task Three");

    // DB: verify all tasks were persisted
    let db = app.quit();
    db.assert_task_count(3);
    db.assert_task_exists("Task One");
    db.assert_task_exists("Task Two");
    db.assert_task_exists("Task Three");
    db.assert_pending_count(3);
    db.assert_completed_count(0);
}

#[test]
fn test_empty_task_not_created() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    // Open quick capture dialog and try to submit without typing a title
    app.press("a");
    app.wait(Duration::from_millis(100));
    // Press Enter with empty title
    app.press_enter();
    app.wait(Duration::from_millis(100));

    // DB: no task should have been created
    let db = app.quit();
    db.assert_task_count(0);
}

// ============================================================================
// Task Completion Tests
// ============================================================================

#[test]
fn test_toggle_task_completion() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    // Switch to "All" filter so completed tasks stay visible
    app.set_filter_all();

    app.add_task("Complete me");
    app.expect_text("Complete me");

    // Toggle to completed
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // Toggle back to pending (task is still visible with "All" filter)
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // DB: task should be pending after two toggles
    let db = app.quit();
    db.assert_task_count(1);
    db.assert_task_pending("Complete me");
}

#[test]
fn test_complete_single_task() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Finish report");
    app.expect_text("Finish report");

    // Complete the task
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // DB: verify it's completed
    let db = app.quit();
    db.assert_task_completed("Finish report");
    db.assert_completed_count(1);
}

#[test]
fn test_complete_multiple_tasks() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    // Switch to "All" filter so completed tasks stay visible and don't shift indices
    app.set_filter_all();

    app.add_task("Task A");
    app.add_task("Task B");
    app.add_task("Task C");

    // Navigate to first task
    app.press("g"); // Jump to top
    app.wait(Duration::from_millis(50));
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // Move down and complete second
    app.move_down();
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // DB: verify specific tasks
    let db = app.quit();
    db.assert_task_completed("Task A");
    db.assert_task_completed("Task B");
    db.assert_task_pending("Task C");
    db.assert_completed_count(2);
    db.assert_pending_count(1);
}

// ============================================================================
// Task Deletion Tests
// ============================================================================

#[test]
fn test_delete_task() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Delete me");
    app.expect_text("Delete me");

    // Delete it (press 'd', confirm dialog shows, press 'y')
    app.delete_task();

    // DB: verify deletion
    let db = app.quit();
    db.assert_task_count(0);
    db.assert_task_not_exists("Delete me");
}

#[test]
fn test_delete_one_of_multiple_tasks() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Keep me");
    app.add_task("Delete me");
    app.add_task("Keep me too");

    // Navigate to second task and delete
    app.press("g"); // Jump to top
    app.wait(Duration::from_millis(50));
    app.move_down();
    app.delete_task();

    // DB: verify correct task was deleted
    let db = app.quit();
    db.assert_task_count(2);
    db.assert_task_exists("Keep me");
    db.assert_task_not_exists("Delete me");
    db.assert_task_exists("Keep me too");
}

#[test]
fn test_cancel_delete() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Keep me");
    app.expect_text("Keep me");

    // Start delete but cancel with 'n'
    app.press("d");
    app.wait(Duration::from_millis(100));
    app.press("n");
    app.wait(Duration::from_millis(100));

    // DB: task should still exist
    let db = app.quit();
    db.assert_task_count(1);
    db.assert_task_exists("Keep me");
}

// ============================================================================
// Navigation Tests
// ============================================================================

#[test]
fn test_navigation_with_vim_keys() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    // Switch to "All" filter so completed tasks stay visible
    app.set_filter_all();

    app.add_task("First");
    app.add_task("Second");
    app.add_task("Third");

    // Jump to top, complete first task to verify selection
    app.press("g");
    app.wait(Duration::from_millis(50));
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // Move down twice to third, complete it
    app.move_down();
    app.move_down();
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // Move up to second, complete it
    app.move_up();
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // DB: all should be completed
    let db = app.quit();
    db.assert_completed_count(3);
    db.assert_task_completed("First");
    db.assert_task_completed("Second");
    db.assert_task_completed("Third");
}

#[test]
fn test_navigation_with_arrow_keys() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    // Switch to "All" filter so completed tasks stay visible
    app.set_filter_all();

    app.add_task("Task A");
    app.add_task("Task B");

    // Jump to top first
    app.press("g");
    app.wait(Duration::from_millis(50));

    // Navigate down with arrow keys and complete
    app.press_arrow("down");
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // DB: second task should be completed
    let db = app.quit();
    db.assert_task_pending("Task A");
    db.assert_task_completed("Task B");
}

// ============================================================================
// Search Tests
// ============================================================================

#[test]
fn test_search_dialog_opens_and_closes() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Searchable task");
    app.expect_text("Searchable task");

    // Open search
    app.open_search();
    app.wait(Duration::from_millis(100));

    // UI: search dialog should be visible
    app.expect_text("Search");

    // Close with Escape
    app.press_escape();
    app.wait(Duration::from_millis(100));

    // App should still be functional - add another task
    app.add_task("Another task");
    app.expect_text("Another task");

    let db = app.quit();
    db.assert_task_count(2);
}

// ============================================================================
// Priority Tests
// ============================================================================

#[test]
fn test_cycle_priority() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Priority test");
    app.expect_text("Priority test");

    // Cycle priority multiple times
    app.press("p");
    app.wait(Duration::from_millis(100));
    app.press("p");
    app.wait(Duration::from_millis(100));

    // DB: task should still exist
    let db = app.quit();
    db.assert_task_exists("Priority test");
}

// ============================================================================
// Edit Tests
// ============================================================================

#[test]
fn test_edit_dialog_opens_and_closes() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Original title");
    app.expect_text("Original title");

    // Open edit dialog
    app.edit_task();
    app.wait(Duration::from_millis(100));

    // Cancel with Escape
    app.press_escape();
    app.wait(Duration::from_millis(100));

    // DB: task should be unchanged
    let db = app.quit();
    db.assert_task_exists("Original title");
}

// ============================================================================
// Panel Switching Tests
// ============================================================================

#[test]
fn test_panel_switching() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Test task");
    app.expect_text("Test task");

    // Switch panels with h/l
    app.press("h"); // To sidebar
    app.wait(Duration::from_millis(100));
    app.press("l"); // Back to task list
    app.wait(Duration::from_millis(100));

    // Switch with Tab
    app.press_tab();
    app.wait(Duration::from_millis(100));

    // DB: app should still be functional
    let db = app.quit();
    db.assert_task_count(1);
}

// ============================================================================
// Edge Case Tests
// ============================================================================

#[test]
fn test_special_characters_in_title() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Task with 'quotes' and numbers 123");
    app.expect_text("Task with");

    let db = app.quit();
    db.assert_task_count(1);
}

#[test]
fn test_rapid_operations() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    // Rapid add
    for i in 1..=5 {
        app.add_task(&format!("Rapid task {}", i));
    }

    // Rapid navigation
    for _ in 0..10 {
        app.press("j");
    }
    for _ in 0..10 {
        app.press("k");
    }

    // DB: tasks should all be there
    let db = app.quit();
    db.assert_task_count(5);
}

// ============================================================================
// Full Workflow Tests
// ============================================================================

#[test]
fn test_full_task_lifecycle() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    // Switch to "All" filter so completed tasks stay visible for toggling back
    app.set_filter_all();

    // 1. Create task
    app.add_task("Lifecycle test");
    app.expect_text("Lifecycle test");

    // 2. Complete it
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // 3. Uncomplete it
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // 4. Delete it
    app.delete_task();
    app.wait(Duration::from_millis(100));

    // DB: should be gone
    let db = app.quit();
    db.assert_task_count(0);
    db.assert_task_not_exists("Lifecycle test");
}

#[test]
fn test_debug_view_toggle() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    app.add_task("Debug test");
    app.expect_text("Debug test");

    // Toggle debug view with F12
    app.session.send("\x1b[24~").expect("Failed to send F12");
    app.wait(Duration::from_millis(200));

    // Toggle back
    app.session.send("\x1b[24~").expect("Failed to send F12");
    app.wait(Duration::from_millis(200));

    // DB: app should still work
    let db = app.quit();
    db.assert_task_exists("Debug test");
}

// ============================================================================
// Filter Tests
// ============================================================================

#[test]
fn test_mixed_task_states() {
    let mut app = RatadoTest::spawn();
    app.wait_for_startup();

    // Switch to "All" filter so completed tasks stay visible
    app.set_filter_all();

    app.add_task("Pending task");
    app.add_task("Completed task");

    // Complete the second task
    app.press("g"); // Jump to top
    app.wait(Duration::from_millis(50));
    app.move_down();
    app.toggle_complete();
    app.wait(Duration::from_millis(100));

    // DB: verify database state
    let db = app.quit();
    db.assert_pending_count(1);
    db.assert_completed_count(1);
    db.assert_task_pending("Pending task");
    db.assert_task_completed("Completed task");
}