team-ljyzipelo

공개
311줄11 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| 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 "resource-approval" => "큰 작업을 허용할까요?",
100 "resource-ratio" => "압축률이 매우 높습니다",
101 "resource-retry" => "한도를 늘려 다시 시도",
102 "resource-partial" => "저장 위치를 확인하세요",
103 "empty" => "TAR.BZ2, TAR.XZ",
104 "tar-bz2" | "tar-xz" => "읽어주세요.txt",
105 "folder-empty" => "이 폴더는 비어 있습니다",
106 "dialog-error" => "파일 선택 창을 열 수 없습니다",
107 "extract-partial" => "일부 파일만 풀렸습니다",
108 "extract-uncertain" => "저장이 끝났는지 확인하지 못했습니다",
109 "extract-unsynced" => "파일을 디스크에 완전히 저장했는지 확인하지 못했습니다",
110 "source-changed" => "압축파일 다시 열기",
111 "gzip-conflict" => "다른 이름으로 저장",
112 "create-error" => "ZIP 파일을 만들지 못했습니다",
113 "password-create" => "암호 확인",
114 "folder" => "바다.jpg",
115 "search-empty" => "일치하는 항목이 없습니다",
116 "password" | "password-retry" => "암호",
117 "extract-complete" => "압축을 풀었습니다",
118 "extract-cancelled" => "작업을 취소했습니다",
119 "create-complete" => "ZIP 파일을 만들었습니다",
120 "create" | "create-encrypted" => "암호로 보호하기",
121 "unsupported" | "damaged" => "압축파일을 열지 못했습니다",
122 "conflict" => "압축을 풀지 못했습니다",
123 "close-confirm" => "닫",
124 _ => "읽어주세요.txt",
125 };
126 assert!(labels.contains(expected), "{}: {labels}", scenario.name);
127 if matches!(scenario.name, "tar-bz2" | "tar-xz") {
128 assert!(app.model.entries.iter().all(|entry| !entry.encrypted));
129 assert_eq!(
130 app.model.list_id.as_ref().unwrap().format,
131 zipelo_ui_memory_app::archive_ui::Format::Tar
132 );
133 }
134 if scenario.name == "many-items" {
135 assert_eq!(app.model.entries.len(), 505);
136 }
137 if matches!(scenario.name, "selection" | "marquee") {
138 assert_eq!(app.model.selected.len(), 4);
139 assert!(labels.contains("선택 2개"));
140 }
141 if scenario.name == "password-retry" {
142 assert_eq!(app.model.challenge.unwrap().1, 2);
143 }
144 }
145 }
146}
147
148#[test]
149fn command_line_catalog_and_errors_work_without_a_display() {
150 let run = |args: &[&str]| {
151 std::process::Command::new(env!("CARGO_BIN_EXE_zipelo-ui-memory-app"))
152 .args(args)
153 .env_remove("DISPLAY")
154 .env_remove("WAYLAND_DISPLAY")
155 .output()
156 .unwrap()
157 };
158 let listed = run(&["--list-ui-scenarios"]);
159 assert!(listed.status.success());
160 assert_eq!(
161 String::from_utf8(listed.stdout).unwrap(),
162 scenarios::listing()
163 );
164 for args in [vec!["--ui-scenario", "unknown"], vec!["--ui-scenario"]] {
165 let failed = run(&args);
166 assert!(!failed.status.success());
167 let stderr = String::from_utf8_lossy(&failed.stderr);
168 for scenario in SCENARIOS {
169 assert!(stderr.contains(scenario.name));
170 }
171 }
172}
173
174#[test]
175fn preview_ignores_password_submission() {
176 let ctx = egui::Context::default();
177 let mut preview = scenarios::Preview::new(scenarios::parse("password").unwrap().build(), &ctx);
178 for _ in 0..3 {
179 let mut output = ctx.run_ui(
180 egui::RawInput {
181 screen_rect: Some(egui::Rect::from_min_size(
182 egui::Pos2::ZERO,
183 egui::vec2(1060.0, 720.0),
184 )),
185 events: vec![
186 egui::Event::Text("화면 검토".into()),
187 egui::Event::Key {
188 key: egui::Key::Enter,
189 physical_key: None,
190 pressed: true,
191 repeat: false,
192 modifiers: egui::Modifiers::NONE,
193 },
194 ],
195 ..Default::default()
196 },
197 |ui| preview.0.show(ui),
198 );
199 output.textures_delta.clear();
200 }
201 assert_eq!(preview.0.model.challenge, Some((17, 1, false)));
202 assert!(preview.0.model.busy());
203}
204
205fn resource_frame(
206 app: &mut zipelo_ui_memory_app::archive_screen::ArchiveApp,
207 ctx: &egui::Context,
208 events: Vec<egui::Event>,
209) -> Vec<egui::epaint::ClippedShape> {
210 let mut out = ctx.run_ui(
211 egui::RawInput {
212 screen_rect: Some(egui::Rect::from_min_size(
213 egui::Pos2::ZERO,
214 egui::vec2(760.0, 540.0),
215 )),
216 events,
217 ..Default::default()
218 },
219 |ui| app.show(ui),
220 );
221 out.textures_delta.clear();
222 out.shapes
223}
224fn find_resource_action(shapes: &[egui::epaint::ClippedShape], label: &str) -> egui::Pos2 {
225 fn find(s: &egui::Shape, label: &str) -> Option<egui::Pos2> {
226 match s {
227 egui::Shape::Text(t) if t.galley.text() == label => {
228 Some(t.pos + t.galley.rect.size() / 2.0)
229 }
230 egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, label)),
231 _ => None,
232 }
233 }
234 shapes.iter().find_map(|s| find(&s.shape, label)).unwrap()
235}
236#[test]
237fn resource_dialog_requires_explicit_click_and_escape_cancels() {
238 for allow in [false, true] {
239 let ctx = egui::Context::default();
240 let mut app = scenarios::parse("resource-ratio").unwrap().build();
241 let mut shapes = Vec::new();
242 for _ in 0..3 {
243 shapes = resource_frame(&mut app, &ctx, vec![]);
244 }
245 assert!(text(&shapes).contains("미확인"));
246 resource_frame(
247 &mut app,
248 &ctx,
249 vec![egui::Event::Key {
250 key: egui::Key::Enter,
251 physical_key: None,
252 pressed: true,
253 repeat: false,
254 modifiers: Default::default(),
255 }],
256 );
257 assert!(app.model.resource.is_some());
258 if allow {
259 let point = find_resource_action(&shapes, "이 작업 허용");
260 resource_frame(
261 &mut app,
262 &ctx,
263 vec![
264 egui::Event::PointerMoved(point),
265 egui::Event::PointerButton {
266 pos: point,
267 button: egui::PointerButton::Primary,
268 pressed: true,
269 modifiers: Default::default(),
270 },
271 ],
272 );
273 resource_frame(
274 &mut app,
275 &ctx,
276 vec![egui::Event::PointerButton {
277 pos: point,
278 button: egui::PointerButton::Primary,
279 pressed: false,
280 modifiers: Default::default(),
281 }],
282 );
283 assert!(!app.model.cancellation_requested());
284 } else {
285 resource_frame(
286 &mut app,
287 &ctx,
288 vec![egui::Event::Key {
289 key: egui::Key::Escape,
290 physical_key: None,
291 pressed: true,
292 repeat: false,
293 modifiers: Default::default(),
294 }],
295 );
296 assert!(app.model.cancellation_requested());
297 }
298 assert!(app.model.resource.is_none());
299 }
300}
301#[test]
302fn partial_limit_result_never_offers_expanded_retry() {
303 let ctx = egui::Context::default();
304 let mut app = scenarios::parse("resource-partial").unwrap().build();
305 let mut shapes = Vec::new();
306 for _ in 0..3 {
307 shapes = resource_frame(&mut app, &ctx, vec![]);
308 }
309 assert!(!text(&shapes).contains("한도를 늘려 다시 시도"));
310 assert!(text(&shapes).contains("풀린 자료"));
311}