| 1 | use super::*; |
| 2 | use std::{ |
| 3 | collections::BTreeSet, |
| 4 | fs, |
| 5 | sync::atomic::{AtomicU64, Ordering}, |
| 6 | }; |
| 7 | use zipelo_ui_memory_app::archive_present::*; |
| 8 | |
| 9 | fn terminal() -> Terminal { |
| 10 | Terminal { |
| 11 | outcome: Outcome::Failed, |
| 12 | error: Some(ErrorCode::Io), |
| 13 | publication: Publication::Partial, |
| 14 | created_count: 1, |
| 15 | retained_partial_count: 0, |
| 16 | durability: Durability::Synced, |
| 17 | cleanup: Cleanup::Complete, |
| 18 | } |
| 19 | } |
| 20 | fn targets() -> BTreeSet<String> { |
| 21 | ["one.txt".into(), "two.txt".into()].into_iter().collect() |
| 22 | } |
| 23 | |
| 24 | #[test] |
| 25 | fn partial_extraction_requires_matching_file_reports() { |
| 26 | let t = terminal(); |
| 27 | assert_eq!( |
| 28 | warnings( |
| 29 | Some(&t), |
| 30 | true, |
| 31 | Some(&targets()), |
| 32 | &[("one.txt".into(), Disposition::Created)] |
| 33 | ), |
| 34 | vec![PARTIAL] |
| 35 | ); |
| 36 | } |
| 37 | #[test] |
| 38 | fn all_saved_with_temporary_leftover_is_not_partial_extraction() { |
| 39 | let mut t = terminal(); |
| 40 | t.retained_partial_count = 1; |
| 41 | t.cleanup = Cleanup::Failed; |
| 42 | let files = ["one.txt".into()].into_iter().collect(); |
| 43 | assert_eq!( |
| 44 | warnings( |
| 45 | Some(&t), |
| 46 | true, |
| 47 | Some(&files), |
| 48 | &[ |
| 49 | ("one.txt".into(), Disposition::Created), |
| 50 | ("temp".into(), Disposition::PartialRetained) |
| 51 | ] |
| 52 | ), |
| 53 | vec![LEFTOVERS] |
| 54 | ); |
| 55 | } |
| 56 | #[test] |
| 57 | fn leftover_without_file_reports_and_commit_uncertainty_are_unknown() { |
| 58 | let mut t = terminal(); |
| 59 | t.created_count = 0; |
| 60 | t.retained_partial_count = 1; |
| 61 | for outputs in [ |
| 62 | vec![("temp".into(), Disposition::PartialRetained)], |
| 63 | vec![("one.txt".into(), Disposition::CommitUncertain)], |
| 64 | ] { |
| 65 | assert!(warnings(Some(&t), true, Some(&targets()), &outputs).contains(&UNCERTAIN)); |
| 66 | assert!(!warnings(Some(&t), true, Some(&targets()), &outputs).contains(&PARTIAL)); |
| 67 | } |
| 68 | } |
| 69 | #[test] |
| 70 | fn synchronization_and_cleanup_warnings_are_both_visible() { |
| 71 | let mut t = terminal(); |
| 72 | t.created_count = 0; |
| 73 | t.durability = Durability::Unconfirmed; |
| 74 | t.cleanup = Cleanup::Failed; |
| 75 | let result = warnings(Some(&t), true, Some(&targets()), &[]); |
| 76 | assert!(result.contains(&SYNC_WARNING)); |
| 77 | assert!(result.contains(&CLEANUP_WARNING)); |
| 78 | } |
| 79 | #[test] |
| 80 | fn missing_terminal_exit_or_contradictory_reports_never_claim_unsaved() { |
| 81 | let mut t = terminal(); |
| 82 | t.publication = Publication::None; |
| 83 | t.created_count = 0; |
| 84 | assert!(definitely_unsaved(Some(&t), true, &[])); |
| 85 | assert!(!definitely_unsaved(None, true, &[])); |
| 86 | assert!(!definitely_unsaved(Some(&t), false, &[])); |
| 87 | let reports = [("one.txt".into(), Disposition::Created)]; |
| 88 | assert!(!definitely_unsaved(Some(&t), true, &reports)); |
| 89 | assert!(warnings(Some(&t), true, Some(&targets()), &reports).contains(&UNCERTAIN)); |
| 90 | } |
| 91 | #[test] |
| 92 | fn unsafe_path_and_conflict_preserve_result_classification() { |
| 93 | for code in [ErrorCode::UnsafePath, ErrorCode::Conflict] { |
| 94 | let mut t = terminal(); |
| 95 | t.error = Some(code); |
| 96 | assert_eq!( |
| 97 | warnings( |
| 98 | Some(&t), |
| 99 | true, |
| 100 | Some(&targets()), |
| 101 | &[("one.txt".into(), Disposition::Created)] |
| 102 | ), |
| 103 | vec![PARTIAL] |
| 104 | ); |
| 105 | t.publication = Publication::Uncertain; |
| 106 | assert!(warnings(Some(&t), true, Some(&targets()), &[]).contains(&UNCERTAIN)); |
| 107 | t.publication = Publication::None; |
| 108 | t.created_count = 0; |
| 109 | assert!(definitely_unsaved(Some(&t), true, &[])); |
| 110 | } |
| 111 | } |
| 112 | #[test] |
| 113 | fn every_error_and_stage_has_user_facing_text() { |
| 114 | for code in [ |
| 115 | ErrorCode::Integrity, |
| 116 | ErrorCode::UnsupportedFormat, |
| 117 | ErrorCode::UnsupportedFeature, |
| 118 | ErrorCode::WrongPassword, |
| 119 | ErrorCode::UnsafePath, |
| 120 | ErrorCode::Conflict, |
| 121 | ErrorCode::Limit, |
| 122 | ErrorCode::Io, |
| 123 | ErrorCode::DiskFull, |
| 124 | ErrorCode::Protocol, |
| 125 | ErrorCode::Internal, |
| 126 | ErrorCode::SourceChanged, |
| 127 | ErrorCode::InvalidRequest, |
| 128 | ] { |
| 129 | assert!(!error_text(code).is_empty()); |
| 130 | assert!(!error_text(code).contains("작업자")); |
| 131 | } |
| 132 | assert_eq!(error_text(ErrorCode::Protocol), INTERNAL); |
| 133 | assert_eq!(error_text(ErrorCode::Internal), INTERNAL); |
| 134 | assert_eq!(progress_text(Stage::Decode, true), "압축하는 중"); |
| 135 | assert_eq!(progress_text(Stage::Decode, false), "압축을 푸는 중"); |
| 136 | } |
| 137 | #[test] |
| 138 | fn folder_selection_expands_only_matching_descendants() { |
| 139 | let entries = vec![ |
| 140 | Entry { |
| 141 | id: 0, |
| 142 | name: "docs".into(), |
| 143 | kind: Kind::Directory, |
| 144 | bytes: None, |
| 145 | packed: None, |
| 146 | encrypted: false, |
| 147 | }, |
| 148 | Entry { |
| 149 | id: 1, |
| 150 | name: "docs/one.txt".into(), |
| 151 | kind: Kind::File, |
| 152 | bytes: None, |
| 153 | packed: None, |
| 154 | encrypted: false, |
| 155 | }, |
| 156 | Entry { |
| 157 | id: 2, |
| 158 | name: "docs-old/two.txt".into(), |
| 159 | kind: Kind::File, |
| 160 | bytes: None, |
| 161 | packed: None, |
| 162 | encrypted: false, |
| 163 | }, |
| 164 | ]; |
| 165 | assert_eq!( |
| 166 | target_files(&entries, &[0].into_iter().collect(), true, None), |
| 167 | Some(["docs/one.txt".into()].into_iter().collect()) |
| 168 | ); |
| 169 | } |
| 170 | #[test] |
| 171 | fn duplicate_names_prevent_file_completion_assumptions() { |
| 172 | let entry = Entry { |
| 173 | id: 0, |
| 174 | name: "same.txt".into(), |
| 175 | kind: Kind::File, |
| 176 | bytes: None, |
| 177 | packed: None, |
| 178 | encrypted: false, |
| 179 | }; |
| 180 | assert!(target_files(&[entry.clone(), entry], &BTreeSet::new(), false, None).is_none()); |
| 181 | assert_eq!( |
| 182 | warnings(Some(&terminal()), true, None, &[]), |
| 183 | vec![UNCERTAIN] |
| 184 | ); |
| 185 | } |
| 186 | #[test] |
| 187 | fn default_names_and_middle_truncation_preserve_unicode() { |
| 188 | assert_eq!(default_destination(&path("자료.tar.gz")), path("자료")); |
| 189 | assert_eq!(default_destination(&path("자료.zip")), path("자료")); |
| 190 | assert_eq!(middle_text("가나다라마바사아자차", 7), "가나다…아자차"); |
| 191 | assert_eq!(bytes_text(21), "21 B"); |
| 192 | } |
| 193 | |
| 194 | static SCRATCH_ID: AtomicU64 = AtomicU64::new(0); |
| 195 | pub(super) struct Folder(pub(super) PathBuf); |
| 196 | impl Folder { |
| 197 | pub(super) fn new() -> Self { |
| 198 | let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../tests/rust-app-ui/runs"); |
| 199 | fs::create_dir_all(&root).unwrap(); |
| 200 | let path = root.join(format!( |
| 201 | "presentation-{}-{}", |
| 202 | std::process::id(), |
| 203 | SCRATCH_ID.fetch_add(1, Ordering::Relaxed) |
| 204 | )); |
| 205 | fs::create_dir(&path).unwrap(); |
| 206 | Self(path.canonicalize().unwrap()) |
| 207 | } |
| 208 | } |
| 209 | impl Drop for Folder { |
| 210 | fn drop(&mut self) { |
| 211 | fs::remove_dir_all(&self.0).unwrap(); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | #[test] |
| 216 | fn automatic_destination_creation_and_failure_are_distinct() { |
| 217 | let scratch = Folder::new(); |
| 218 | let output = scratch.0.join("output"); |
| 219 | assert!(prepare_destination(&output, true).unwrap()); |
| 220 | assert!(!prepare_destination(&output, true).unwrap()); |
| 221 | assert!(prepare_destination(&scratch.0.join("missing/child"), true).is_err()); |
| 222 | assert!(prepare_destination(&scratch.0.join("chosen-missing"), false).is_err()); |
| 223 | let file = scratch.0.join("file"); |
| 224 | fs::write(&file, "existing").unwrap(); |
| 225 | assert!(prepare_destination(&file, true).is_err()); |
| 226 | assert_eq!(fs::read_to_string(file).unwrap(), "existing"); |
| 227 | } |
| 228 | #[test] |
| 229 | fn only_new_empty_output_is_removed_and_nonempty_is_preserved() { |
| 230 | let scratch = Folder::new(); |
| 231 | let empty = scratch.0.join("empty"); |
| 232 | assert!(prepare_destination(&empty, true).unwrap()); |
| 233 | remove_owned_empty(&empty); |
| 234 | assert!(!empty.exists()); |
| 235 | let nonempty = scratch.0.join("nonempty"); |
| 236 | assert!(prepare_destination(&nonempty, true).unwrap()); |
| 237 | fs::write(nonempty.join("existing"), "keep").unwrap(); |
| 238 | remove_owned_empty(&nonempty); |
| 239 | assert_eq!( |
| 240 | fs::read_to_string(nonempty.join("existing")).unwrap(), |
| 241 | "keep" |
| 242 | ); |
| 243 | assert!(!prepare_destination(&scratch.0, false).unwrap()); |
| 244 | assert!(scratch.0.is_dir()); |
| 245 | } |
| 246 | #[cfg(unix)] |
| 247 | #[test] |
| 248 | fn browser_and_output_do_not_follow_symbolic_links() { |
| 249 | let scratch = Folder::new(); |
| 250 | let link = scratch.0.join("link"); |
| 251 | std::os::unix::fs::symlink(&scratch.0, &link).unwrap(); |
| 252 | let rows = directory_entries(&scratch.0).unwrap(); |
| 253 | assert!(rows.iter().any(|entry| entry.link && entry.path == link)); |
| 254 | assert!(directory_entries(&link).is_err()); |
| 255 | assert!(prepare_destination(&link, true).is_err()); |
| 256 | } |
| 257 | |
| 258 | #[cfg(feature = "ui")] |
| 259 | mod widgets { |
| 260 | use super::*; |
| 261 | use eframe::egui::{self, epaint::Shape}; |
| 262 | use zipelo_ui_memory_app::{ |
| 263 | archive_picker::{Choice, Picker, Purpose}, |
| 264 | archive_screen::ArchiveApp, |
| 265 | }; |
| 266 | |
| 267 | fn labels(shapes: &[egui::epaint::ClippedShape]) -> Vec<(String, egui::Pos2)> { |
| 268 | fn walk(shape: &Shape, result: &mut Vec<(String, egui::Pos2)>) { |
| 269 | match shape { |
| 270 | Shape::Text(text) => result.push(( |
| 271 | text.galley.job.text.clone(), |
| 272 | text.pos + text.galley.rect.size() / 2.0, |
| 273 | )), |
| 274 | Shape::Vec(shapes) => { |
| 275 | for shape in shapes { |
| 276 | walk(shape, result); |
| 277 | } |
| 278 | } |
| 279 | _ => {} |
| 280 | } |
| 281 | } |
| 282 | let mut result = Vec::new(); |
| 283 | for shape in shapes { |
| 284 | walk(&shape.shape, &mut result); |
| 285 | } |
| 286 | result |
| 287 | } |
| 288 | fn render( |
| 289 | ctx: &egui::Context, |
| 290 | app: &mut ArchiveApp, |
| 291 | events: Vec<egui::Event>, |
| 292 | ) -> Vec<(String, egui::Pos2)> { |
| 293 | let mut output = ctx.run_ui( |
| 294 | egui::RawInput { |
| 295 | screen_rect: Some(egui::Rect::from_min_size( |
| 296 | egui::Pos2::ZERO, |
| 297 | egui::vec2(760.0, 540.0), |
| 298 | )), |
| 299 | events, |
| 300 | ..Default::default() |
| 301 | }, |
| 302 | |ui| app.show(ui), |
| 303 | ); |
| 304 | output.textures_delta.clear(); |
| 305 | labels(&output.shapes) |
| 306 | } |
| 307 | fn click(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) { |
| 308 | render(ctx, app, vec![]); |
| 309 | let point = render(ctx, app, vec![]) |
| 310 | .into_iter() |
| 311 | .filter(|(text, _)| text == label) |
| 312 | .max_by(|a, b| a.1.y.total_cmp(&b.1.y)) |
| 313 | .unwrap_or_else(|| panic!("항목 없음: {label}")) |
| 314 | .1; |
| 315 | for pressed in [true, false] { |
| 316 | render( |
| 317 | ctx, |
| 318 | app, |
| 319 | vec![ |
| 320 | egui::Event::PointerMoved(point), |
| 321 | egui::Event::PointerButton { |
| 322 | pos: point, |
| 323 | button: egui::PointerButton::Primary, |
| 324 | pressed, |
| 325 | modifiers: egui::Modifiers::NONE, |
| 326 | }, |
| 327 | ], |
| 328 | ); |
| 329 | } |
| 330 | } |
| 331 | fn key(key: egui::Key) -> egui::Event { |
| 332 | egui::Event::Key { |
| 333 | key, |
| 334 | physical_key: None, |
| 335 | pressed: true, |
| 336 | repeat: false, |
| 337 | modifiers: egui::Modifiers::NONE, |
| 338 | } |
| 339 | } |
| 340 | fn text(ctx: &egui::Context, app: &mut ArchiveApp, id: &str, value: &str) { |
| 341 | ctx.memory_mut(|memory| memory.request_focus(egui::Id::unique(id))); |
| 342 | render( |
| 343 | ctx, |
| 344 | app, |
| 345 | vec![ |
| 346 | egui::Event::Key { |
| 347 | key: egui::Key::A, |
| 348 | physical_key: None, |
| 349 | pressed: true, |
| 350 | repeat: false, |
| 351 | modifiers: egui::Modifiers::COMMAND, |
| 352 | }, |
| 353 | egui::Event::Text(value.into()), |
| 354 | ], |
| 355 | ); |
| 356 | } |
| 357 | fn loaded(scratch: &Folder, factory: &FakeFactory) -> ArchiveApp { |
| 358 | let mut app = ArchiveApp::new( |
| 359 | Box::new(factory.clone()), |
| 360 | Some(scratch.0.join("sample.zip")), |
| 361 | false, |
| 362 | ); |
| 363 | pump(&mut app.model); |
| 364 | app |
| 365 | } |
| 366 | #[test] |
| 367 | fn empty_view_has_no_internal_status_and_keyboard_focus_is_reachable() { |
| 368 | let ctx = egui::Context::default(); |
| 369 | let mut app = ArchiveApp::new(Box::new(FakeFactory::default()), None, false); |
| 370 | render(&ctx, &mut app, vec![]); |
| 371 | let shown = render(&ctx, &mut app, vec![key(egui::Key::Tab)]); |
| 372 | assert!( |
| 373 | shown |
| 374 | .iter() |
| 375 | .any(|(text, _)| text == "압축파일을 여기에 끌어 놓으세요") |
| 376 | ); |
| 377 | assert!(!shown.iter().any(|(text, _)| text.contains("게시") |
| 378 | || text.contains("동기화") |
| 379 | || text.contains("시험 모드"))); |
| 380 | assert!(ctx.memory(|memory| memory.focused().is_some())); |
| 381 | app.model.request_close(); |
| 382 | let closing = render(&ctx, &mut app, vec![]); |
| 383 | assert!(!closing.iter().any(|(text, _)| text == UNCERTAIN)); |
| 384 | } |
| 385 | #[test] |
| 386 | fn empty_selection_and_empty_zip_sources_do_not_start_work() { |
| 387 | let scratch = Folder::new(); |
| 388 | let ctx = egui::Context::default(); |
| 389 | let factory = FakeFactory::default(); |
| 390 | let mut app = loaded(&scratch, &factory); |
| 391 | render(&ctx, &mut app, vec![]); |
| 392 | click(&ctx, &mut app, "선택한 항목만 풀기"); |
| 393 | click(&ctx, &mut app, "풀기"); |
| 394 | assert_eq!(factory.state.borrow().starts.len(), 1); |
| 395 | click(&ctx, &mut app, "ZIP 만들기"); |
| 396 | click(&ctx, &mut app, "만들기"); |
| 397 | assert_eq!(factory.state.borrow().starts.len(), 1); |
| 398 | assert!(!app.model.busy()); |
| 399 | } |
| 400 | #[test] |
| 401 | fn destination_failure_sends_no_request_and_explains_folder_change() { |
| 402 | let scratch = Folder::new(); |
| 403 | let factory = FakeFactory::default(); |
| 404 | let mut app = loaded(&scratch, &factory); |
| 405 | let file = scratch.0.join("existing.txt"); |
| 406 | fs::write(&file, "preserve").unwrap(); |
| 407 | app.choose_destination(file.clone()); |
| 408 | assert!(!app.begin_extract()); |
| 409 | assert_eq!(factory.state.borrow().starts.len(), 1); |
| 410 | let ctx = egui::Context::default(); |
| 411 | render(&ctx, &mut app, vec![]); |
| 412 | assert!( |
| 413 | render(&ctx, &mut app, vec![]) |
| 414 | .iter() |
| 415 | .any(|(text, _)| text == FOLDER_ERROR) |
| 416 | ); |
| 417 | assert_eq!(fs::read_to_string(file).unwrap(), "preserve"); |
| 418 | } |
| 419 | #[test] |
| 420 | fn cancelling_removes_only_automatically_created_empty_folder() { |
| 421 | for case in ["automatic-empty", "automatic-nonempty", "chosen-empty"] { |
| 422 | let scratch = Folder::new(); |
| 423 | let factory = FakeFactory::default(); |
| 424 | let mut app = loaded(&scratch, &factory); |
| 425 | factory.state.borrow_mut().manual = true; |
| 426 | let destination = if case == "chosen-empty" { |
| 427 | let path = scratch.0.join("chosen"); |
| 428 | fs::create_dir(&path).unwrap(); |
| 429 | app.choose_destination(path.clone()); |
| 430 | path |
| 431 | } else { |
| 432 | scratch.0.join("sample") |
| 433 | }; |
| 434 | assert!(app.begin_extract()); |
| 435 | if case == "automatic-nonempty" { |
| 436 | fs::write(destination.join("preserve"), "keep").unwrap(); |
| 437 | } |
| 438 | { |
| 439 | let mut state = factory.state.borrow_mut(); |
| 440 | state.frame(Event::Accepted { encryption: true }); |
| 441 | state.finish(Outcome::Cancelled, Publication::None); |
| 442 | } |
| 443 | let ctx = egui::Context::default(); |
| 444 | for _ in 0..30 { |
| 445 | render(&ctx, &mut app, vec![]); |
| 446 | } |
| 447 | assert!(!app.model.busy()); |
| 448 | assert_eq!(destination.exists(), case != "automatic-empty"); |
| 449 | } |
| 450 | } |
| 451 | #[test] |
| 452 | fn password_confirmation_requires_match_and_enter_sends_once() { |
| 453 | let scratch = Folder::new(); |
| 454 | let factory = FakeFactory::manual(); |
| 455 | let mut app = ArchiveApp::new(Box::new(factory.clone()), None, false); |
| 456 | assert!(app.model.begin( |
| 457 | Start::CreateZip { |
| 458 | sources: vec![(scratch.0.join("source"), "source".into())], |
| 459 | output_file: scratch.0.join("new.zip"), |
| 460 | method: Method::Deflate, |
| 461 | aes256: true |
| 462 | }, |
| 463 | &mut factory.clone() |
| 464 | )); |
| 465 | { |
| 466 | let mut state = factory.state.borrow_mut(); |
| 467 | state.frame(Event::Accepted { encryption: true }); |
| 468 | state.frame(Event::PasswordRequired { |
| 469 | challenge_id: 17, |
| 470 | attempt: 1, |
| 471 | encrypt: true, |
| 472 | }); |
| 473 | } |
| 474 | let ctx = egui::Context::default(); |
| 475 | for _ in 0..12 { |
| 476 | render(&ctx, &mut app, vec![]); |
| 477 | } |
| 478 | assert_eq!( |
| 479 | ctx.memory(|memory| memory.focused()), |
| 480 | Some(egui::Id::unique("archive-password-input")) |
| 481 | ); |
| 482 | text(&ctx, &mut app, "archive-password-input", "fixture-secret"); |
| 483 | text(&ctx, &mut app, "archive-password-confirm", "different"); |
| 484 | click(&ctx, &mut app, "확인"); |
| 485 | assert!(!factory.state.borrow().password_seen); |
| 486 | text(&ctx, &mut app, "archive-password-confirm", "fixture-secret"); |
| 487 | let shown = render(&ctx, &mut app, vec![key(egui::Key::Enter)]); |
| 488 | assert!( |
| 489 | !shown |
| 490 | .iter() |
| 491 | .any(|(text, _)| text.contains("fixture-secret")) |
| 492 | ); |
| 493 | assert!(factory.state.borrow().password_seen); |
| 494 | assert!(app.model.challenge.is_none()); |
| 495 | } |
| 496 | #[test] |
| 497 | fn picker_fits_minimum_window_and_opens_selected_file_with_enter() { |
| 498 | let scratch = Folder::new(); |
| 499 | let file = scratch.0.join("one.zip"); |
| 500 | fs::write(&file, "fixture").unwrap(); |
| 501 | let ctx = egui::Context::default(); |
| 502 | let mut picker = Picker::new(Purpose::Open, &scratch.0); |
| 503 | let mut result = None; |
| 504 | let mut draw = |events| { |
| 505 | let mut output = ctx.run_ui( |
| 506 | egui::RawInput { |
| 507 | screen_rect: Some(egui::Rect::from_min_size( |
| 508 | egui::Pos2::ZERO, |
| 509 | egui::vec2(760.0, 540.0), |
| 510 | )), |
| 511 | events, |
| 512 | ..Default::default() |
| 513 | }, |
| 514 | |_ui| { |
| 515 | result = picker.show(&ctx); |
| 516 | }, |
| 517 | ); |
| 518 | output.textures_delta.clear(); |
| 519 | labels(&output.shapes) |
| 520 | }; |
| 521 | draw(vec![]); |
| 522 | let shown = draw(vec![]); |
| 523 | for label in ["파일 열기", "열기", "홈"] { |
| 524 | let (_, point) = shown.iter().find(|(text, _)| text == label).unwrap(); |
| 525 | assert!((0.0..540.0).contains(&point.y), "{label}: {point:?}"); |
| 526 | } |
| 527 | let cancel = shown.iter().find(|(text, _)| text == "취소").unwrap().1; |
| 528 | let confirm = shown.iter().find(|(text, _)| text == "열기").unwrap().1; |
| 529 | assert!(cancel.x < confirm.x); |
| 530 | let point = shown.iter().find(|(text, _)| text == "one.zip").unwrap().1; |
| 531 | for pressed in [true, false] { |
| 532 | draw(vec![ |
| 533 | egui::Event::PointerMoved(point), |
| 534 | egui::Event::PointerButton { |
| 535 | pos: point, |
| 536 | button: egui::PointerButton::Primary, |
| 537 | pressed, |
| 538 | modifiers: egui::Modifiers::NONE, |
| 539 | }, |
| 540 | ]); |
| 541 | } |
| 542 | draw(vec![key(egui::Key::Enter)]); |
| 543 | assert!(matches!(result, Some(Choice::Paths(ref paths)) if paths == &vec![file])); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | #[cfg(feature = "ui")] |
| 548 | #[test] |
| 549 | fn conflict_retry_waits_for_folder_choice_and_preserves_selection() { |
| 550 | use eframe::egui; |
| 551 | use zipelo_ui_memory_app::archive_screen::ArchiveApp; |
| 552 | let scratch = Folder::new(); |
| 553 | let factory = FakeFactory::default(); |
| 554 | let mut app = ArchiveApp::new( |
| 555 | Box::new(factory.clone()), |
| 556 | Some(scratch.0.join("sample.zip")), |
| 557 | false, |
| 558 | ); |
| 559 | pump(&mut app.model); |
| 560 | app.model.selected.insert(0); |
| 561 | factory.state.borrow_mut().manual = true; |
| 562 | let ctx = egui::Context::default(); |
| 563 | let render = |app: &mut ArchiveApp, events| { |
| 564 | let mut output = ctx.run_ui( |
| 565 | egui::RawInput { |
| 566 | screen_rect: Some(egui::Rect::from_min_size( |
| 567 | egui::Pos2::ZERO, |
| 568 | egui::vec2(760.0, 540.0), |
| 569 | )), |
| 570 | events, |
| 571 | ..Default::default() |
| 572 | }, |
| 573 | |ui| app.show(ui), |
| 574 | ); |
| 575 | output.textures_delta.clear(); |
| 576 | fn walk(shape: &egui::epaint::Shape, labels: &mut Vec<(String, egui::Pos2)>) { |
| 577 | match shape { |
| 578 | egui::epaint::Shape::Text(text) => labels.push(( |
| 579 | text.galley.job.text.clone(), |
| 580 | text.pos + text.galley.rect.size() / 2.0, |
| 581 | )), |
| 582 | egui::epaint::Shape::Vec(shapes) => { |
| 583 | for shape in shapes { |
| 584 | walk(shape, labels); |
| 585 | } |
| 586 | } |
| 587 | _ => {} |
| 588 | } |
| 589 | } |
| 590 | let mut labels = Vec::new(); |
| 591 | for shape in &output.shapes { |
| 592 | walk(&shape.shape, &mut labels); |
| 593 | } |
| 594 | labels |
| 595 | }; |
| 596 | let click = |app: &mut ArchiveApp, text: &str| { |
| 597 | render(app, vec![]); |
| 598 | let point = render(app, vec![]) |
| 599 | .into_iter() |
| 600 | .filter(|(value, _)| value == text) |
| 601 | .max_by(|a, b| a.1.y.total_cmp(&b.1.y)) |
| 602 | .unwrap_or_else(|| panic!("항목 없음: {text}")) |
| 603 | .1; |
| 604 | for pressed in [true, false] { |
| 605 | render( |
| 606 | app, |
| 607 | vec![ |
| 608 | egui::Event::PointerMoved(point), |
| 609 | egui::Event::PointerButton { |
| 610 | pos: point, |
| 611 | button: egui::PointerButton::Primary, |
| 612 | pressed, |
| 613 | modifiers: egui::Modifiers::NONE, |
| 614 | }, |
| 615 | ], |
| 616 | ); |
| 617 | } |
| 618 | }; |
| 619 | render(&mut app, vec![]); |
| 620 | click(&mut app, "선택한 항목만 풀기"); |
| 621 | assert!(app.begin_extract()); |
| 622 | let old = scratch.0.join("sample"); |
| 623 | fs::write(old.join("existing"), "preserve").unwrap(); |
| 624 | let chosen = scratch.0.join("chosen"); |
| 625 | fs::create_dir(&chosen).unwrap(); |
| 626 | { |
| 627 | let mut state = factory.state.borrow_mut(); |
| 628 | state.frame(Event::Accepted { encryption: true }); |
| 629 | state.frame(Event::Terminal(Terminal { |
| 630 | outcome: Outcome::Failed, |
| 631 | error: Some(ErrorCode::Conflict), |
| 632 | publication: Publication::None, |
| 633 | created_count: 0, |
| 634 | retained_partial_count: 0, |
| 635 | durability: Durability::NotApplicable, |
| 636 | cleanup: Cleanup::Complete, |
| 637 | })); |
| 638 | state.queue.extend([ |
| 639 | HostEvent::StdoutEof, |
| 640 | HostEvent::StderrEof, |
| 641 | HostEvent::Exited { success: true }, |
| 642 | ]); |
| 643 | } |
| 644 | for _ in 0..30 { |
| 645 | render(&mut app, vec![]); |
| 646 | } |
| 647 | assert_eq!(factory.state.borrow().starts.len(), 2); |
| 648 | click(&mut app, "다른 폴더에 풀기"); |
| 649 | assert_eq!(factory.state.borrow().starts.len(), 2); |
| 650 | click(&mut app, "상위 폴더"); |
| 651 | click(&mut app, "chosen"); |
| 652 | click(&mut app, "이 폴더 선택"); |
| 653 | assert!(matches!(factory.state.borrow().starts.last(), |
| 654 | Some(Start::Extract { destination, selection: Selection::EntryIds(ids), .. }) |
| 655 | if destination == &chosen && ids == &vec![0])); |
| 656 | assert_eq!( |
| 657 | fs::read_to_string(old.join("existing")).unwrap(), |
| 658 | "preserve" |
| 659 | ); |
| 660 | } |
| 661 | |
| 662 | #[cfg(feature = "ui")] |
| 663 | #[test] |
| 664 | fn create_dialog_keeps_title_and_actions_visible_after_resize() { |
| 665 | use eframe::egui::{self, epaint::Shape}; |
| 666 | use zipelo_ui_memory_app::archive_screen::ArchiveApp; |
| 667 | let scratch = Folder::new(); |
| 668 | let mut app = ArchiveApp::new(Box::new(FakeFactory::default()), None, false); |
| 669 | app.add_sources(vec![scratch.0.join("one.txt"), scratch.0.join("photos")]); |
| 670 | let ctx = egui::Context::default(); |
| 671 | for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] { |
| 672 | let mut texts = Vec::new(); |
| 673 | for _ in 0..8 { |
| 674 | let mut output = ctx.run_ui( |
| 675 | egui::RawInput { |
| 676 | screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)), |
| 677 | ..Default::default() |
| 678 | }, |
| 679 | |ui| app.show(ui), |
| 680 | ); |
| 681 | output.textures_delta.clear(); |
| 682 | fn walk(shape: &Shape, output: &mut Vec<(String, egui::Pos2)>) { |
| 683 | match shape { |
| 684 | Shape::Text(text) => output.push(( |
| 685 | text.galley.job.text.clone(), |
| 686 | text.pos + text.galley.rect.size() / 2.0, |
| 687 | )), |
| 688 | Shape::Vec(shapes) => { |
| 689 | for shape in shapes { |
| 690 | walk(shape, output); |
| 691 | } |
| 692 | } |
| 693 | _ => {} |
| 694 | } |
| 695 | } |
| 696 | texts.clear(); |
| 697 | for shape in &output.shapes { |
| 698 | walk(&shape.shape, &mut texts); |
| 699 | } |
| 700 | } |
| 701 | for label in ["ZIP 만들기", "만들기", "취소"] { |
| 702 | let positions = texts |
| 703 | .iter() |
| 704 | .filter(|(text, _)| text == label) |
| 705 | .map(|(_, p)| p) |
| 706 | .collect::<Vec<_>>(); |
| 707 | assert!(!positions.is_empty(), "{label}"); |
| 708 | assert!( |
| 709 | positions.iter().all(|p| p.y >= 0.0 && p.y <= size.y), |
| 710 | "{label}: {positions:?}" |
| 711 | ); |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | #[test] |
| 716 | fn folder_open_command_preserves_shell_characters_as_one_argument() { |
| 717 | let path = path("한글 폴더 ; $(touch unexpected)"); |
| 718 | let command = folder_command(&path); |
| 719 | assert_eq!( |
| 720 | command.get_program(), |
| 721 | if cfg!(windows) { |
| 722 | "explorer" |
| 723 | } else { |
| 724 | "xdg-open" |
| 725 | } |
| 726 | ); |
| 727 | assert_eq!( |
| 728 | command.get_args().collect::<Vec<_>>(), |
| 729 | vec![path.as_os_str()] |
| 730 | ); |
| 731 | } |
| 732 | |
| 733 | #[test] |
| 734 | fn late_cancel_and_terminal_wait_use_finishing_text() { |
| 735 | let mut model = Model::default(); |
| 736 | model.progress = Some((Stage::Decode, 1, Some(2), 0)); |
| 737 | assert_eq!(activity_text(&model, false), "압축을 푸는 중"); |
| 738 | model.cancel = Some(CancelStatus::Requested); |
| 739 | assert_eq!(activity_text(&model, false), "취소하는 중..."); |
| 740 | for state in [CancelStatus::TooLate, CancelStatus::Finished] { |
| 741 | model.cancel = Some(state); |
| 742 | assert_eq!(activity_text(&model, false), "마무리하는 중"); |
| 743 | } |
| 744 | model.cancel = Some(CancelStatus::Requested); |
| 745 | model.terminal = Some(terminal()); |
| 746 | assert_eq!(activity_text(&model, false), "마무리하는 중"); |
| 747 | } |
| 748 | #[test] |
| 749 | fn client_protocol_errors_hide_internal_terms_but_preserve_exit_uncertainty() { |
| 750 | for error in [ |
| 751 | "작업 ID 한도에 도달했습니다", |
| 752 | "작업자 응답 순서나 작업 ID가 일치하지 않습니다", |
| 753 | "작업 승인 응답이 없습니다", |
| 754 | "출력 보고 한도 초과", |
| 755 | ] { |
| 756 | assert_eq!(client_error_text(error), INTERNAL); |
| 757 | } |
| 758 | assert_eq!( |
| 759 | client_error_text("작업자 종료 결과를 확인할 수 없습니다. 출력 상태를 확인하세요"), |
| 760 | UNCONFIRMED_FINISH |
| 761 | ); |
| 762 | } |