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