| 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 | "empty" => "압축파일", |
| 100 | "folder-empty" => "이 폴더는 비어 있습니다", |
| 101 | "dialog-error" => "파일 선택 창을 열 수 없습니다", |
| 102 | "extract-partial" => "일부 파일만 풀렸습니다", |
| 103 | "extract-uncertain" => "저장이 끝났는지 확인하지 못했습니다", |
| 104 | "extract-unsynced" => "파일을 디스크에 완전히 저장했는지 확인하지 못했습니다", |
| 105 | "source-changed" => "압축파일 다시 열기", |
| 106 | "gzip-conflict" => "다른 이름으로 저장", |
| 107 | "create-error" => "ZIP 파일을 만들지 못했습니다", |
| 108 | "password-create" => "암호 확인", |
| 109 | "folder" => "바다.jpg", |
| 110 | "search-empty" => "일치하는 항목이 없습니다", |
| 111 | "password" | "password-retry" => "암호", |
| 112 | "extract-complete" => "압축을 풀었습니다", |
| 113 | "extract-cancelled" => "작업을 취소했습니다", |
| 114 | "create-complete" => "ZIP 파일을 만들었습니다", |
| 115 | "create" | "create-encrypted" => "암호로 보호하기", |
| 116 | "unsupported" | "damaged" => "압축파일을 열지 못했습니다", |
| 117 | "conflict" => "압축을 풀지 못했습니다", |
| 118 | "close-confirm" => "닫", |
| 119 | _ => "읽어주세요.txt", |
| 120 | }; |
| 121 | assert!(labels.contains(expected), "{}: {labels}", scenario.name); |
| 122 | if scenario.name == "many-items" { |
| 123 | assert_eq!(app.model.entries.len(), 505); |
| 124 | } |
| 125 | if matches!(scenario.name, "selection" | "marquee") { |
| 126 | assert_eq!(app.model.selected.len(), 4); |
| 127 | assert!(labels.contains("선택 2개")); |
| 128 | } |
| 129 | if scenario.name == "password-retry" { |
| 130 | assert_eq!(app.model.challenge.unwrap().1, 2); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | #[test] |
| 137 | fn command_line_catalog_and_errors_work_without_a_display() { |
| 138 | let run = |args: &[&str]| { |
| 139 | std::process::Command::new(env!("CARGO_BIN_EXE_zipelo-ui-memory-app")) |
| 140 | .args(args) |
| 141 | .env_remove("DISPLAY") |
| 142 | .env_remove("WAYLAND_DISPLAY") |
| 143 | .output() |
| 144 | .unwrap() |
| 145 | }; |
| 146 | let listed = run(&["--list-ui-scenarios"]); |
| 147 | assert!(listed.status.success()); |
| 148 | assert_eq!( |
| 149 | String::from_utf8(listed.stdout).unwrap(), |
| 150 | scenarios::listing() |
| 151 | ); |
| 152 | for args in [vec!["--ui-scenario", "unknown"], vec!["--ui-scenario"]] { |
| 153 | let failed = run(&args); |
| 154 | assert!(!failed.status.success()); |
| 155 | let stderr = String::from_utf8_lossy(&failed.stderr); |
| 156 | for scenario in SCENARIOS { |
| 157 | assert!(stderr.contains(scenario.name)); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | #[test] |
| 163 | fn preview_ignores_password_submission() { |
| 164 | let ctx = egui::Context::default(); |
| 165 | let mut preview = scenarios::Preview::new(scenarios::parse("password").unwrap().build(), &ctx); |
| 166 | for _ in 0..3 { |
| 167 | let mut output = ctx.run_ui( |
| 168 | egui::RawInput { |
| 169 | screen_rect: Some(egui::Rect::from_min_size( |
| 170 | egui::Pos2::ZERO, |
| 171 | egui::vec2(1060.0, 720.0), |
| 172 | )), |
| 173 | events: vec![ |
| 174 | egui::Event::Text("화면 검토".into()), |
| 175 | egui::Event::Key { |
| 176 | key: egui::Key::Enter, |
| 177 | physical_key: None, |
| 178 | pressed: true, |
| 179 | repeat: false, |
| 180 | modifiers: egui::Modifiers::NONE, |
| 181 | }, |
| 182 | ], |
| 183 | ..Default::default() |
| 184 | }, |
| 185 | |ui| preview.0.show(ui), |
| 186 | ); |
| 187 | output.textures_delta.clear(); |
| 188 | } |
| 189 | assert_eq!(preview.0.model.challenge, Some((17, 1, false))); |
| 190 | assert!(preview.0.model.busy()); |
| 191 | } |