team-ljyzipelo

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