team-ljyzipelo

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