//! Integration tests: HTML string → DOM → extract CSS → resolve styles. use we_css::values::Color; use we_style::computed::{extract_stylesheets, resolve_styles, Display, FontWeight, LengthOrAuto}; #[test] fn html_with_style_element() { let html = r#"
Paragraph
"#; let doc = we_html::parse_html(html); let sheets = extract_stylesheets(&doc); assert_eq!(sheets.len(), 1); let styled = resolve_styles(&doc, &sheets).unwrap(); // styled root is // Find body (first visible child) let body = &styled.children[0]; // Find h1 and p let h1 = &body.children[0]; let p = &body.children[1]; assert_eq!(h1.style.color, Color::rgb(0, 0, 255)); // blue assert_eq!(p.style.color, Color::rgb(255, 0, 0)); // red assert_eq!(p.style.font_size, 24.0); } #[test] fn html_with_multiple_style_elements() { let html = r#"text
"#; let doc = we_html::parse_html(html); let sheets = extract_stylesheets(&doc); assert_eq!(sheets.len(), 2); let styled = resolve_styles(&doc, &sheets).unwrap(); let body = &styled.children[0]; let p = &body.children[0]; // Later stylesheet wins. assert_eq!(p.style.color, Color::rgb(0, 128, 0)); } #[test] fn html_with_inline_style_attribute() { let html = r#"text
"#; let doc = we_html::parse_html(html); let sheets = extract_stylesheets(&doc); let styled = resolve_styles(&doc, &sheets).unwrap(); let body = &styled.children[0]; let p = &body.children[0]; // Inline style overrides stylesheet. assert_eq!(p.style.color, Color::rgb(0, 0, 255)); } #[test] fn html_no_style_uses_ua_defaults() { let html = r#"Text
"#; let doc = we_html::parse_html(html); let sheets = extract_stylesheets(&doc); assert!(sheets.is_empty()); let styled = resolve_styles(&doc, &sheets).unwrap(); let body = &styled.children[0]; // Body should have 8px margin from UA stylesheet. assert_eq!(body.style.margin_top, LengthOrAuto::Length(8.0)); // h1 should be block with bold and 2em font-size. let h1 = &body.children[0]; assert_eq!(h1.style.display, Display::Block); assert_eq!(h1.style.font_weight, FontWeight(700.0)); assert_eq!(h1.style.font_size, 32.0); // 2em * 16px } #[test] fn style_element_display_none_in_styled_tree() { let html = r#"text
"#; let doc = we_html::parse_html(html); let sheets = extract_stylesheets(&doc); let styled = resolve_styles(&doc, &sheets).unwrap(); // The andImportant
Normal
"#; let doc = we_html::parse_html(html); let sheets = extract_stylesheets(&doc); let styled = resolve_styles(&doc, &sheets).unwrap(); let body = &styled.children[0]; let highlight_p = &body.children[0]; let normal_p = &body.children[1]; assert_eq!(highlight_p.style.color, Color::rgb(255, 0, 0)); assert_eq!(highlight_p.style.background_color, Color::rgb(255, 255, 0)); // Normal p inherits default color (black). assert_eq!(normal_p.style.color, Color::rgb(0, 0, 0)); }