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
//! A consistency guard over the app's dialogs.
//!
//! Every dialog is painted headlessly and every piece of text it draws is
//! collected with the size it was drawn at. The app has exactly two text
//! sizes — body for content and heading for a window's title — and a dialog
//! that reaches for a third (a `.small()` annotation, a title left at body
//! size) reads as belonging to a different program. That is easy to do by
//! accident and impossible to see in a diff, so it is asserted here instead.
#[cfg(test)]
mod tests {
use crate::gui::app::{Dialog, GuiApp, PromptKind, RenameTarget};
use crate::session::Session;
use eframe::egui;
/// The only two sizes any dialog may paint text at.
const BODY: f32 = 13.0;
const HEADING: f32 = 18.0;
/// Every run of text one frame painted, with the size it was set in.
fn painted(app: &mut GuiApp) -> Vec<(String, f32)> {
fn walk(s: &egui::epaint::Shape, out: &mut Vec<(String, f32)>) {
match s {
egui::epaint::Shape::Text(t) => {
let text = t.galley.text().to_string();
if text.trim().is_empty() {
return;
}
for sec in &t.galley.job.sections {
out.push((text.clone(), sec.format.font_id.size));
}
}
egui::epaint::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),
_ => {}
}
}
let ctx = egui::Context::default();
app.theme.apply(&ctx);
let input = || egui::RawInput {
screen_rect: Some(egui::Rect::from_min_size(
egui::pos2(0.0, 0.0),
egui::vec2(1200.0, 800.0),
)),
..Default::default()
};
// Three frames: a modal's layer is laid out on the frame after the one
// that asks for it, and a window is only sized once it has been seen.
let mut last = Vec::new();
for _ in 0..3 {
let out = ctx.run_ui(input(), |ui| {
let ctx = ui.ctx().clone();
crate::gui::menu::show_dialog(app, &ctx);
crate::gui::postman::show(app, &ctx);
crate::gui::remote::show(app, &ctx);
if app.report_editor.is_some() {
crate::gui::report_editor::ui(app, ui);
}
});
last.clear();
out.shapes.iter().for_each(|s| walk(&s.shape, &mut last));
}
last
}
/// Regression guard: a dialog that paints text at any other size — the
/// `.small()` annotations the parameter cards used to carry, or a modal
/// that drew its own title at body size — is a dialog that no longer looks
/// like the rest of the app.
#[test]
fn every_dialog_paints_at_the_apps_two_text_sizes() {
let cases: Vec<(&str, Box<dyn Fn(&mut GuiApp)>)> = vec![
(
"Rename",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::Rename {
target: RenameTarget::Tab { ci: 0 },
text: "My collection".into(),
})
}),
),
(
"Prompt/BaseUrl",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::Prompt {
kind: PromptKind::BaseUrl,
text: "https://example.test".into(),
})
}),
),
(
"Prompt/NewEnvName",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::Prompt {
kind: PromptKind::NewEnvName,
text: String::new(),
})
}),
),
(
"UnsavedQuit",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::UnsavedQuit {
count: 3,
tabs: "Alpha, Beta".into(),
})
}),
),
(
"UnsavedCloseTab",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::UnsavedCloseTab {
ci: 0,
name: "Alpha".into(),
count: 2,
})
}),
),
(
"ExportResults",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::ExportResults {
path: "/home/me/report.csv".into(),
})
}),
),
(
"CloseGitWorkspace",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::CloseGitWorkspace {
ci: 0,
root: "/tmp/pb/ws".into(),
})
}),
),
(
"RevertToSaved",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::RevertToSaved {
ci: 0,
path: "/tmp/pb/alpha.hurl".into(),
entry: None,
name: "Alpha".into(),
})
}),
),
(
"ConfirmDeleteRequest",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::ConfirmDeleteRequest {
ci: 0,
idx: 0,
name: "Login".into(),
})
}),
),
(
"ConfirmRunAll",
Box::new(|a: &mut GuiApp| {
a.dialog = Some(Dialog::ConfirmRunAll {
ci: 0,
total: 8,
non_get: 3,
})
}),
),
(
"Shortcuts",
Box::new(|a: &mut GuiApp| a.dialog = Some(Dialog::Shortcuts)),
),
(
"Theme",
Box::new(|a: &mut GuiApp| {
let spec = a.session.active_theme_spec();
a.dialog = Some(Dialog::Theme(Box::new(crate::gui::menu::ThemeEditState {
original_name: spec.name.clone(),
spec,
})));
}),
),
(
"Report/RunSettings",
Box::new(|a: &mut GuiApp| {
const TRAIL: &str = "\
# name: Face
# collection: c.hurl
PARAM TEXT TICKET LABEL \"Ticket number\"
PARAM CHOICE(\"au\", \"eu\") REGION = \"au\"
PARAM FILE SAMPLES
REPORT REQUEST x
";
a.open_report_editor(
crate::gui::report_editor::ReportOrigin::Workspace,
crate::report::Report::from_text("Face", TRAIL),
);
let ed = a.report_editor.as_mut().unwrap();
crate::gui::report_editor::arm_params_for_audit(ed);
}),
),
(
"Report/NodeWizard",
Box::new(|a: &mut GuiApp| {
const TRAIL: &str = "\
# name: Face
# collection: c.hurl
REPORT REQUEST x
";
a.open_report_editor(
crate::gui::report_editor::ReportOrigin::Workspace,
crate::report::Report::from_text("Face", TRAIL),
);
let mut ed = a.report_editor.take().unwrap();
crate::gui::report_wizard::open(&mut ed, a, &[0]);
a.report_editor = Some(ed);
}),
),
(
"Git/LoadCollection",
Box::new(|a: &mut GuiApp| a.remote.open_load()),
),
(
"Git/SaveReport",
Box::new(|a: &mut GuiApp| a.remote.open_save_report()),
),
(
"Postman/Options",
Box::new(|a: &mut GuiApp| {
a.postman.open();
a.postman
.seed_step_for_audit(crate::postman_flow::Step::Options);
}),
),
(
"Postman/Confirm",
Box::new(|a: &mut GuiApp| {
a.postman.open();
a.postman
.seed_step_for_audit(crate::postman_flow::Step::Confirm);
}),
),
(
"Postman/Downloading",
Box::new(|a: &mut GuiApp| {
a.postman.open();
a.postman
.seed_step_for_audit(crate::postman_flow::Step::Downloading);
}),
),
(
"Postman/Done",
Box::new(|a: &mut GuiApp| {
a.postman.open();
a.postman
.seed_step_for_audit(crate::postman_flow::Step::Done);
}),
),
(
"Postman/Connect",
Box::new(|a: &mut GuiApp| {
a.postman.open();
}),
),
];
for (name, setup) in cases {
let mut app = GuiApp::for_test(Session::default());
setup(&mut app);
for (text, size) in painted(&mut app) {
assert!(
size == BODY || size == HEADING,
"{name} paints {text:?} at {size}, which is neither the \
body size ({BODY}) nor a title ({HEADING})"
);
}
}
}
}