| 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| app.show(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 | "conflict-choice" | "conflict-apply" | "gzip-conflict-choice" => { |
| 100 | "나머지 파일에도 같게 적용" |
| 101 | } |
| 102 | "extract-skipped" => "모든 파일을 건너뛰었습니다", |
| 103 | "extract-rename-failed" => "아무 파일도 풀지 않았습니다", |
| 104 | "extract-renamed" => "이름 바꿔 저장: 읽어주세요 (1).txt", |
| 105 | "empty" => "TAR.BZ2, TAR.XZ", |
| 106 | "tar-bz2" | "tar-xz" => "읽어주세요.txt", |
| 107 | "folder-empty" => "이 폴더는 비어 있습니다", |
| 108 | "dialog-error" => "파일 선택 창을 열 수 없습니다", |
| 109 | "extract-partial" => "일부 파일만 풀렸습니다", |
| 110 | "extract-uncertain" => "저장이 끝났는지 확인하지 못했습니다", |
| 111 | "extract-unsynced" => "파일을 디스크에 완전히 저장했는지 확인하지 못했습니다", |
| 112 | "source-changed" => "압축파일 다시 열기", |
| 113 | "gzip-conflict" => "다른 이름으로 저장", |
| 114 | "create-error" => "ZIP 파일을 만들지 못했습니다", |
| 115 | "password-create" => "암호 확인", |
| 116 | "folder" => "바다.jpg", |
| 117 | "search-empty" => "일치하는 항목이 없습니다", |
| 118 | "password" | "password-retry" => "암호", |
| 119 | "extract-complete" => "압축을 풀었습니다", |
| 120 | "extract-cancelled" => "작업을 취소했습니다", |
| 121 | "create-complete" => "ZIP 파일을 만들었습니다", |
| 122 | "create" | "create-encrypted" => "암호로 보호하기", |
| 123 | "unsupported" | "damaged" => "압축파일을 열지 못했습니다", |
| 124 | "conflict" => "압축을 풀지 못했습니다", |
| 125 | "close-confirm" => "닫", |
| 126 | _ => "읽어주세요.txt", |
| 127 | }; |
| 128 | assert!(labels.contains(expected), "{}: {labels}", scenario.name); |
| 129 | if scenario.name == "extract-rename-failed" { |
| 130 | assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}"); |
| 131 | assert!(!labels.contains("이름 바꿔 저장:"), "{labels}"); |
| 132 | } |
| 133 | if matches!(scenario.name, "tar-bz2" | "tar-xz") { |
| 134 | assert!(app.model.entries.iter().all(|entry| !entry.encrypted)); |
| 135 | assert_eq!( |
| 136 | app.model.list_id.as_ref().unwrap().format, |
| 137 | zipelo_ui_memory_app::archive_ui::Format::Tar |
| 138 | ); |
| 139 | } |
| 140 | if scenario.name == "many-items" { |
| 141 | assert_eq!(app.model.entries.len(), 505); |
| 142 | } |
| 143 | if matches!(scenario.name, "selection" | "marquee") { |
| 144 | assert_eq!(app.model.selected.len(), 4); |
| 145 | assert!(labels.contains("선택 2개")); |
| 146 | } |
| 147 | if scenario.name == "password-retry" { |
| 148 | assert_eq!(app.model.challenge.unwrap().1, 2); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | #[test] |
| 155 | fn command_line_catalog_and_errors_work_without_a_display() { |
| 156 | let run = |args: &[&str]| { |
| 157 | std::process::Command::new(env!("CARGO_BIN_EXE_zipelo-ui-memory-app")) |
| 158 | .args(args) |
| 159 | .env_remove("DISPLAY") |
| 160 | .env_remove("WAYLAND_DISPLAY") |
| 161 | .output() |
| 162 | .unwrap() |
| 163 | }; |
| 164 | let listed = run(&["--list-ui-scenarios"]); |
| 165 | assert!(listed.status.success()); |
| 166 | assert_eq!( |
| 167 | String::from_utf8(listed.stdout).unwrap(), |
| 168 | scenarios::listing() |
| 169 | ); |
| 170 | for args in [vec!["--ui-scenario", "unknown"], vec!["--ui-scenario"]] { |
| 171 | let failed = run(&args); |
| 172 | assert!(!failed.status.success()); |
| 173 | let stderr = String::from_utf8_lossy(&failed.stderr); |
| 174 | for scenario in SCENARIOS { |
| 175 | assert!(stderr.contains(scenario.name)); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | #[test] |
| 181 | fn preview_ignores_password_submission() { |
| 182 | let ctx = egui::Context::default(); |
| 183 | let mut preview = scenarios::Preview::new(scenarios::parse("password").unwrap().build(), &ctx); |
| 184 | for _ in 0..3 { |
| 185 | let mut output = ctx.run_ui( |
| 186 | egui::RawInput { |
| 187 | screen_rect: Some(egui::Rect::from_min_size( |
| 188 | egui::Pos2::ZERO, |
| 189 | egui::vec2(1060.0, 720.0), |
| 190 | )), |
| 191 | events: vec![ |
| 192 | egui::Event::Text("화면 검토".into()), |
| 193 | egui::Event::Key { |
| 194 | key: egui::Key::Enter, |
| 195 | physical_key: None, |
| 196 | pressed: true, |
| 197 | repeat: false, |
| 198 | modifiers: egui::Modifiers::NONE, |
| 199 | }, |
| 200 | ], |
| 201 | ..Default::default() |
| 202 | }, |
| 203 | |ui| preview.0.show(ui), |
| 204 | ); |
| 205 | output.textures_delta.clear(); |
| 206 | } |
| 207 | assert_eq!(preview.0.model.challenge, Some((17, 1, false))); |
| 208 | assert!(preview.0.model.busy()); |
| 209 | } |
| 210 | |
| 211 | fn result_labels( |
| 212 | app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp, |
| 213 | size: egui::Vec2, |
| 214 | ) -> String { |
| 215 | let ctx = egui::Context::default(); |
| 216 | let mut labels = String::new(); |
| 217 | for _ in 0..3 { |
| 218 | let mut output = ctx.run_ui( |
| 219 | egui::RawInput { |
| 220 | screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)), |
| 221 | ..Default::default() |
| 222 | }, |
| 223 | |ui| app.show(ui), |
| 224 | ); |
| 225 | labels = text(&output.shapes); |
| 226 | output.textures_delta.clear(); |
| 227 | } |
| 228 | labels |
| 229 | } |
| 230 | |
| 231 | #[test] |
| 232 | fn rename_without_created_output_never_claims_saved_name() { |
| 233 | use zipelo_ui_memory_app::archive_ui::*; |
| 234 | for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] { |
| 235 | for disposition in [ |
| 236 | None, |
| 237 | Some(Disposition::PartialRetained), |
| 238 | Some(Disposition::Removed), |
| 239 | Some(Disposition::CommitUncertain), |
| 240 | ] { |
| 241 | let mut app = scenarios::parse("extract-renamed").unwrap().build(); |
| 242 | app.model.outputs = disposition |
| 243 | .into_iter() |
| 244 | .map(|d| ("읽어주세요 (1).txt".into(), d)) |
| 245 | .collect(); |
| 246 | app.model.terminal = Some(Terminal { |
| 247 | outcome: Outcome::Failed, |
| 248 | error: Some(ErrorCode::Io), |
| 249 | publication: if disposition.is_none() { |
| 250 | Publication::None |
| 251 | } else { |
| 252 | Publication::Uncertain |
| 253 | }, |
| 254 | created_count: 0, |
| 255 | retained_partial_count: 0, |
| 256 | durability: Durability::NotApplicable, |
| 257 | cleanup: Cleanup::Complete, |
| 258 | }); |
| 259 | let labels = result_labels(&mut app, size); |
| 260 | assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}"); |
| 261 | if disposition.is_none() { |
| 262 | assert!(labels.contains("아무 파일도 풀지 않았습니다"), "{labels}"); |
| 263 | } |
| 264 | assert!( |
| 265 | !labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"), |
| 266 | "{labels}" |
| 267 | ); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | #[test] |
| 273 | fn rename_saved_before_later_failure_remains_reported() { |
| 274 | use zipelo_ui_memory_app::archive_ui::*; |
| 275 | for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] { |
| 276 | let mut app = scenarios::parse("extract-renamed").unwrap().build(); |
| 277 | app.model.resolutions.push(Resolution { |
| 278 | entry_id: 2, |
| 279 | relative_name: "여행 일정 (1).pdf".into(), |
| 280 | choice: ConflictChoice::Rename, |
| 281 | }); |
| 282 | app.model.terminal.as_mut().unwrap().outcome = Outcome::Failed; |
| 283 | app.model.terminal.as_mut().unwrap().error = Some(ErrorCode::Io); |
| 284 | app.model.terminal.as_mut().unwrap().publication = Publication::Partial; |
| 285 | let labels = result_labels(&mut app, size); |
| 286 | assert!( |
| 287 | labels.contains("이름 바꿔 저장: 읽어주세요 (1).txt"), |
| 288 | "{labels}" |
| 289 | ); |
| 290 | assert!( |
| 291 | !labels.contains("이름 바꿔 저장: 여행 일정 (1).pdf"), |
| 292 | "{labels}" |
| 293 | ); |
| 294 | assert!(labels.contains("파일을 읽거나 쓰지 못했습니다"), "{labels}"); |
| 295 | } |
| 296 | } |