linear-tui 0.9.0

A TUI client for Linear.app — manage issues, projects, and cycles from your 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
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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
//! Reopening a [`ViewSnapshot`] on launch.
//!
//! A snapshot names its page by ID, and the IDs only turn into places once
//! Linear has answered: a team needs the teams, a saved view the views, a
//! project page the team's projects. So a restore is a walk down the path the
//! user took — destination, then the project or cycle page, then the issue —
//! each step taken as soon as what it needs has arrived. Anything that is gone
//! lands on its parent: a deleted view on the Views page, a deleted project on
//! the project list, a deleted issue on the list it was opened from.

use super::*;
use crate::snapshot::{self as snap, ViewSnapshot};

/// What is left of a restore.
#[derive(Debug)]
pub struct Restore {
    pub(super) team: Option<TeamId>,
    /// The destination to open, until it has been.
    pub(super) dest: Option<snap::Destination>,
    search: Option<String>,
    project: Option<ProjectId>,
    cycle: Option<CycleId>,
    issue: Option<snap::IssueRef>,
    /// The restored issue page, until Linear confirms the issue still exists.
    opened_issue: Option<IssueId>,
    /// The row to put the cursor back on in a project, cycle, or view list.
    row: Option<String>,
    /// The issue to put each list's cursor back on once its rows arrive.
    selection: Vec<(IssueSource, IssueId)>,
}

impl Restore {
    fn is_done(&self) -> bool {
        self.dest.is_none()
            && self.project.is_none()
            && self.cycle.is_none()
            && self.issue.is_none()
            && self.opened_issue.is_none()
            && self.row.is_none()
            && self.selection.is_empty()
    }
}

impl App {
    /// Reopen `snapshot` as Linear's answers come in. The list settings take
    /// effect at once: a team list's preset decides what is fetched.
    pub fn restore(&mut self, snapshot: ViewSnapshot) {
        self.view.group_by = snapshot.group_by.into();
        let mut selection = Vec::new();
        for settings in &snapshot.lists {
            let source = IssueSource::from(settings.source);
            let list = &mut self.view.lists[source];
            list.preset = settings.preset.into();
            list.filters.status.clone_from(&settings.status);
            list.filters.priority = settings
                .priority
                .as_deref()
                .and_then(|label| Priority::ALL.into_iter().find(|p| p.label() == label));
            if let Some(issue) = &settings.selected {
                selection.push((source, issue.id.clone()));
            }
        }
        let row = match snapshot.screen {
            snap::Screen::ProjectList | snap::Screen::CycleList | snap::Screen::ViewList => {
                snapshot.selected().map(|row| row.id.clone())
            }
            _ => None,
        };
        self.restore = Some(Restore {
            team: snapshot.team.map(|t| t.id),
            dest: Some(snapshot.destination),
            search: snapshot.search,
            project: snapshot.project.map(|p| p.id),
            cycle: snapshot.cycle.map(|c| c.id),
            issue: snapshot.issue,
            opened_issue: None,
            row,
            selection,
        });
    }

    /// Open the issue `identifier` names once the teams are in, over the
    /// team's list — `linear-tui open ENG-42`. Linear looks an issue up by
    /// identifier as readily as by ID, so the identifier stands in for the
    /// ID until the detail arrives.
    pub fn open_on_launch(&mut self, identifier: &str) {
        self.restore = Some(Restore {
            team: None,
            dest: None,
            search: None,
            project: None,
            cycle: None,
            issue: Some(snap::IssueRef {
                id: IssueId::new(identifier),
                identifier: identifier.to_string(),
                title: String::new(),
            }),
            opened_issue: None,
            row: None,
            selection: Vec::new(),
        });
    }

    /// Whether a restore is still finding its way to the destination — in
    /// which case the default first page is not fetched.
    pub(super) fn restoring_destination(&self) -> bool {
        self.restore.as_ref().is_some_and(|r| r.dest.is_some())
    }

    /// The team a restore reopens, by its position in `teams`.
    pub(super) fn restored_team(&self, teams: &[Team]) -> Option<usize> {
        let id = self.restore.as_ref()?.team.as_ref()?;
        teams.iter().position(|t| &t.id == id)
    }

