| 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 | let expected = match scenario.name { |
| 99 | "resource-approval" => "큰 작업을 허용할까요?", |
| 100 | "resource-ratio" => "압축률이 매우 높습니다", |
| 101 | "resource-retry" => "한도를 늘려 다시 시도", |
| 102 | "resource-partial" => "저장 위치를 확인하세요", |
| 103 | "uninstall-windows" => "제거 전에 다른 앱을 선택하세요", |
| 104 | "uninstall-settings-error" => "Windows 설정을 열지 못했습니다", |
| 105 | "uninstall-ubuntu-missing" => "이전 앱을 복원할 수 없습니다", |
| 106 | "uninstall-ubuntu-unknown-user" => "사용자 기본 앱 설정은 변경하지 않습니다", |
| 107 | "conflict-choice" | "conflict-apply" | "gzip-conflict-choice" => { |
| 108 | "나머지 파일에도 같게 적용" |
| 109 | } |
| 110 | "extract-skipped" => "모든 파일을 건너뛰었습니다", |
| 111 | "extract-rename-failed" => "아무 파일도 풀지 않았습니다", |
| 112 | "extract-renamed" => "이름 바꿔 저장: 읽어주세요 (1).txt", |
| 113 | "empty" => "TAR.BZ2, TAR.XZ", |
| 114 | "tar-bz2" | "tar-xz" => "읽어주세요.txt", |
| 115 | "folder-empty" => "이 폴더는 비어 있습니다", |
| 116 | "dialog-error" => "파일 선택 창을 열 수 없습니다", |
| 117 | "extract-partial" => "일부 파일만 풀렸습니다", |
| 118 | "extract-uncertain" => "저장이 끝났는지 확인하지 못했습니다", |
| 119 | "extract-unsynced" => "파일을 디스크에 완전히 저장했는지 확인하지 못했습니다", |
| 120 | "source-changed" => "압축파일 다시 열기", |
| 121 | "gzip-conflict" => "다른 이름으로 저장", |
| 122 | "create-error" => "ZIP 파일을 만들지 못했습니다", |
| 123 | "password-create" => "암호 확인", |
| 124 | "folder" => "바다.jpg", |
| 125 | "search-empty" => "일치하는 항목이 없습니다", |
| 126 | "password" | "password-retry" => "암호", |
| 127 | "extract-complete" => "압축을 풀었습니다", |
| 128 | "extract-cancelled" => "작업을 취소했습니다", |
| 129 | "create-complete" => "ZIP 파일을 만들었습니다", |
| 130 | "create" | "create-encrypted" => "암호로 보호하기", |
| 131 | "unsupported" | "damaged" => "압축파일을 열지 못했습니다", |
| 132 | "conflict" => "압축을 풀지 못했습니다", |
| 133 | "close-confirm" => "닫", |
| 134 | _ => "읽어주세요.txt", |
| 135 | }; |
| 136 | assert!(labels.contains(expected), "{}: {labels}", scenario.name); |
| 137 | if scenario.name == "extract-rename-failed" { |
| 138 | assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}"); |
| 139 | assert!(!labels.contains("이름 바꿔 저장:"), "{labels}"); |
| 140 | } |
| 141 | if matches!(scenario.name, "tar-bz2" | "tar-xz") { |
| 142 | assert!(app.model.entries.iter().all(|entry| !entry.encrypted)); |
| 143 | assert_eq!( |
| 144 | app.model.list_id.as_ref().unwrap().format, |
| 145 | zipelo_ui_memory_app::archive_ui::Format::Tar |
| 146 | ); |
| 147 | } |
| 148 | if scenario.name == "many-items" { |
| 149 | assert_eq!(app.model.entries.len(), 505); |
| 150 | } |
| 151 | if matches!(scenario.name, "selection" | "marquee") { |
| 152 | assert_eq!(app.model.selected.len(), 4); |
| 153 | assert!(labels.contains("선택 2개")); |
| 154 | } |
| 155 | if scenario.name == "password-retry" { |
| 156 | assert_eq!(app.model.challenge.unwrap().1, 2); |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | #[test] |
| 163 | fn command_line_catalog_and_errors_work_without_a_display() { |
| 164 | let run = |args: &[&str]| { |
| 165 | std::process::Command::new(env!("CARGO_BIN_EXE_zipelo-ui-memory-app")) |
| 166 | .args(args) |
| 167 | .env_remove("DISPLAY") |
| 168 | .env_remove("WAYLAND_DISPLAY") |
| 169 | .output() |
| 170 | .unwrap() |
| 171 | }; |
| 172 | let listed = run(&["--list-ui-scenarios"]); |
| 173 | assert!(listed.status.success()); |
| 174 | assert_eq!( |
| 175 | String::from_utf8(listed.stdout).unwrap(), |
| 176 | scenarios::listing() |
| 177 | ); |
| 178 | for args in [vec!["--ui-scenario", "unknown"], vec!["--ui-scenario"]] { |
| 179 | let failed = run(&args); |
| 180 | assert!(!failed.status.success()); |
| 181 | let stderr = String::from_utf8_lossy(&failed.stderr); |
| 182 | for scenario in SCENARIOS { |
| 183 | assert!(stderr.contains(scenario.name)); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | #[test] |
| 189 | fn preview_ignores_password_submission() { |
| 190 | let ctx = egui::Context::default(); |
| 191 | let mut preview = scenarios::Preview::new(scenarios::parse("password").unwrap().build(), &ctx); |
| 192 | for _ in 0..3 { |
| 193 | let mut output = ctx.run_ui( |
| 194 | egui::RawInput { |
| 195 | screen_rect: Some(egui::Rect::from_min_size( |
| 196 | egui::Pos2::ZERO, |
| 197 | egui::vec2(1060.0, 720.0), |
| 198 | )), |
| 199 | events: vec![ |
| 200 | egui::Event::Text("화면 검토".into()), |
| 201 | egui::Event::Key { |
| 202 | key: egui::Key::Enter, |
| 203 | physical_key: None, |
| 204 | pressed: true, |
| 205 | repeat: false, |
| 206 | modifiers: egui::Modifiers::NONE, |
| 207 | }, |
| 208 | ], |
| 209 | ..Default::default() |
| 210 | }, |
| 211 | |ui| preview.0.show(ui), |
| 212 | ); |
| 213 | output.textures_delta.clear(); |
| 214 | } |
| 215 | assert_eq!(preview.0.model.challenge, Some((17, 1, false))); |
| 216 | assert!(preview.0.model.busy()); |
| 217 | } |
| 218 | |
| 219 | #[test] |
| 220 | fn uninstall_previews_match_packaged_notices_and_do_not_start_jobs() { |
| 221 | let installer = include_str!("../../packaging/windows/rust/installer.nsi"); |
| 222 | let prerm = include_str!("../../packaging/ubuntu/rust/prerm"); |
| 223 | let helper = include_str!("../../packaging/ubuntu/rust/default-apps"); |
| 224 | for (name, source, expected) in [ |
| 225 | ( |
| 226 | "uninstall-windows", |
| 227 | installer, |
| 228 | "직접 고른 기본 앱은 자동으로 바꾸지 않습니다.", |
| 229 | ), |
| 230 | ( |
| 231 | "uninstall-settings-error", |
| 232 | installer, |
| 233 | "Windows 설정을 열지 못했습니다.", |
| 234 | ), |
| 235 | ( |
| 236 | "uninstall-ubuntu-missing", |
| 237 | helper, |
| 238 | "이전 앱을 복원할 수 없습니다:", |
| 239 | ), |
| 240 | ( |
| 241 | "uninstall-ubuntu-unknown-user", |
| 242 | prerm, |
| 243 | "제거를 요청한 사용자를 확인할 수 없어 사용자 기본 앱 설정은 변경하지 않습니다.", |
| 244 | ), |
| 245 | ] { |
| 246 | assert!(source.contains(expected)); |
| 247 | let scenario = scenarios::parse(name).unwrap(); |
| 248 | let ctx = egui::Context::default(); |
| 249 | let mut preview = scenarios::Preview::new(scenario.build(), &ctx).with_scenario(scenario); |
| 250 | let mut output = ctx.run_ui( |
| 251 | egui::RawInput { |
| 252 | screen_rect: Some(egui::Rect::from_min_size( |
| 253 | egui::Pos2::ZERO, |
| 254 | egui::vec2(760.0, 540.0), |
| 255 | )), |
| 256 | events: vec![egui::Event::Key { |
| 257 | key: egui::Key::Enter, |
| 258 | physical_key: None, |
| 259 | pressed: true, |
| 260 | repeat: false, |
| 261 | modifiers: egui::Modifiers::NONE, |
| 262 | }], |
| 263 | ..Default::default() |
| 264 | }, |
| 265 | |ui| preview.show(ui), |
| 266 | ); |
| 267 | assert!(text(&output.shapes).contains(expected), "{name}"); |
| 268 | assert!(!preview.0.model.busy()); |
| 269 | assert!(preview.0.model.archive.is_none()); |
| 270 | assert!(output.platform_output.commands.is_empty()); |
| 271 | output.textures_delta.clear(); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | fn result_labels( |
| 276 | app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp, |
| 277 | size: egui::Vec2, |
| 278 | ) -> String { |
| 279 | let ctx = egui::Context::default(); |
| 280 | let mut labels = String::new(); |
| 281 | for _ in 0..3 { |
| 282 | let mut output = ctx.run_ui( |
| 283 | egui::RawInput { |
| 284 | screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)), |
| 285 | ..Default::default() |
| 286 | }, |
| 287 | |ui| app.show(ui), |
| 288 | ); |
| 289 | labels = text(&output.shapes); |
| 290 | output.textures_delta.clear(); |
| 291 | } |
| 292 | labels |
| 293 | } |
| 294 | |
| 295 | #[test] |
| 296 | fn rename_without_created_output_never_claims_saved_name() { |
| 297 | use zipelo_ui_memory_app::archive_ui::*; |
| 298 | for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] { |
| 299 | for disposition in [ |
| 300 | None, |
| 301 | Some(Disposition::PartialRetained), |
| 302 | Some(Disposition::Removed), |
| 303 | Some(Disposition::CommitUncertain), |
| 304 | ] { |
| 305 | let mut app = scenarios::parse("extract-renamed").unwrap().build(); |
| 306 | app.model.outputs = disposition |
| 307 | .into_iter() |
| 308 | .map(|d| ("읽어주세요 (1).txt".into(), d)) |
| 309 | .collect(); |
| 310 | app.model.terminal = Some(Terminal { |
| 311 | outcome: Outcome::Failed, |
| 312 | error: Some(ErrorCode::Io), |
| 313 | publication: if disposition.is_none() { |
| 314 | Publication::None |
| 315 | } else { |
| 316 | Publication::Uncertain |
| 317 | }, |
| 318 | created_count: 0, |
| 319 | retained_partial_count: 0, |
| 320 | durability: Durability::NotApplicable, |
| 321 | cleanup: Cleanup::Complete, |
| 322 | }); |
| 323 | let labels = result_labels(&mut app, size); |
| 324 | assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}"); |
| 325 | if disposition.is_none() { |
| 326 | assert!(labels.contains("아무 파일도 풀지 않았습니다"), "{labels}"); |
| 327 | } |
| 328 | assert!( |
| 329 | !labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"), |
| 330 | "{labels}" |
| 331 | ); |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | #[test] |
| 337 | fn rename_saved_before_later_failure_remains_reported() { |
| 338 | use zipelo_ui_memory_app::archive_ui::*; |
| 339 | for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] { |
| 340 | let mut app = scenarios::parse("extract-renamed").unwrap().build(); |
| 341 | app.model.resolutions.push(Resolution { |
| 342 | entry_id: 2, |
| 343 | relative_name: "여행 일정 (1).pdf".into(), |
| 344 | choice: ConflictChoice::Rename, |
| 345 | }); |
| 346 | app.model.terminal.as_mut().unwrap().outcome = Outcome::Failed; |
| 347 | app.model.terminal.as_mut().unwrap().error = Some(ErrorCode::Io); |
| 348 | app.model.terminal.as_mut().unwrap().publication = Publication::Partial; |
| 349 | let labels = result_labels(&mut app, size); |
| 350 | assert!( |
| 351 | labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"), |
| 352 | "{labels}" |
| 353 | ); |
| 354 | assert!( |
| 355 | !labels.contains("이름 바꿔 저장: 여행 일정 (1).pdf"), |
| 356 | "{labels}" |
| 357 | ); |
| 358 | assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}"); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | fn resource_frame( |
| 363 | app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp, |
| 364 | ctx: &egui::Context, |
| 365 | events: Vec<egui::Event>, |
| 366 | ) -> Vec<egui::epaint::ClippedShape> { |
| 367 | let mut out = ctx.run_ui( |
| 368 | egui::RawInput { |
| 369 | screen_rect: Some(egui::Rect::from_min_size( |
| 370 | egui::Pos2::ZERO, |
| 371 | egui::vec2(760.0, 540.0), |
| 372 | )), |
| 373 | events, |
| 374 | ..Default::default() |
| 375 | }, |
| 376 | |ui| app.show(ui), |
| 377 | ); |
| 378 | out.textures_delta.clear(); |
| 379 | out.shapes |
| 380 | } |
| 381 | fn find_resource_action(shapes: &[egui::epaint::ClippedShape], label: &str) -> egui::Pos2 { |
| 382 | fn find(s: &egui::Shape, label: &str) -> Option<egui::Pos2> { |
| 383 | match s { |
| 384 | egui::Shape::Text(t) if t.galley.text() == label => { |
| 385 | Some(t.pos + t.galley.rect.size() / 2.0) |
| 386 | } |
| 387 | egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, label)), |
| 388 | _ => None, |
| 389 | } |
| 390 | } |
| 391 | shapes.iter().find_map(|s| find(&s.shape, label)).unwrap() |
| 392 | } |
| 393 | #[test] |
| 394 | fn resource_dialog_requires_explicit_click_and_escape_cancels() { |
| 395 | for allow in [false, true] { |
| 396 | let ctx = egui::Context::default(); |
| 397 | let mut app = scenarios::parse("resource-ratio").unwrap().build(); |
| 398 | let mut shapes = Vec::new(); |
| 399 | for _ in 0..3 { |
| 400 | shapes = resource_frame(&mut app, &ctx, vec![]); |
| 401 | } |
| 402 | assert!(text(&shapes).contains("미확인")); |
| 403 | resource_frame( |
| 404 | &mut app, |
| 405 | &ctx, |
| 406 | vec![egui::Event::Key { |
| 407 | key: egui::Key::Enter, |
| 408 | physical_key: None, |
| 409 | pressed: true, |
| 410 | repeat: false, |
| 411 | modifiers: Default::default(), |
| 412 | }], |
| 413 | ); |
| 414 | assert!(app.model.resource.is_some()); |
| 415 | if allow { |
| 416 | let point = find_resource_action(&shapes, "이 작업 허용"); |
| 417 | resource_frame( |
| 418 | &mut app, |
| 419 | &ctx, |
| 420 | vec![ |
| 421 | egui::Event::PointerMoved(point), |
| 422 | egui::Event::PointerButton { |
| 423 | pos: point, |
| 424 | button: egui::PointerButton::Primary, |
| 425 | pressed: true, |
| 426 | modifiers: Default::default(), |
| 427 | }, |
| 428 | ], |
| 429 | ); |
| 430 | resource_frame( |
| 431 | &mut app, |
| 432 | &ctx, |
| 433 | vec![egui::Event::PointerButton { |
| 434 | pos: point, |
| 435 | button: egui::PointerButton::Primary, |
| 436 | pressed: false, |
| 437 | modifiers: Default::default(), |
| 438 | }], |
| 439 | ); |
| 440 | assert!(!app.model.cancellation_requested()); |
| 441 | } else { |
| 442 | resource_frame( |
| 443 | &mut app, |
| 444 | &ctx, |
| 445 | vec![egui::Event::Key { |
| 446 | key: egui::Key::Escape, |
| 447 | physical_key: None, |
| 448 | pressed: true, |
| 449 | repeat: false, |
| 450 | modifiers: Default::default(), |
| 451 | }], |
| 452 | ); |
| 453 | assert!(app.model.cancellation_requested()); |
| 454 | } |
| 455 | assert!(app.model.resource.is_none()); |
| 456 | } |
| 457 | } |
| 458 | #[test] |
| 459 | fn partial_limit_result_never_offers_expanded_retry() { |
| 460 | let ctx = egui::Context::default(); |
| 461 | let mut app = scenarios::parse("resource-partial").unwrap().build(); |
| 462 | let mut shapes = Vec::new(); |
| 463 | for _ in 0..3 { |
| 464 | shapes = resource_frame(&mut app, &ctx, vec![]); |
| 465 | } |
| 466 | assert!(!text(&shapes).contains("한도를 늘려 다시 시도")); |
| 467 | assert!(text(&shapes).contains("풀린 자료")); |
| 468 | } |