Describe the browser handoff and cover retrying selected artboards

This commit is contained in:
Codex committed 2026-12-03 00:23:57 +01:00
1 parent 88359281d9
commit 3a9c4fc386
2 files changed
+41 -3

No files matched your search

+2 -3
View File
@@ -562,8 +562,7 @@ fn blob_url(bytes: &[u8], mime: &str) -> Result<String, String> {
web_sys::Url::create_object_url_with_blob(&blob).map_err(js_err)
}
/// File → Print in the browser: the job's PDF in a hidden frame, printed through the browser's
/// print dialog (which picks the printer).
/// Hands File → Print's composed PDF to the shared browser workflow.
struct BrowserPrint;
impl PrintService for BrowserPrint {
@@ -574,6 +573,6 @@ impl PrintService for BrowserPrint {
fn print(&mut self, job: &PrintJob) -> Result<String, String> {
craft::print::browser::print_pdf(job.pdf)?;
Ok(format!("Printing “{}”: pick the printer in the browser's print dialog", job.title))
Ok(format!("“{}” is ready to print in the browser", job.title))
}
}
+39
View File
@@ -171,6 +171,45 @@ fn print_sends_every_page_to_the_chosen_printer_and_keeps_the_settings() {
assert_eq!(fields(&app)["copies"], 2);
}
/// The browser supplies its own printer picker and can refuse to open it. Retrying prints
/// only the artboards the user selected in the same File → Print window.
#[test]
fn refused_browser_handoff_keeps_the_selected_artboards_for_retry() {
struct Browser {
refuse: bool,
accepted: Jobs,
}
impl PrintService for Browser {
fn printers(&mut self) -> Vec<Printer> {
Vec::new()
}
fn print(&mut self, job: &PrintJob) -> Result<String, String> {
if std::mem::take(&mut self.refuse) {
return Err("The browser could not open the print document".into());
}
MockPrint(self.accepted.clone()).print(job)
}
}
let (mut app, jobs) = app();
app.services.print = Some(Box::new(Browser { refuse: true, accepted: jobs.clone() }));
app.run("file.print", json!({})).unwrap();
pump(&mut app);
set(&mut app, "artboards", json!("range"));
set(&mut app, "range", json!("2-3"));
confirm(&mut app);
assert!(is_open(&app));
assert_eq!(fields(&app)["range"], "2-3");
assert!(jobs.borrow().is_empty());
confirm(&mut app);
assert!(!is_open(&app));
let accepted = jobs.borrow();
assert_eq!(accepted.len(), 1);
assert_eq!(accepted[0].0, None);
assert_eq!(pages(&accepted[0].2), 2);
}
#[test]
fn done_keeps_the_settings_without_printing_and_bad_settings_keep_the_dialog() {
let (mut app, jobs) = app();