Print color: the print test retries across a second boundary, as its sibling does

This commit is contained in:
aiongg
2026-10-20 18:11:27 +00:00
parent c89faad6a3
commit 2e0aedbaf6
+24 -14
View File
@@ -96,20 +96,30 @@ mod tests {
let mut s = Session::new();
s.execute("file.new", &json!({"pages": 4})).unwrap();
let params = json!({"printer": "Office (east)", "copies": 2, "pages": "2-3", "marks": true, "bleed": true});
let expected = super::super::export::pdf_export(&s, &params).unwrap().bytes;
let r = print_with(&mut s, &params, |pdf, job| {
// The production export options and full bytes reach the shared spooler boundary.
assert_eq!(pdf, expected);
assert!(pdf.starts_with(b"%PDF-"));
assert_eq!(job.printer.as_deref(), Some("Office (east)"));
assert_eq!(job.copies, 2);
assert_eq!(job.duplex, None);
assert_eq!(job.scaling, craft_print::Scaling::ShrinkToFit);
assert!(!job.title.is_empty());
Ok("request id is Office-1".into())
})
.unwrap();
assert_eq!(r["pages"], 2);
// The production export options and full bytes reach the shared spooler boundary. The
// creation date is in whole seconds: an attempt can straddle a second boundary.
let mut matched = false;
for _ in 0..3 {
let expected = super::super::export::pdf_export(&s, &params).unwrap().bytes;
let mut printed = Vec::new();
let r = print_with(&mut s, &params, |pdf, job| {
printed = pdf.to_vec();
assert!(pdf.starts_with(b"%PDF-"));
assert_eq!(job.printer.as_deref(), Some("Office (east)"));
assert_eq!(job.copies, 2);
assert_eq!(job.duplex, None);
assert_eq!(job.scaling, craft_print::Scaling::ShrinkToFit);
assert!(!job.title.is_empty());
Ok("request id is Office-1".into())
})
.unwrap();
assert_eq!(r["pages"], 2);
if printed == expected {
matched = true;
break;
}
}
assert!(matched, "File › Print spools the selected export's bytes");
let refusal = print_with(&mut s, &params, |_, _| Err(craft_print::Error::Spool("printer offline".into()))).unwrap_err();
assert!(refusal.to_string().contains("printer offline"));
print_with(&mut s, &json!({"dryRun": true}), |_, _| panic!("dry runs must not spool")).unwrap();