mirror of
https://github.com/duhanbalci/dreport.git
synced 2026-07-01 18:39:16 +00:00
fmt
This commit is contained in:
@@ -66,10 +66,7 @@ fn test_render_pdf_produces_valid_output() {
|
||||
let pdf_bytes = dreport_layout::pdf_render::render_pdf(&layout, &fonts).unwrap();
|
||||
|
||||
// PDF should not be empty
|
||||
assert!(
|
||||
!pdf_bytes.is_empty(),
|
||||
"PDF output should not be empty"
|
||||
);
|
||||
assert!(!pdf_bytes.is_empty(), "PDF output should not be empty");
|
||||
|
||||
// PDF should start with %PDF magic bytes
|
||||
assert!(
|
||||
@@ -239,7 +236,10 @@ fn test_page_break_produces_multiple_pages() {
|
||||
let template = Template {
|
||||
id: "pb_test".to_string(),
|
||||
name: "Page Break Test".to_string(),
|
||||
page: PageSettings { width: 210.0, height: 297.0 },
|
||||
page: PageSettings {
|
||||
width: 210.0,
|
||||
height: 297.0,
|
||||
},
|
||||
fonts: vec!["Noto Sans".to_string()],
|
||||
header: None,
|
||||
footer: None,
|
||||
@@ -250,7 +250,12 @@ fn test_page_break_produces_multiple_pages() {
|
||||
size: SizeConstraint::default(),
|
||||
direction: "column".to_string(),
|
||||
gap: 5.0,
|
||||
padding: Padding { top: 15.0, right: 15.0, bottom: 15.0, left: 15.0 },
|
||||
padding: Padding {
|
||||
top: 15.0,
|
||||
right: 15.0,
|
||||
bottom: 15.0,
|
||||
left: 15.0,
|
||||
},
|
||||
align: "stretch".to_string(),
|
||||
justify: "start".to_string(),
|
||||
style: ContainerStyle::default(),
|
||||
@@ -259,16 +264,32 @@ fn test_page_break_produces_multiple_pages() {
|
||||
TemplateElement::StaticText(StaticTextElement {
|
||||
id: "t1".to_string(),
|
||||
position: PositionMode::Flow,
|
||||
size: SizeConstraint { width: SizeValue::Fr { value: 1.0 }, height: SizeValue::Auto, ..Default::default() },
|
||||
style: TextStyle { font_size: Some(18.0), ..Default::default() },
|
||||
size: SizeConstraint {
|
||||
width: SizeValue::Fr { value: 1.0 },
|
||||
height: SizeValue::Auto,
|
||||
..Default::default()
|
||||
},
|
||||
style: TextStyle {
|
||||
font_size: Some(18.0),
|
||||
..Default::default()
|
||||
},
|
||||
content: "Page 1 content".to_string(),
|
||||
}),
|
||||
TemplateElement::PageBreak(PageBreakElement { id: "pb1".to_string() }),
|
||||
TemplateElement::PageBreak(PageBreakElement {
|
||||
id: "pb1".to_string(),
|
||||
}),
|
||||
TemplateElement::StaticText(StaticTextElement {
|
||||
id: "t2".to_string(),
|
||||
position: PositionMode::Flow,
|
||||
size: SizeConstraint { width: SizeValue::Fr { value: 1.0 }, height: SizeValue::Auto, ..Default::default() },
|
||||
style: TextStyle { font_size: Some(18.0), ..Default::default() },
|
||||
size: SizeConstraint {
|
||||
width: SizeValue::Fr { value: 1.0 },
|
||||
height: SizeValue::Auto,
|
||||
..Default::default()
|
||||
},
|
||||
style: TextStyle {
|
||||
font_size: Some(18.0),
|
||||
..Default::default()
|
||||
},
|
||||
content: "Page 2 content".to_string(),
|
||||
}),
|
||||
],
|
||||
@@ -277,32 +298,43 @@ fn test_page_break_produces_multiple_pages() {
|
||||
|
||||
let data = serde_json::json!({});
|
||||
let fonts = load_test_fonts();
|
||||
|
||||
|
||||
let layout = compute_layout(&template, &data, &fonts).unwrap();
|
||||
|
||||
|
||||
println!("Layout pages: {}", layout.pages.len());
|
||||
for (i, page) in layout.pages.iter().enumerate() {
|
||||
println!("Page {}: {} elements", i, page.elements.len());
|
||||
for el in &page.elements {
|
||||
println!(" - {} (type={}, y={:.1}mm, h={:.1}mm)", el.id, el.element_type, el.y_mm, el.height_mm);
|
||||
println!(
|
||||
" - {} (type={}, y={:.1}mm, h={:.1}mm)",
|
||||
el.id, el.element_type, el.y_mm, el.height_mm
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
assert_eq!(layout.pages.len(), 2, "Page break should produce 2 pages");
|
||||
|
||||
|
||||
// Verify page 1 has t1 and page 2 has t2
|
||||
let p1_ids: Vec<&str> = layout.pages[0].elements.iter().map(|e| e.id.as_str()).collect();
|
||||
let p2_ids: Vec<&str> = layout.pages[1].elements.iter().map(|e| e.id.as_str()).collect();
|
||||
let p1_ids: Vec<&str> = layout.pages[0]
|
||||
.elements
|
||||
.iter()
|
||||
.map(|e| e.id.as_str())
|
||||
.collect();
|
||||
let p2_ids: Vec<&str> = layout.pages[1]
|
||||
.elements
|
||||
.iter()
|
||||
.map(|e| e.id.as_str())
|
||||
.collect();
|
||||
println!("Page 1 IDs: {:?}", p1_ids);
|
||||
println!("Page 2 IDs: {:?}", p2_ids);
|
||||
|
||||
|
||||
assert!(p1_ids.contains(&"t1"), "Page 1 should contain t1");
|
||||
assert!(p2_ids.contains(&"t2"), "Page 2 should contain t2");
|
||||
|
||||
|
||||
// Render PDF and verify it's valid
|
||||
let pdf_bytes = dreport_layout::pdf_render::render_pdf(&layout, &fonts).unwrap();
|
||||
assert!(pdf_bytes.starts_with(b"%PDF"));
|
||||
|
||||
|
||||
// Write PDF to temp dir for manual inspection
|
||||
let out_path = std::env::temp_dir().join("dreport_test_page_break.pdf");
|
||||
std::fs::write(&out_path, &pdf_bytes).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user