team-ljyzipelo

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