    /// Take the next steps of the restore that what has arrived allows.
    pub(super) fn advance_restore(&mut self) {
        let Some(mut restore) = self.restore.take() else {
            return;
        };
        self.step_restore(&mut restore);
        if !restore.is_done() {
            self.restore = Some(restore);
        }
    }

    fn step_restore(&mut self, r: &mut Restore) {
        if self.store.teams.is_empty() {
            return;
        }
        if let Some(dest) = r.dest.take() {
            match self.resolve_destination(&dest) {
                None => {
                    r.dest = Some(dest);
                    return;
                }
                Some(Ok(nav)) => self.enter(nav),
                Some(Err(parent)) => {
                    self.enter(parent);
                    r.project = None;
                    r.cycle = None;
                    r.issue = None;
                    r.row = None;
                }
            }
            if let Some(term) = r.search.take() {
                let team_id = self.team_id();
                self.request(Request::Search { term, team_id });
            }
            // A favorite opens its own project, cycle, or issue page.
            if let Nav::Favorite(_) = self.nav.dest {
                r.project = None;
                r.cycle = None;
            }
        }

        if let Some(id) = &r.project {
            let rows = if self.in_project_view() {
                &self.store.view_projects
            } else {
                &self.store.projects
            };
            if !rows.loaded {
                return;
            }
            // A project that is gone leaves the list it was on open.
            if let Some(project) = rows.items.iter().find(|p| &p.id == id).cloned() {
                self.open_project(project);
            }
            r.project = None;
        }
        if let Some(id) = &r.cycle {
            if !self.store.cycles.loaded {
                return;
            }
            if let Some(cycle) = self
                .store
                .cycles
                .items
                .iter()
                .find(|c| &c.id == id)
                .cloned()
            {
                self.open_cycle(cycle);
            }
            r.cycle = None;
        }

        if let Some(issue) = r.issue.take()
            && self.store.current_issue.as_ref().map(|i| &i.id) != Some(&issue.id)
        {
            // Just enough to draw the header; the detail fetch fills the rest.
            let stub = Issue {
                id: issue.id.clone(),
                identifier: issue.identifier,
                title: issue.title,
                ..Issue::default()
            };
            self.open_issue_from_list(&stub);
            r.opened_issue = Some(issue.id);
        }

        if let Some(id) = r.row.clone() {
            match self.nav.screen {
                Screen::ProjectList => {
                    let rows = if self.in_project_view() {
                        &self.store.view_projects
                    } else {
                        &self.store.projects
                    };
                    if !rows.loaded {
                        return;
                    }
                    if let Some(index) = rows.items.iter().position(|p| p.id == id.as_str()) {
                        *self.project_cursor_mut() = index;
                    }
                }
                Screen::CycleList => {
                    if !self.store.cycles.loaded {
                        return;
                    }
                    let cycles = &self.store.cycles.items;
                    if let Some(index) = cycles.iter().position(|c| c.id == id.as_str()) {
                        self.view.selected_cycle_index = index;
                    }
                }
                Screen::ViewList => {
                    let views = &self.store.custom_views;
                    if let Some(index) = self
                        .listed_views()
                        .iter()
                        .position(|&i| views[i].id == id.as_str())
                    {
                        self.view.selected_view_index = index;
                    }
                }
                _ => {}
            }
            r.row = None;
        }
    }

    /// The place a snapshot's destination names now: `Ok` when it is still
    /// there, `Err` with its parent when it is gone, `None` while what it
    /// needs has not arrived.
    fn resolve_destination(&self, dest: &snap::Destination) -> Option<Result<Nav, Nav>> {
        let team_issues = Nav::Team(self.nav.team, TeamSection::Issues);
        Some(match dest {
            snap::Destination::MyIssues => Ok(Nav::MyIssues),
            snap::Destination::Views => Ok(Nav::Views),
            snap::Destination::Team { team, section } => self
                .store
                .teams
                .iter()
                .position(|t| t.id == team.id)
                .map(|index| Nav::Team(index, (*section).into()))
                .ok_or(team_issues),
            snap::Destination::View { id, .. } => {
                if !self.store.views_loaded {
                    return None;
                }
                self.store
                    .custom_views
                    .iter()
                    .position(|v| &v.id == id)
                    .map(Nav::View)
                    .ok_or(Nav::Views)
            }
            snap::Destination::Favorite { id, .. } => {
                if !self.store.favorites_loaded {
                    return None;
                }
                self.store
                    .favorites
                    .iter()
                    .position(|f| &f.id == id)
                    .map(Nav::Favorite)
                    .ok_or(team_issues)
            }
        })
    }

