team-ljyzipelo

공개
408줄15 KB
1#![cfg(debug_assertions)]
2
3use eframe::egui;
4use std::{collections::BTreeSet, ffi::OsString};
5use zipelo_ui_memory_app::archive_screen::scenarios::{self, Launch, SCENARIOS};
6
7#[test]
8fn every_name_round_trips_and_listing_has_no_duplicates() {
9 let names: BTreeSet<_> = SCENARIOS.iter().map(|s| s.name).collect();
10 assert_eq!(names.len(), SCENARIOS.len());
11 for scenario in SCENARIOS {
12 assert_eq!(scenarios::parse(scenario.name), Ok(*scenario));
13 assert!(scenarios::listing().contains(scenario.description));
14 assert!(
15 include_str!("../../docs/ui-scenario-guide.md")
16 .contains(&format!("- {}:", scenario.name))
17 );
18 assert_eq!(
19 scenarios::launch(vec!["--ui-scenario".into(), scenario.name.into()]),
20 Ok(Launch::Scenario(*scenario)),
21 );
22 }
23 assert_eq!(
24 scenarios::launch(vec!["--list-ui-scenarios".into()]),
25 Ok(Launch::List)
26 );
27}
28
29#[test]
30fn unknown_missing_and_conflicting_arguments_are_rejected_with_catalog() {
31 for args in [
32 vec!["--ui-scenario", "missing"],
33 vec!["--ui-scenario"],
34 vec!["--ui-scenario", "archive", "file.zip"],
35 vec!["--list-ui-scenarios", "file.zip"],
36 vec!["--ui-fixture", "--ui-scenario", "archive"],
37 ] {
38 let error = scenarios::launch(args.into_iter().map(OsString::from).collect()).unwrap_err();
39 for scenario in SCENARIOS {
40 assert!(error.contains(scenario.name));
41 }
42 }
43 let original = vec![OsString::from("압축 자료.zip")];
44 assert_eq!(
45 scenarios::launch(original.clone()),
46 Ok(Launch::Normal(original))
47 );
48}
49
50fn text(shapes: &[egui::epaint::ClippedShape]) -> String {
51 fn collect(shape: &egui::Shape, result: &mut String) {
52 match shape {
53 egui::Shape::Text(t) => {
54 result.push_str(t.galley.text());
55 result.push('\n');
56 }
57 egui::Shape::Vec(shapes) => {
58 for shape in shapes {
59 collect(shape, result);
60 }
61 }
62 _ => {}
63 }
64 }
65 let mut result = String::new();
66 for shape in shapes {
67 collect(&shape.shape, &mut result);
68 }
69 result
70}
71
72#[test]
73fn every_listed_scenario_draws_and_keeps_its_expected_screen() {
74 for scenario in SCENARIOS {
75 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
76 let ctx = egui::Context::default();
77 let mut app = scenario.build();
78 let mut labels = String::new();
79 for _ in 0..3 {
80 let mut output = ctx.run_ui(
81 egui::RawInput {
82 screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)),
83 ..Default::default()
84 },
85 |ui| app.show(ui),
86 );
87 assert!(!output.shapes.is_empty(), "{}", scenario.name);
88 labels = text(&output.shapes);
89 output.textures_delta.clear();
90 }
91 assert!(
92 app.model.error.is_none(),
93 "{}: {:?}",
94 scenario.name,
95 app.model.error
96 );
97 assert!(app.model.input_error.is_none(), "{}", scenario.name);
98 let expected = match scenario.name {
99 "resource-approval" => "큰 작업을 허용할까요?",
100 "resource-ratio" => "압축률이 매우 높습니다",
101 "resource-retry" => "한도를 늘려 다시 시도",
102 "resource-partial" => "저장 위치를 확인하세요",
103 "conflict-choice" | "conflict-apply" | "gzip-conflict-choice" => {
104 "나머지 파일에도 같게 적용"
105 }
106 "extract-skipped" => "모든 파일을 건너뛰었습니다",
107 "extract-rename-failed" => "아무 파일도 풀지 않았습니다",
108 "extract-renamed" => "이름 바꿔 저장: 읽어주세요 (1).txt",
109 "empty" => "TAR.BZ2, TAR.XZ",
110 "tar-bz2" | "tar-xz" => "읽어주세요.txt",
111 "folder-empty" => "이 폴더는 비어 있습니다",
112 "dialog-error" => "파일 선택 창을 열 수 없습니다",
113 "extract-partial" => "일부 파일만 풀렸습니다",
114 "extract-uncertain" => "저장이 끝났는지 확인하지 못했습니다",
115 "extract-unsynced" => "파일을 디스크에 완전히 저장했는지 확인하지 못했습니다",
116 "source-changed" => "압축파일 다시 열기",
117 "gzip-conflict" => "다른 이름으로 저장",
118 "create-error" => "ZIP 파일을 만들지 못했습니다",
119 "password-create" => "암호 확인",
120 "folder" => "바다.jpg",
121 "search-empty" => "일치하는 항목이 없습니다",
122 "password" | "password-retry" => "암호",
123 "extract-complete" => "압축을 풀었습니다",
124 "extract-cancelled" => "작업을 취소했습니다",
125 "create-complete" => "ZIP 파일을 만들었습니다",
126 "create" | "create-encrypted" => "암호로 보호하기",
127 "unsupported" | "damaged" => "압축파일을 열지 못했습니다",
128 "conflict" => "압축을 풀지 못했습니다",
129 "close-confirm" => "닫",
130 _ => "읽어주세요.txt",
131 };
132 assert!(labels.contains(expected), "{}: {labels}", scenario.name);
133 if scenario.name == "extract-rename-failed" {
134 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
135 assert!(!labels.contains("이름 바꿔 저장:"), "{labels}");
136 }
137 if matches!(scenario.name, "tar-bz2" | "tar-xz") {
138 assert!(app.model.entries.iter().all(|entry| !entry.encrypted));
139 assert_eq!(
140 app.model.list_id.as_ref().unwrap().format,
141 zipelo_ui_memory_app::archive_ui::Format::Tar
142 );
143 }
144 if scenario.name == "many-items" {
145 assert_eq!(app.model.entries.len(), 505);
146 }
147 if matches!(scenario.name, "selection" | "marquee") {
148 assert_eq!(app.model.selected.len(), 4);
149 assert!(labels.contains("선택 2개"));
150 }
151 if scenario.name == "password-retry" {
152 assert_eq!(app.model.challenge.unwrap().1, 2);
153 }
154 }
155 }
156}
157
158#[test]
159fn command_line_catalog_and_errors_work_without_a_display() {
160 let run = |args: &[&str]| {
161 std::process::Command::new(env!("CARGO_BIN_EXE_zipelo-ui-memory-app"))
162 .args(args)
163 .env_remove("DISPLAY")
164 .env_remove("WAYLAND_DISPLAY")
165 .output()
166 .unwrap()
167 };
168 let listed = run(&["--list-ui-scenarios"]);
169 assert!(listed.status.success());
170 assert_eq!(
171 String::from_utf8(listed.stdout).unwrap(),
172 scenarios::listing()
173 );
174 for args in [vec!["--ui-scenario", "unknown"], vec!["--ui-scenario"]] {
175 let failed = run(&args);
176 assert!(!failed.status.success());
177 let stderr = String::from_utf8_lossy(&failed.stderr);
178 for scenario in SCENARIOS {
179 assert!(stderr.contains(scenario.name));
180 }
181 }
182}
183
184#[test]
185fn preview_ignores_password_submission() {
186 let ctx = egui::Context::default();
187 let mut preview = scenarios::Preview::new(scenarios::parse("password").unwrap().build(), &ctx);
188 for _ in 0..3 {
189 let mut output = ctx.run_ui(
190 egui::RawInput {
191 screen_rect: Some(egui::Rect::from_min_size(
192 egui::Pos2::ZERO,
193 egui::vec2(1060.0, 720.0),
194 )),
195 events: vec![
196 egui::Event::Text("화면 검토".into()),
197 egui::Event::Key {
198 key: egui::Key::Enter,
199 physical_key: None,
200 pressed: true,
201 repeat: false,
202 modifiers: egui::Modifiers::NONE,
203 },
204 ],
205 ..Default::default()
206 },
207 |ui| preview.0.show(ui),
208 );
209 output.textures_delta.clear();
210 }
211 assert_eq!(preview.0.model.challenge, Some((17, 1, false)));
212 assert!(preview.0.model.busy());
213}
214
215fn result_labels(
216 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
217 size: egui::Vec2,
218) -> String {
219 let ctx = egui::Context::default();
220 let mut labels = String::new();
221 for _ in 0..3 {
222 let mut output = ctx.run_ui(
223 egui::RawInput {
224 screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)),
225 ..Default::default()
226 },
227 |ui| app.show(ui),
228 );
229 labels = text(&output.shapes);
230 output.textures_delta.clear();
231 }
232 labels
233}
234
235#[test]
236fn rename_without_created_output_never_claims_saved_name() {
237 use zipelo_ui_memory_app::archive_ui::*;
238 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
239 for disposition in [
240 None,
241 Some(Disposition::PartialRetained),
242 Some(Disposition::Removed),
243 Some(Disposition::CommitUncertain),
244 ] {
245 let mut app = scenarios::parse("extract-renamed").unwrap().build();
246 app.model.outputs = disposition
247 .into_iter()
248 .map(|d| ("읽어주세요 (1).txt".into(), d))
249 .collect();
250 app.model.terminal = Some(Terminal {
251 outcome: Outcome::Failed,
252 error: Some(ErrorCode::Io),
253 publication: if disposition.is_none() {
254 Publication::None
255 } else {
256 Publication::Uncertain
257 },
258 created_count: 0,
259 retained_partial_count: 0,
260 durability: Durability::NotApplicable,
261 cleanup: Cleanup::Complete,
262 });
263 let labels = result_labels(&mut app, size);
264 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
265 if disposition.is_none() {
266 assert!(labels.contains("아무 파일도 풀지 않았습니다"), "{labels}");
267 }
268 assert!(
269 !labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
270 "{labels}"
271 );
272 }
273 }
274}
275
276#[test]
277fn rename_saved_before_later_failure_remains_reported() {
278 use zipelo_ui_memory_app::archive_ui::*;
279 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
280 let mut app = scenarios::parse("extract-renamed").unwrap().build();
281 app.model.resolutions.push(Resolution {
282 entry_id: 2,
283 relative_name: "여행 일정 (1).pdf".into(),
284 choice: ConflictChoice::Rename,
285 });
286 app.model.terminal.as_mut().unwrap().outcome = Outcome::Failed;
287 app.model.terminal.as_mut().unwrap().error = Some(ErrorCode::Io);
288 app.model.terminal.as_mut().unwrap().publication = Publication::Partial;
289 let labels = result_labels(&mut app, size);
290 assert!(
291 labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
292 "{labels}"
293 );
294 assert!(
295 !labels.contains("이름 바꿔 저장: 여행 일정 (1).pdf"),
296 "{labels}"
297 );
298 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
299 }
300}
301
302fn resource_frame(
303 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
304 ctx: &egui::Context,
305 events: Vec<egui::Event>,
306) -> Vec<egui::epaint::ClippedShape> {
307 let mut out = ctx.run_ui(
308 egui::RawInput {
309 screen_rect: Some(egui::Rect::from_min_size(
310 egui::Pos2::ZERO,
311 egui::vec2(760.0, 540.0),
312 )),
313 events,
314 ..Default::default()
315 },
316 |ui| app.show(ui),
317 );
318 out.textures_delta.clear();
319 out.shapes
320}
321fn find_resource_action(shapes: &[egui::epaint::ClippedShape], label: &str) -> egui::Pos2 {
322 fn find(s: &egui::Shape, label: &str) -> Option<egui::Pos2> {
323 match s {
324 egui::Shape::Text(t) if t.galley.text() == label => {
325 Some(t.pos + t.galley.rect.size() / 2.0)
326 }
327 egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, label)),
328 _ => None,
329 }
330 }
331 shapes.iter().find_map(|s| find(&s.shape, label)).unwrap()
332}
333#[test]
334fn resource_dialog_requires_explicit_click_and_escape_cancels() {
335 for allow in [false, true] {
336 let ctx = egui::Context::default();
337 let mut app = scenarios::parse("resource-ratio").unwrap().build();
338 let mut shapes = Vec::new();
339 for _ in 0..3 {
340 shapes = resource_frame(&mut app, &ctx, vec![]);
341 }
342 assert!(text(&shapes).contains("미확인"));
343 resource_frame(
344 &mut app,
345 &ctx,
346 vec![egui::Event::Key {
347 key: egui::Key::Enter,
348 physical_key: None,
349 pressed: true,
350 repeat: false,
351 modifiers: Default::default(),
352 }],
353 );
354 assert!(app.model.resource.is_some());
355 if allow {
356 let point = find_resource_action(&shapes, "이 작업 허용");
357 resource_frame(
358 &mut app,
359 &ctx,
360 vec![
361 egui::Event::PointerMoved(point),
362 egui::Event::PointerButton {
363 pos: point,
364 button: egui::PointerButton::Primary,
365 pressed: true,
366 modifiers: Default::default(),
367 },
368 ],
369 );
370 resource_frame(
371 &mut app,
372 &ctx,
373 vec![egui::Event::PointerButton {
374 pos: point,
375 button: egui::PointerButton::Primary,
376 pressed: false,
377 modifiers: Default::default(),
378 }],
379 );
380 assert!(!app.model.cancellation_requested());
381 } else {
382 resource_frame(
383 &mut app,
384 &ctx,
385 vec![egui::Event::Key {
386 key: egui::Key::Escape,
387 physical_key: None,
388 pressed: true,
389 repeat: false,
390 modifiers: Default::default(),
391 }],
392 );
393 assert!(app.model.cancellation_requested());
394 }
395 assert!(app.model.resource.is_none());
396 }
397}
398#[test]
399fn partial_limit_result_never_offers_expanded_retry() {
400 let ctx = egui::Context::default();
401 let mut app = scenarios::parse("resource-partial").unwrap().build();
402 let mut shapes = Vec::new();
403 for _ in 0..3 {
404 shapes = resource_frame(&mut app, &ctx, vec![]);
405 }
406 assert!(!text(&shapes).contains("한도를 늘려 다시 시도"));
407 assert!(text(&shapes).contains("풀린 자료"));
408}