team-ljyzipelo

공개
798줄32 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| scenario.show(&mut app, 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 if scenario.name.starts_with("recovery-") {
99 let expected = match scenario.name {
100 "recovery-complete" => "복구본 저장 완료",
101 "recovery-partial" => "일부 항목만 복구함",
102 "recovery-unknown" => "전체 목록을 알 수 없어",
103 "recovery-impossible" => "복구 가능한 항목 없음",
104 "recovery-save-error" | "recovery-retained" => {
105 "복구본 저장을 완료하지 못했습니다"
106 }
107 "recovery-cancelled" => "복구를 취소했습니다",
108 "recovery-resource" => "이 작업 허용",
109 _ => "ZIP 복구 중",
110 };
111 assert!(labels.contains(expected), "{}: {labels}", scenario.name);
112 assert_eq!(
113 labels.contains("복구본 열기"),
114 matches!(
115 scenario.name,
116 "recovery-complete" | "recovery-partial" | "recovery-unknown"
117 )
118 );
119 assert!(!labels.contains("100%"));
120 if scenario.name == "recovery-retained" {
121 assert!(labels.contains("남은 임시 파일:"), "{labels}");
122 assert!(labels.contains(".zipelo-42-1.tmp"), "{labels}");
123 assert!(app.model.confirmed);
124 assert!(!app.model.can_retry_expanded());
125 }
126 }
127 if scenario.name == "split-archive" {
128 assert!(app.model.list_id.as_ref().unwrap().is_split());
129 assert!(!app.model.can_preview());
130 }
131 if matches!(scenario.name, "archive-loading" | "archive-loading-in-parent") {
132 assert!(app.model.busy());
133 assert!(app.model.list_id.is_none());
134 assert!(app.model.entries.is_empty());
135 assert!(!labels.contains("이 폴더는 비어 있습니다"), "{labels}");
136 }
137
138 let expected = match scenario.name {
139 "archive-loading" | "archive-loading-in-parent" => "압축파일을 읽는 중",
140 "split-archive" => "읽어주세요.txt",
141 "split-first-volume" => "첫 조각 여행.7z.001을 선택해 다시 여세요.",
142 "split-missing-volume" => "여행.7z.003 조각이 없습니다",
143 "split-incomplete" => "분할 묶음이 불완전하거나 손상됐습니다",
144 "split-unsupported" => "분할 ZIP과 RAR",
145 "split-source-changed" => "원본 파일이 바뀌었습니다",
146 "preview-implicit-folder" => "자료",
147 "preview-catalog-approval" | "preview-catalog-bytes-approval" => {
148 "큰 작업을 허용할까요?"
149 }
150 "preview-loading" => "미리보기를 불러오는 중입니다",
151 "preview-text" => "여행 준비 목록",
152 "preview-image" => "미리보기",
153 "preview-empty" => "빈 텍스트 파일입니다",
154 "preview-limit" => "미리보기 크기 또는 처리 한도를 초과했습니다",
155 "preview-damaged" => "파일이 손상됐거나 UTF-8 텍스트가 아닙니다",
156 "preview-unsupported" => "이 파일 형식은 미리보기를 지원하지 않습니다",
157 "resource-approval" => "큰 작업을 허용할까요?",
158 "resource-ratio" => "압축률이 매우 높습니다",
159 "resource-retry" => "한도를 늘려 다시 시도",
160 "resource-partial" => "저장 위치를 확인하세요",
161 "uninstall-windows" => "제거 전에 다른 앱을 선택하세요",
162 "uninstall-settings-error" => "Windows 설정을 열지 못했습니다",
163 "uninstall-ubuntu-missing" => "이전 앱을 복원할 수 없습니다",
164 "uninstall-ubuntu-unknown-user" => "사용자 기본 앱 설정은 변경하지 않습니다",
165 "conflict-choice" | "conflict-apply" | "gzip-conflict-choice" => {
166 "나머지 파일에도 같게 적용"
167 }
168 "extract-skipped" => "모든 파일을 건너뛰었습니다",
169 "extract-rename-failed" => "아무 파일도 풀지 않았습니다",
170 "extract-renamed" => "이름 바꿔 저장: 읽어주세요 (1).txt",
171 "empty" => "TAR.BZ2, TAR.XZ",
172 "tar-bz2" | "tar-xz" => "읽어주세요.txt",
173 "folder-empty" => "이 폴더는 비어 있습니다",
174 "dialog-error" => "파일 선택 창을 열 수 없습니다",
175 "extract-complete-cleanup-failed" => "압축을 풀었습니다",
176 "extract-disk-full" => "디스크 여유 공간이 부족합니다",
177 "extract-cleanup-failed" => "풀 위치 폴더에 남은 임시 파일이 있을 수 있습니다",
178 "extract-partial" => "일부 파일만 풀렸습니다",
179 "extract-uncertain" => "저장이 끝났는지 확인하지 못했습니다",
180 "extract-unsynced" => "파일을 디스크에 완전히 저장했는지 확인하지 못했습니다",
181 "source-changed" => "압축파일 다시 열기",
182 "gzip-conflict" => "다른 이름으로 저장",
183 "create-sevenzip" => "7z는 암호를 지원하지 않습니다",
184 "create-sevenzip-progress" => "파일을 저장하는 중",
185 "create-sevenzip-complete" => "7z 파일을 만들었습니다",
186 "create-sevenzip-error" => "7z 파일을 만들지 못했습니다",
187 "create-sevenzip-cancelled" => "작업을 취소했습니다",
188 "create-sevenzip-resource" => "큰 작업을 허용할까요?",
189 "create-sevenzip-split" => "쪼갤 용량 설정",
190 "create-sevenzip-split-invalid" => "쪼갤 용량은 1 이상의 정수로 입력하세요",
191 "create-sevenzip-split-complete" => "볼륨 3개로 나누어 저장했습니다",
192 "create-error" => "ZIP 파일을 만들지 못했습니다",
193 "password-create" => "암호 확인",
194 "folder" => "바다.jpg",
195 "search-empty" => "일치하는 항목이 없습니다",
196 "password" | "password-retry" => "암호",
197 "extract-complete" => "압축을 풀었습니다",
198 "extract-cancelled" => "작업을 취소했습니다",
199 "create-complete" => "ZIP 파일을 만들었습니다",
200 "create" | "create-encrypted" => "암호로 보호하기",
201 "unsupported" | "damaged" => "압축파일을 열지 못했습니다",
202 "conflict" => "압축을 풀지 못했습니다",
203 "close-confirm" => "닫",
204 _ => "읽어주세요.txt",
205 };
206 assert!(labels.contains(expected), "{}: {labels}", scenario.name);
207 match scenario.name {
208 "create-sevenzip-split" => {
209 for label in [
210 "볼륨 크기",
211 "700",
212 "MB",
213 "GB",
214 "여행 자료.7z.001, 여행 자료.7z.002",
215 ] {
216 assert!(labels.contains(label), "{label}: {labels}");
217 }
218 assert!(!labels.contains("쪼갤 용량은"), "{labels}");
219 assert_eq!(scenarios::split_volume(&app), Ok(Some(700 * 1024 * 1024)));
220 }
221 "create-sevenzip-split-invalid" => {
222 assert!(scenarios::split_volume(&app).is_err());
223 assert!(!labels.contains("여행 자료.7z.001"), "{labels}");
224 }
225 "create-sevenzip-split-complete" => {
226 let terminal = app.model.terminal.as_ref().unwrap();
227 assert_eq!(terminal.created_count, 3);
228 assert!(labels.contains("7z 파일을 만들었습니다"), "{labels}");
229 assert!(labels.contains("여행 자료.7z.001"), "{labels}");
230 assert!(!labels.contains("확인하지 못했습니다"), "{labels}");
231 }
232 _ => {}
233 }
234 if scenario.name == "extract-complete-cleanup-failed" {
235 use zipelo_ui_memory_app::archive_ui::{
236 Cleanup, Disposition, Outcome, Publication,
237 };
238 let terminal = app.model.terminal.as_ref().unwrap();
239 assert!(app.model.confirmed);
240 assert_eq!(terminal.outcome, Outcome::Completed);
241 assert_eq!(terminal.error, None);
242 assert_eq!(terminal.publication, Publication::Complete);
243 assert_eq!(terminal.cleanup, Cleanup::Failed);
244 assert_eq!(terminal.created_count, app.model.outputs.len() as u64);
245 assert!(app
246 .model
247 .outputs
248 .iter()
249 .all(|(_, state)| *state == Disposition::Created));
250 assert!(labels.contains("폴더에 저장했습니다"), "{labels}");
251 assert!(labels.contains("임시 파일을 지우지 못했습니다"), "{labels}");
252 assert!(
253 labels.contains("풀 위치 폴더에 남은 임시 파일이 있을 수 있습니다"),
254 "{labels}"
255 );
256 assert!(!labels.contains("압축을 풀지 못했습니다"), "{labels}");
257 assert!(!labels.contains("아무 파일도 풀지 않았습니다"), "{labels}");
258 }
259 if matches!(
260 scenario.name,
261 "extract-disk-full" | "extract-cleanup-failed"
262 ) {
263 use zipelo_ui_memory_app::archive_ui::{Cleanup, ErrorCode, Outcome, Publication};
264 let cleanup_failed = scenario.name == "extract-cleanup-failed";
265 let terminal = app.model.terminal.as_ref().unwrap();
266 assert!(app.model.confirmed);
267 assert_eq!(terminal.outcome, Outcome::Failed);
268 assert_eq!(terminal.publication, Publication::None);
269 assert_eq!(terminal.created_count, 0);
270 assert_eq!(terminal.retained_partial_count, 0);
271 assert_eq!(
272 terminal.error,
273 Some(if cleanup_failed {
274 ErrorCode::Io
275 } else {
276 ErrorCode::DiskFull
277 })
278 );
279 assert_eq!(
280 terminal.cleanup,
281 if cleanup_failed {
282 Cleanup::Failed
283 } else {
284 Cleanup::Complete
285 }
286 );
287 assert!(labels.contains("압축을 풀지 못했습니다"), "{labels}");
288 assert!(!labels.contains("압축을 풀었습니다"), "{labels}");
289 assert_eq!(
290 labels.contains("임시 파일을 지우지 못했습니다"),
291 cleanup_failed
292 );
293 if cleanup_failed {
294 assert!(!labels.contains("아무 파일도 풀지 않았습니다"), "{labels}");
295 } else {
296 assert!(
297 labels.contains("공간을 확보한 뒤 다시 시도하세요"),
298 "{labels}"
299 );
300 assert!(labels.contains("아무 파일도 풀지 않았습니다"), "{labels}");
301 }
302 }
303 if scenario.name == "extract-rename-failed" {
304 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
305 assert!(!labels.contains("이름 바꿔 저장:"), "{labels}");
306 }
307 if matches!(scenario.name, "tar-bz2" | "tar-xz") {
308 assert!(app.model.entries.iter().all(|entry| !entry.encrypted));
309 assert_eq!(
310 app.model.list_id.as_ref().unwrap().format,
311 zipelo_ui_memory_app::archive_ui::Format::Tar
312 );
313 }
314 if scenario.name == "many-items" {
315 assert_eq!(app.model.entries.len(), 505);
316 }
317 if matches!(scenario.name, "selection" | "marquee") {
318 assert_eq!(app.model.selected.len(), 4);
319 assert!(labels.contains("선택 2개"));
320 }
321 if scenario.name == "password-retry" {
322 assert_eq!(app.model.challenge.unwrap().1, 2);
323 }
324 }
325 }
326}
327
328#[test]
329fn command_line_catalog_and_errors_work_without_a_display() {
330 let run = |args: &[&str]| {
331 std::process::Command::new(env!("CARGO_BIN_EXE_zipelo-ui-memory-app"))
332 .args(args)
333 .env_remove("DISPLAY")
334 .env_remove("WAYLAND_DISPLAY")
335 .output()
336 .unwrap()
337 };
338 let listed = run(&["--list-ui-scenarios"]);
339 assert!(listed.status.success());
340 assert_eq!(
341 String::from_utf8(listed.stdout).unwrap(),
342 scenarios::listing()
343 );
344 for args in [vec!["--ui-scenario", "unknown"], vec!["--ui-scenario"]] {
345 let failed = run(&args);
346 assert!(!failed.status.success());
347 let stderr = String::from_utf8_lossy(&failed.stderr);
348 for scenario in SCENARIOS {
349 assert!(stderr.contains(scenario.name));
350 }
351 }
352}
353
354#[test]
355fn preview_ignores_password_submission() {
356 let ctx = egui::Context::default();
357 let mut preview = scenarios::Preview::new(scenarios::parse("password").unwrap().build(), &ctx);
358 for _ in 0..3 {
359 let mut output = ctx.run_ui(
360 egui::RawInput {
361 screen_rect: Some(egui::Rect::from_min_size(
362 egui::Pos2::ZERO,
363 egui::vec2(1060.0, 720.0),
364 )),
365 events: vec![
366 egui::Event::Text("화면 검토".into()),
367 egui::Event::Key {
368 key: egui::Key::Enter,
369 physical_key: None,
370 pressed: true,
371 repeat: false,
372 modifiers: egui::Modifiers::NONE,
373 },
374 ],
375 ..Default::default()
376 },
377 |ui| preview.0.show(ui),
378 );
379 output.textures_delta.clear();
380 }
381 assert_eq!(preview.0.model.challenge, Some((17, 1, false)));
382 assert!(preview.0.model.busy());
383}
384
385#[test]
386fn uninstall_previews_match_packaged_notices_and_do_not_start_jobs() {
387 let installer = include_str!("../../packaging/windows/rust/installer.nsi");
388 let prerm = include_str!("../../packaging/ubuntu/rust/prerm");
389 let helper = include_str!("../../packaging/ubuntu/rust/default-apps");
390 for (name, source, expected) in [
391 (
392 "uninstall-windows",
393 installer,
394 "직접 고른 기본 앱은 자동으로 바꾸지 않습니다.",
395 ),
396 (
397 "uninstall-settings-error",
398 installer,
399 "Windows 설정을 열지 못했습니다.",
400 ),
401 (
402 "uninstall-ubuntu-missing",
403 helper,
404 "이전 앱을 복원할 수 없습니다:",
405 ),
406 (
407 "uninstall-ubuntu-unknown-user",
408 prerm,
409 "제거를 요청한 사용자를 확인할 수 없어 사용자 기본 앱 설정은 변경하지 않습니다.",
410 ),
411 ] {
412 assert!(source.contains(expected));
413 let scenario = scenarios::parse(name).unwrap();
414 let ctx = egui::Context::default();
415 let mut preview = scenarios::Preview::new(scenario.build(), &ctx).with_scenario(scenario);
416 let mut output = ctx.run_ui(
417 egui::RawInput {
418 screen_rect: Some(egui::Rect::from_min_size(
419 egui::Pos2::ZERO,
420 egui::vec2(760.0, 540.0),
421 )),
422 events: vec![egui::Event::Key {
423 key: egui::Key::Enter,
424 physical_key: None,
425 pressed: true,
426 repeat: false,
427 modifiers: egui::Modifiers::NONE,
428 }],
429 ..Default::default()
430 },
431 |ui| preview.show(ui),
432 );
433 assert!(text(&output.shapes).contains(expected), "{name}");
434 assert!(!preview.0.model.busy());
435 assert!(preview.0.model.archive.is_none());
436 assert!(output.platform_output.commands.is_empty());
437 output.textures_delta.clear();
438 }
439}
440
441fn result_labels(
442 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
443 size: egui::Vec2,
444) -> String {
445 let ctx = egui::Context::default();
446 let mut labels = String::new();
447 for _ in 0..3 {
448 let mut output = ctx.run_ui(
449 egui::RawInput {
450 screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)),
451 ..Default::default()
452 },
453 |ui| app.show(ui),
454 );
455 labels = text(&output.shapes);
456 output.textures_delta.clear();
457 }
458 labels
459}
460
461#[test]
462fn rename_without_created_output_never_claims_saved_name() {
463 use zipelo_ui_memory_app::archive_ui::*;
464 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
465 for disposition in [
466 None,
467 Some(Disposition::PartialRetained),
468 Some(Disposition::Removed),
469 Some(Disposition::CommitUncertain),
470 ] {
471 let mut app = scenarios::parse("extract-renamed").unwrap().build();
472 app.model.outputs = disposition
473 .into_iter()
474 .map(|d| ("읽어주세요 (1).txt".into(), d))
475 .collect();
476 app.model.terminal = Some(Terminal {
477 outcome: Outcome::Failed,
478 error: Some(ErrorCode::Io),
479 publication: if disposition.is_none() {
480 Publication::None
481 } else {
482 Publication::Uncertain
483 },
484 created_count: 0,
485 retained_partial_count: 0,
486 durability: Durability::NotApplicable,
487 cleanup: Cleanup::Complete,
488 });
489 let labels = result_labels(&mut app, size);
490 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
491 if disposition.is_none() {
492 assert!(labels.contains("아무 파일도 풀지 않았습니다"), "{labels}");
493 }
494 assert!(
495 !labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
496 "{labels}"
497 );
498 }
499 }
500}
501
502#[test]
503fn rename_saved_before_later_failure_remains_reported() {
504 use zipelo_ui_memory_app::archive_ui::*;
505 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
506 let mut app = scenarios::parse("extract-renamed").unwrap().build();
507 app.model.resolutions.push(Resolution {
508 entry_id: 2,
509 relative_name: "여행 일정 (1).pdf".into(),
510 choice: ConflictChoice::Rename,
511 });
512 app.model.terminal.as_mut().unwrap().outcome = Outcome::Failed;
513 app.model.terminal.as_mut().unwrap().error = Some(ErrorCode::Io);
514 app.model.terminal.as_mut().unwrap().publication = Publication::Partial;
515 let labels = result_labels(&mut app, size);
516 assert!(
517 labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"),
518 "{labels}"
519 );
520 assert!(
521 !labels.contains("이름 바꿔 저장: 여행 일정 (1).pdf"),
522 "{labels}"
523 );
524 assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}");
525 }
526}
527
528fn resource_frame(
529 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
530 ctx: &egui::Context,
531 events: Vec<egui::Event>,
532) -> Vec<egui::epaint::ClippedShape> {
533 let mut out = ctx.run_ui(
534 egui::RawInput {
535 screen_rect: Some(egui::Rect::from_min_size(
536 egui::Pos2::ZERO,
537 egui::vec2(760.0, 540.0),
538 )),
539 events,
540 ..Default::default()
541 },
542 |ui| app.show(ui),
543 );
544 out.textures_delta.clear();
545 out.shapes
546}
547fn find_resource_action(shapes: &[egui::epaint::ClippedShape], label: &str) -> egui::Pos2 {
548 fn find(s: &egui::Shape, label: &str) -> Option<egui::Pos2> {
549 match s {
550 egui::Shape::Text(t) if t.galley.text() == label => {
551 Some(t.pos + t.galley.rect.size() / 2.0)
552 }
553 egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, label)),
554 _ => None,
555 }
556 }
557 shapes.iter().find_map(|s| find(&s.shape, label)).unwrap()
558}
559#[test]
560fn resource_dialog_requires_explicit_click_and_escape_cancels() {
561 for allow in [false, true] {
562 let ctx = egui::Context::default();
563 let mut app = scenarios::parse("resource-ratio").unwrap().build();
564 let mut shapes = Vec::new();
565 for _ in 0..3 {
566 shapes = resource_frame(&mut app, &ctx, vec![]);
567 }
568 assert!(text(&shapes).contains("미확인"));
569 resource_frame(
570 &mut app,
571 &ctx,
572 vec![egui::Event::Key {
573 key: egui::Key::Enter,
574 physical_key: None,
575 pressed: true,
576 repeat: false,
577 modifiers: Default::default(),
578 }],
579 );
580 assert!(app.model.resource.is_some());
581 if allow {
582 let point = find_resource_action(&shapes, "이 작업 허용");
583 resource_frame(
584 &mut app,
585 &ctx,
586 vec![
587 egui::Event::PointerMoved(point),
588 egui::Event::PointerButton {
589 pos: point,
590 button: egui::PointerButton::Primary,
591 pressed: true,
592 modifiers: Default::default(),
593 },
594 ],
595 );
596 resource_frame(
597 &mut app,
598 &ctx,
599 vec![egui::Event::PointerButton {
600 pos: point,
601 button: egui::PointerButton::Primary,
602 pressed: false,
603 modifiers: Default::default(),
604 }],
605 );
606 assert!(!app.model.cancellation_requested());
607 } else {
608 resource_frame(
609 &mut app,
610 &ctx,
611 vec![egui::Event::Key {
612 key: egui::Key::Escape,
613 physical_key: None,
614 pressed: true,
615 repeat: false,
616 modifiers: Default::default(),
617 }],
618 );
619 assert!(app.model.cancellation_requested());
620 }
621 assert!(app.model.resource.is_none());
622 }
623}
624#[test]
625fn partial_limit_result_never_offers_expanded_retry() {
626 let ctx = egui::Context::default();
627 let mut app = scenarios::parse("resource-partial").unwrap().build();
628 let mut shapes = Vec::new();
629 for _ in 0..3 {
630 shapes = resource_frame(&mut app, &ctx, vec![]);
631 }
632 assert!(!text(&shapes).contains("한도를 늘려 다시 시도"));
633 assert!(text(&shapes).contains("풀린 자료"));
634}
635
636#[test]
637fn preview_escape_discards_content_and_returns_to_list_without_changing_selection() {
638 for name in ["preview-text", "preview-image", "preview-loading"] {
639 let ctx = egui::Context::default();
640 let mut app = scenarios::parse(name).unwrap().build();
641 let selected = app.model.selected.clone();
642 for _ in 0..3 {
643 resource_frame(&mut app, &ctx, vec![]);
644 }
645 assert!(text(&resource_frame(&mut app, &ctx, vec![])).contains("미리보기"));
646 resource_frame(
647 &mut app,
648 &ctx,
649 vec![egui::Event::Key {
650 key: egui::Key::Escape,
651 physical_key: None,
652 pressed: true,
653 repeat: false,
654 modifiers: Default::default(),
655 }],
656 );
657 for _ in 0..3 {
658 resource_frame(&mut app, &ctx, vec![]);
659 }
660 assert!(app.model.preview.is_none());
661 assert_eq!(app.model.selected, selected);
662 if name == "preview-loading" {
663 assert!(app.model.cancellation_requested());
664 } else {
665 assert_eq!(
666 ctx.memory(|m| m.focused()),
667 Some(egui::Id::unique("archive-list"))
668 );
669 }
670 }
671}
672
673#[test]
674fn preview_image_respects_renderer_texture_limit() {
675 let ctx = egui::Context::default();
676 let mut app = scenarios::parse("preview-image").unwrap().build();
677 app.model.preview = Some(zipelo_ui_memory_app::archive_ui::Preview {
678 info: zipelo_ui_memory_app::archive_ui::PreviewInfo {
679 entry_id: 1,
680 format: zipelo_ui_memory_app::archive_ui::PreviewFormat::Rgba8,
681 width: 2048,
682 height: 1,
683 total_bytes: 8192,
684 },
685 data: vec![255; 8192],
686 });
687 let mut image_seen = false;
688 for _ in 0..3 {
689 let mut result = ctx.run_ui(
690 egui::RawInput {
691 max_texture_side: Some(1024),
692 screen_rect: Some(egui::Rect::from_min_size(
693 egui::Pos2::ZERO,
694 egui::vec2(760.0, 540.0),
695 )),
696 ..Default::default()
697 },
698 |ui| app.show(ui),
699 );
700 for (id, delta) in &result.textures_delta.set {
701 if *id == egui::TextureId::Managed(0) {
702 continue;
703 }
704 for image in delta {
705 assert!(image.image.size().iter().all(|n| *n <= 1024));
706 }
707 image_seen = true;
708 }
709 result.textures_delta.clear();
710 }
711 assert!(image_seen);
712}
713
714#[test]
715fn split_errors_use_main_modal_without_native_child() {
716 for name in [
717 "split-first-volume",
718 "split-missing-volume",
719 "split-incomplete",
720 "split-unsupported",
721 ] {
722 let scenario = scenarios::parse(name).unwrap();
723 let mut app = scenario.build();
724 let ctx = egui::Context::default();
725 ctx.set_embed_viewports(false);
726 let mut labels = String::new();
727 for _ in 0..3 {
728 let mut output = ctx.run_ui(
729 egui::RawInput {
730 screen_rect: Some(egui::Rect::from_min_size(
731 egui::Pos2::ZERO,
732 egui::vec2(1060.0, 720.0),
733 )),
734 ..Default::default()
735 },
736 |ui| scenario.show(&mut app, ui),
737 );
738 labels = text(&output.shapes);
739 output.textures_delta.clear();
740 assert!(
741 output
742 .viewport_output
743 .keys()
744 .all(|id| *id == egui::ViewportId::ROOT),
745 "{name}"
746 );
747 }
748 assert!(labels.contains("작업 결과"), "{name}: {labels}");
749 }
750}
751
752#[test]
753fn excluded_split_errors_show_support_guidance_in_main_modal() {
754 use zipelo_ui_memory_app::archive_ui::ErrorCode;
755
756 for code in [ErrorCode::UnsupportedFeature, ErrorCode::UnsupportedFormat] {
757 for archive in ["sample.zip.001", "sample.z01", "sample.rar", "sample.7z"] {
758 let scenario = scenarios::parse("split-unsupported").unwrap();
759 let mut app = scenario.build();
760 let ctx = egui::Context::default();
761 ctx.set_embed_viewports(false);
762 let input = || egui::RawInput {
763 screen_rect: Some(egui::Rect::from_min_size(
764 egui::Pos2::ZERO,
765 egui::vec2(1060.0, 720.0),
766 )),
767 ..Default::default()
768 };
769 for _ in 0..3 {
770 let mut output = ctx.run_ui(input(), |ui| scenario.show(&mut app, ui));
771 output.textures_delta.clear();
772 }
773 assert_eq!(
774 app.model.terminal.as_ref().unwrap().error,
775 Some(ErrorCode::UnsupportedFeature)
776 );
777 app.model.terminal.as_mut().unwrap().error = Some(code);
778 app.model.archive = Some(archive.into());
779 let mut output = ctx.run_ui(input(), |ui| scenario.show(&mut app, ui));
780 let labels = text(&output.shapes);
781 output.textures_delta.clear();
782 if archive == "sample.7z" {
783 assert!(!labels.contains("분할 ZIP과 RAR"));
784 } else {
785 assert!(
786 labels.contains("분할 ZIP과 RAR"),
787 "{code:?} {archive}: {labels}"
788 );
789 assert!(
790 output
791 .viewport_output
792 .keys()
793 .all(|id| *id == egui::ViewportId::ROOT)
794 );
795 }
796 }
797 }
798}