    /// Go to `nav` as the first page of the session. The default page is
    /// not fetched while a restore is pending, so arriving somewhere the app
    /// already points at must still fetch it.
    fn enter(&mut self, nav: Nav) {
        let before = (self.nav.dest, self.nav.screen);
        self.activate(nav);
        if (self.nav.dest, self.nav.screen) == before {
            self.reload_current_tab();
        }
    }

    /// The issue to put `source`'s cursor back on, taken once its rows land.
    pub(super) fn take_restored_selection(&mut self, source: IssueSource) -> Option<IssueId> {
        let restore = self.restore.as_mut()?;
        let at = restore.selection.iter().position(|(s, _)| *s == source)?;
        let (_, id) = restore.selection.remove(at);
        if restore.is_done() {
            self.restore = None;
        }
        Some(id)
    }

    /// A list the restore was waiting on could not be loaded: stop waiting
    /// and go to the destination's parent.
    pub(super) fn restore_lost(&mut self, request: &Request) {
        let Some(restore) = &mut self.restore else {
            return;
        };
        match (request, &restore.dest) {
            (Request::CustomViews, Some(snap::Destination::View { .. })) => {
                restore.dest = Some(snap::Destination::Views);
            }
            (Request::Favorites, Some(snap::Destination::Favorite { .. })) => {
                restore.dest = Some(snap::Destination::MyIssues);
                restore.project = None;
                restore.cycle = None;
                restore.issue = None;
            }
            _ => return,
        }
        self.advance_restore();
    }

    /// The restored issue page could not be loaded — the issue was deleted,
    /// or moved out of reach. Go back to the list it was opened from rather
    /// than show a page for nothing. True when that is what happened.
    pub(super) fn restored_issue_failed(&mut self, issue_id: &IssueId) -> bool {
        let Some(restore) = &mut self.restore else {
            return false;
        };
        if restore.opened_issue.as_ref() != Some(issue_id) {
            return false;
        }
        restore.opened_issue = None;
        if restore.is_done() {
            self.restore = None;
        }
        if self.nav.screen == Screen::IssueDetail
            && self.store.current_issue.as_ref().map(|i| &i.id) == Some(issue_id)
        {
            let identifier = self.store.current_issue.take().map(|i| i.identifier);
            self.close_detail();
            if let Some(identifier) = identifier {
                self.set_status(format!("{identifier} is not available"));
            }
        }
        true
    }

    /// The user took over: whatever the restore has not reached yet stays
    /// where it is, and a destination it was still waiting for gives way to
    /// the team's issues.
    pub fn cancel_restore(&mut self) {
        let Some(restore) = self.restore.take() else {
            return;
        };
        if restore.dest.is_some() && !self.store.teams.is_empty() {
            self.enter(Nav::Team(self.nav.team, TeamSection::Issues));
        }
    }

