1
mod account_balances;
2
mod account_balances_future;
3
mod account_edit;
4
mod accounts_order;
5
mod arrange;
6
mod bulk_delete;
7
mod clipped;
8
mod close;
9
mod commodity_edit;
10
mod commodity_fill;
11
mod config_list;
12
mod console_eval;
13
mod console_streams;
14
mod convert;
15
mod corner_drag;
16
mod create;
17
mod cross_talk;
18
mod delete;
19
mod deliver;
20
mod desktop;
21
mod detail_refresh;
22
mod dialog_move;
23
mod dialog_origin;
24
mod dialog_title_drag;
25
mod discard;
26
mod edit;
27
mod edit_uuid;
28
mod empty_start;
29
mod filter_builder;
30
mod filter_builder_cells;
31
mod filter_builder_rows;
32
mod help_keys;
33
mod help_window;
34
mod hold;
35
mod instances;
36
mod kitty_clipped;
37
mod late_openers;
38
mod lossless;
39
mod merge;
40
mod merge_preview;
41
mod mutation_refresh;
42
mod new_row;
43
mod notice;
44
mod open;
45
mod options;
46
mod options_db;
47
mod options_overrides;
48
mod options_save;
49
mod origin;
50
pub(crate) mod overlap;
51
mod page_edge;
52
mod paging;
53
mod palette_args;
54
mod palette_leaves;
55
mod pending_place;
56
mod report;
57
mod report_args;
58
mod report_chart;
59
mod report_chart_override;
60
mod report_chart_refetch;
61
mod report_csv;
62
mod report_enter;
63
mod report_enter_server;
64
mod report_rerun;
65
mod request_ids;
66
mod resize;
67
mod script_bytecode;
68
mod script_forms;
69
mod scripts;
70
mod size_move;
71
mod ssh_keys;
72
mod ssh_keys_palette;
73
mod status;
74
mod tag_hints;
75
mod tags;
76
mod template_forms;
77
mod template_pick;
78
mod template_test;
79
mod templates;
80
mod text_area;
81
mod title_drag;
82
mod transaction;
83
mod transaction_detail;
84
mod transaction_filter;
85
mod transaction_list;
86
mod ui_config;
87
mod ui_keymap;
88
mod viewer;
89
mod window_clicks;
90
mod window_keys;
91
mod window_list;
92
mod window_seqs;
93
mod windows;
94

            
95
use super::*;
96
use crate::route::{Route, RouteCtx};
97
use crate::tabs::fetch::Fetch;
98
use crate::tabs::nms::ConsoleState;
99
use crate::tabs::nms_eval::ConsoleEval;
100
use crate::tabs::nms_eval::double::Sent;
101
use crate::view::{Tab, ViewId};
102
use crate::window::{View, WindowId};
103
use cli_core::render::ListRow;
104

            
105
impl App {
106
    /// Opens a window of every view, so that each number is its view's digit, and raises
107
    /// Accounts; Next from there reaches Transactions first.
108
2029
    pub(crate) fn open_every_view(&mut self) {
109
2029
        for kind in ViewId::ALL {
110
20290
            self.open_new_window(super::windows::new_view(kind));
111
        }
112
2029
        if let Some(accounts) = self.window_id(ViewId::Accounts) {
113
2029
            self.raise_window(accounts);
114
        }
115
2029
    }
116

            
117
    /// The id of the most recent window of `kind`; the test fails when there is none.
118
603
    pub(crate) fn window_of(&self, kind: ViewId) -> WindowId {
119
603
        match self.window_id(kind) {
120
603
            Some(id) => id,
121
            None => panic!("no {kind:?} window"),
122
        }
123
603
    }
124

            
125
    /// The window with TV number `number`; the test fails when there is none.
126
1
    pub(crate) fn window_of_number(&self, number: u8) -> WindowId {
127
7
        match self.windows.iter().find(|win| win.number == Some(number)) {
128
1
            Some(win) => win.id,
129
            None => panic!("no window {number}"),
130
        }
131
1
    }
132

            
133
    /// How many windows of `kind` are open.
134
51
    pub(crate) fn windows_of(&self, kind: ViewId) -> usize {
135
51
        self.window_ids(kind).len()
136
51
    }
137

            
138
    /// Opens another window of `kind` in front and returns it.
139
140
    pub(crate) fn open_extra(&mut self, kind: ViewId) -> WindowId {
140
140
        self.open_new_window(super::windows::new_view(kind))
141
140
    }
142

            
143
    /// Toggles the zoom of the most recent window of `kind`.
144
18
    pub(crate) fn toggle_zoom_of(&mut self, kind: ViewId) {
145
18
        let id = self.window_of(kind);
146
18
        self.desktop.toggle_zoom(id);
147
18
    }
148

            
149
    /// Brings the console to the front and gives its prompt the keyboard.
150
46
    pub(crate) fn focus_console(&mut self) {
151
46
        self.switch_tab(ViewId::Console);
152
46
        self.set_console_focused(true);
153
46
    }
154

            
155
    /// The script routes awaiting a reply.
156
3
    pub(crate) fn script_routes(&self) -> Vec<&crate::route::ScriptRoute> {
157
3
        self.pending_routes
158
3
            .values()
159
3
            .filter_map(|route| match &route.ctx {
160
3
                RouteCtx::Script(script) => Some(script),
161
                _ => None,
162
3
            })
163
            .collect()
164
3
    }
165

            
166
    /// Attaches a recording console, without the config read `attach_console` starts.
167
535
    pub(crate) fn attach_echo(&mut self) -> Sent {
168
535
        let (eval, sent) = ConsoleEval::recording();
169
535
        self.console_eval = Some(eval);
170
535
        sent
171
535
    }
172

            
173
    /// Swaps in a console whose request ids ran out and whose replies are closed.
174
2
    pub(crate) fn break_console(&mut self) {
175
2
        self.console_eval = Some(ConsoleEval::broken());
176
2
    }
177

            
178
    /// Drains a real console until its UI config read is answered; false when it never is.
179
7
    pub(crate) async fn await_ui_config_read(&mut self) -> bool {
180
7
        for _ in 0..500 {
181
45
            self.drain_eval();
182
45
            let pending = self
183
45
                .pending_routes
184
45
                .values()
185
38
                .any(|route| matches!(route.ctx, RouteCtx::UiConfig { .. }));
186
45
            if !pending {
187
7
                return true;
188
38
            }
189
38
            tokio::time::sleep(std::time::Duration::from_millis(20)).await;
190
        }
191
        false
192
7
    }
193
}
194

            
195
#[test]
196
1
fn all_has_ten_tabs_console_ninth_scripts_last() {
197
1
    assert_eq!(Tab::ALL.len(), 10);
198
1
    assert_eq!(Tab::ALL[8], Tab::Console);
199
1
    assert_eq!(Tab::ALL[9], Tab::Scripts);
200
1
}
201

            
202
#[test]
203
1
fn console_label_is_console() {
204
1
    assert_eq!(Tab::Console.label(), "Console");
205
1
}
206

            
207
#[tokio::test]
208
1
async fn attaching_the_console_opens_no_window() {
209
1
    let mut app = crate::test_support::empty_app();
210
1
    app.attach_console(ConsoleEval::recording().0);
211
1
    assert_eq!(app.front_kind(), None);
212
1
}
213

            
214
#[test]
215
1
fn switch_tab_sets_target() {
216
1
    let mut app = crate::test_support::app();
217
1
    app.switch_tab(Tab::Reports);
218
1
    assert_eq!(app.front_kind(), Some(Tab::Reports));
219
1
}
220

            
221
#[test]
222
1
fn open_and_close_command_line() {
223
1
    let mut app = crate::test_support::app();
224
1
    assert!(!app.cmdline.active);
225
1
    app.open_command_line();
226
1
    assert!(app.cmdline.active);
227
1
    app.close_command_line();
228
1
    assert!(!app.cmdline.active);
229
1
}
230

            
231
#[test]
232
1
fn request_quit_sets_flag() {
233
1
    let mut app = crate::test_support::app();
234
1
    assert!(!app.should_quit);
235
1
    app.request_quit();
236
1
    assert!(app.should_quit);
237
1
}