team-ljyzipelo

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