    /// The restored issue page loaded; nothing is left to undo.
    pub(super) fn restored_issue_loaded(&mut self, issue: &Issue) {
        // An issue opened by identifier learns its real ID now.
        let mut adopted = false;
        if let Some(current) = &mut self.store.current_issue
            && current.id != issue.id
            && current.identifier == issue.identifier
        {
            *current = issue.clone();
            adopted = true;
        }
        if let Some(restore) = &mut self.restore
            && (adopted || restore.opened_issue.as_ref() == Some(&issue.id))
        {
            restore.opened_issue = None;
            if restore.is_done() {
                self.restore = None;
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use std::path::PathBuf;

    use super::*;
    use crate::snapshot::Origin;

    fn issue(id: &str) -> Issue {
        serde_json::from_str(&format!(
            r#"{{"id":"{id}","identifier":"ENG-{id}","title":"Issue {id}","priority":0}}"#
        ))
        .unwrap()
    }

    fn team(id: &str, key: &str) -> Team {
        serde_json::from_str(&format!(
            r#"{{"id":"{id}","name":"{key} team","key":"{key}"}}"#
        ))
        .unwrap()
    }

    fn view(id: &str) -> CustomView {
        serde_json::from_str(&format!(r#"{{"id":"{id}","name":"View {id}"}}"#)).unwrap()
    }

    fn project(id: &str) -> Project {
        serde_json::from_str(&format!(r#"{{"id":"{id}","name":"Project {id}"}}"#)).unwrap()
    }

    fn origin() -> Origin {
        Origin {
            workspace: PathBuf::from("/repo"),
            cwd: PathBuf::from("/repo"),
            pid: 42,
            herdr_pane: None,
        }
    }

    fn page<T>(items: Vec<T>) -> Page<T> {
        Page::new(items, PageInfo::default(), false)
    }

    fn team_ref(id: &str, key: &str) -> snap::TeamRef {
        snap::TeamRef {
            id: TeamId::from(id),
            key: key.into(),
            name: format!("{key} team"),
        }
    }

    fn snapshot(destination: snap::Destination, screen: snap::Screen) -> ViewSnapshot {
        ViewSnapshot {
            version: snap::VERSION,
            workspace: PathBuf::from("/repo"),
            cwd: PathBuf::from("/repo"),
            pid: 7,
            updated_at: "2026-09-25T00:00:00Z".into(),
            closed_at: None,
            herdr_pane: None,
            organization: None,
            team: Some(team_ref("t1", "ENG")),
            destination,
            screen,
            project: None,
            cycle: None,
            issue: None,
            search: None,
            group_by: snap::GroupBy::Status,
            lists: Vec::new(),
            rows: Vec::new(),
            rows_total: 0,
            selected_row: None,
        }
    }

    fn fresh_app() -> App {
        let mut app = App::new(&Config::default());
        app.outbox.requests.clear();
        app
    }

    fn requested(app: &App, want: impl Fn(&Request) -> bool) -> bool {
        app.outbox.requests.iter().any(want)
    }

    #[test]
    fn a_snapshot_round_trips_through_a_restore() {
        let mut before = fresh_app();
        before.handle_message(Message::Teams(vec![team("t1", "ENG"), team("t2", "WEB")]));
        before.activate(Nav::Team(1, TeamSection::Issues));
        before.handle_message(Message::Issues {
            team_id: TeamId::from("t2"),
            preset: Preset::Active,
            page: page(vec![issue("1"), issue("2"), issue("3")]),
        });
        before.set_group_by(GroupBy::None);
        before.set_selected_index(2);
        let saved = before.snapshot(&origin()).unwrap();
        assert_eq!(
            saved.destination,
            snap::Destination::Team {
                team: team_ref("t2", "WEB"),
                section: snap::Section::Issues
            }
        );
        assert_eq!(
            saved.selected().and_then(|r| r.identifier.as_deref()),
            Some("ENG-3")
        );

        // The sidebar has since been reordered: WEB comes first now.
        let mut after = fresh_app();
        after.restore(saved.clone());
        after.handle_message(Message::Teams(vec![team("t2", "WEB"), team("t1", "ENG")]));
        assert_eq!(after.nav.dest, Nav::Team(0, TeamSection::Issues));
        assert!(requested(
            &after,
            |r| matches!(r, Request::Issues { team_id, .. } if team_id == "t2")
        ));
        after.handle_message(Message::Issues {
            team_id: TeamId::from("t2"),
            preset: Preset::Active,
            page: page(vec![issue("1"), issue("2"), issue("3")]),
        });
        assert_eq!(after.selected_index(), 2);
        assert_eq!(after.view.group_by, GroupBy::None);
        assert!(after.snapshot(&origin()).unwrap().same_view(&saved));
    }

    #[test]
    fn a_view_is_found_by_id_after_the_views_reorder() {
        let mut app = fresh_app();
        app.restore(snapshot(
            snap::Destination::View {
                id: CustomViewId::from("v2"),
                name: "View v2".into(),
            },
            snap::Screen::IssueList,
        ));
        app.handle_message(Message::Teams(vec![team("t1", "ENG")]));
        // Nothing to open yet, and the team's list is not fetched meanwhile.
        assert!(!requested(&app, |r| matches!(r, Request::Issues { .. })));
        assert!(
            app.snapshot(&origin()).is_none(),
            "nothing is recorded mid-restore"
        );

        app.handle_message(Message::CustomViews(vec![
            view("v1"),
            view("v2"),
            view("v3"),
        ]));
        let Nav::View(index) = app.nav.dest else {
            panic!("expected a view, got {:?}", app.nav.dest);
        };
        assert_eq!(app.store.custom_views[index].id, "v2");
        assert!(requested(
            &app,
            |r| matches!(r, Request::ViewIssues { view_id, .. } if view_id == "v2")
        ));
    }

    #[test]
    fn a_deleted_view_falls_back_to_the_views_page() {
        let mut app = fresh_app();
        app.restore(snapshot(
            snap::Destination::View {
                id: CustomViewId::from("gone"),
                name: "Gone".into(),
            },
            snap::Screen::IssueList,
        ));
        app.handle_message(Message::Teams(vec![team("t1", "ENG")]));
        app.handle_message(Message::CustomViews(vec![view("v1")]));
        assert_eq!(app.nav.dest, Nav::Views);
        assert_eq!(app.nav.screen, Screen::ViewList);
    }

    #[test]
    fn a_deleted_team_falls_back_to_the_first_team() {
        let mut app = fresh_app();
        app.restore(snapshot(
            snap::Destination::Team {
                team: team_ref("gone", "OLD"),
                section: snap::Section::Cycles,
            },
            snap::Screen::CycleList,
        ));
        app.handle_message(Message::Teams(vec![team("t1", "ENG")]));
        assert_eq!(app.nav.dest, Nav::Team(0, TeamSection::Issues));
        assert!(requested(
            &app,
            |r| matches!(r, Request::Issues { team_id, .. } if team_id == "t1")
        ));
    }

    #[test]
    fn a_project_page_is_reopened_once_the_projects_arrive() {
        let mut saved = snapshot(
            snap::Destination::Team {
                team: team_ref("t1", "ENG"),
                section: snap::Section::Projects,
            },
            snap::Screen::IssueDetail,
        );
        saved.project = Some(snap::NamedRef {
            id: ProjectId::from("p2"),
            name: "Project p2".into(),
        });
        saved.issue = Some(snap::IssueRef {
            id: IssueId::from("9"),
            identifier: "ENG-9".into(),
            title: "Issue 9".into(),
        });
        let mut app = fresh_app();
        app.restore(saved);
        app.handle_message(Message::Teams(vec![team("t1", "ENG")]));
        assert_eq!(app.nav.screen, Screen::ProjectList);

        app.handle_message(Message::Projects {
            team_id: TeamId::from("t1"),
            page: page(vec![project("p1"), project("p2")]),
        });
        assert_eq!(app.nav.screen, Screen::IssueDetail);
        assert_eq!(app.nav.detail_return, Screen::ProjectDetail);
        assert_eq!(app.nav.current_project.as_ref().unwrap().id, "p2");
        assert_eq!(
            app.store.current_issue.as_ref().unwrap().identifier,
            "ENG-9"
        );

        // Back navigation retraces the path.
        app.close_detail();
        assert_eq!(app.nav.screen, Screen::ProjectDetail);
        app.leave_container();
        assert_eq!(app.nav.screen, Screen::ProjectList);
    }

    #[test]
    fn a_deleted_project_leaves_its_list_open() {
        let mut saved = snapshot(
            snap::Destination::Team {
                team: team_ref("t1", "ENG"),
                section: snap::Section::Projects,
            },
            snap::Screen::ProjectDetail,
        );
        saved.project = Some(snap::NamedRef {
            id: ProjectId::from("gone"),
            name: "Gone".into(),
        });
        let mut app = fresh_app();
        app.restore(saved);
        app.handle_message(Message::Teams(vec![team("t1", "ENG")]));
        app.handle_message(Message::Projects {
            team_id: TeamId::from("t1"),
            page: page(vec![project("p1")]),
        });
        assert_eq!(app.nav.screen, Screen::ProjectList);
        assert!(app.restore.is_none());
    }

    #[test]
    fn a_deleted_issue_returns_to_the_list_it_was_opened_from() {
        let mut saved = snapshot(
            snap::Destination::Team {
                team: team_ref("t1", "ENG"),
                section: snap::Section::Issues,
            },
            snap::Screen::IssueDetail,
        );
        saved.issue = Some(snap::IssueRef {
            id: IssueId::from("9"),
            identifier: "ENG-9".into(),
            title: "Issue 9".into(),
        });
        let mut app = fresh_app();
        app.restore(saved);
        app.handle_message(Message::Teams(vec![team("t1", "ENG")]));
        assert_eq!(app.nav.screen, Screen::IssueDetail);

        app.handle_message(Message::Failed {
            request: Box::new(Request::IssueDetail {
                issue_id: IssueId::from("9"),
            }),
            error: "Entity not found".into(),
        });
        assert_eq!(app.nav.screen, Screen::IssueList);
        assert!(
            app.view.error_popup.is_none(),
            "a vanished issue is not an error"
        );
        assert_eq!(
            app.view.status_message.as_deref(),
            Some("ENG-9 is not available")
        );
    }

    #[test]
    fn a_key_press_before_the_page_is_found_opens_the_team_list() {
        let mut app = fresh_app();
        app.restore(snapshot(
            snap::Destination::View {
                id: CustomViewId::from("v1"),
                name: "View v1".into(),
            },
            snap::Screen::IssueList,
        ));
        app.handle_message(Message::Teams(vec![team("t1", "ENG")]));
        app.cancel_restore();
        assert!(requested(&app, |r| matches!(r, Request::Issues { .. })));
        // The views arriving later no longer yank the user away.
        app.handle_message(Message::CustomViews(vec![view("v1")]));
        assert_eq!(app.nav.dest, Nav::Team(0, TeamSection::Issues));
    }

    #[test]
    fn list_settings_take_effect_before_the_first_fetch() {
        let mut saved = snapshot(
            snap::Destination::Team {
                team: team_ref("t1", "ENG"),
                section: snap::Section::Issues,
            },
            snap::Screen::IssueList,
        );
        saved.lists.push(snap::ListSettings {
            source: snap::Source::Team,
            preset: snap::Preset::Backlog,
            status: None,
            priority: Some("High".into()),
            selected: None,
        });
        let mut app = fresh_app();
        app.restore(saved);
        app.handle_message(Message::Teams(vec![team("t1", "ENG")]));
        assert!(requested(&app, |r| matches!(
            r,
            Request::Issues {
                preset: Preset::Backlog,
                ..
            }
        )));
        assert_eq!(app.list().filters.priority, Some(Priority::High));
    }

    #[test]
    fn an_issue_opened_by_identifier_takes_its_real_id_when_it_arrives() {
        let mut app = fresh_app();
        app.open_on_launch("ENG-9");
        app.handle_message(Message::Teams(vec![team("t1", "ENG")]));
        assert_eq!(app.nav.screen, Screen::IssueDetail);
        assert_eq!(app.nav.detail_return, Screen::IssueList);
        assert!(requested(&app, |r| matches!(
            r,
            Request::IssueDetail { issue_id } if issue_id == "ENG-9"
        )));
        assert!(requested(&app, |r| matches!(r, Request::Issues { .. })));

        let mut fresh = issue("9");
        fresh.id = IssueId::from("uuid-9");
        app.handle_message(Message::IssueDetail(Box::new(fresh)));
        assert_eq!(app.store.current_issue.as_ref().unwrap().id, "uuid-9");
        assert!(app.restore.is_none());
    }
}