team-ljyzipelo

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