use webpage_quality_analyzer::{analyze, analyze_with_profile};
#[tokio::test]
async fn test_analyzer_creation() {
assert!(true);
}
#[tokio::test]
async fn test_analyzer_with_profile() {
let html = r#"<!DOCTYPE html>
<html>
<head><title>Test Page</title></head>
<body>
<p>This is a test page for analyzer with profile.</p>
</body>
</html>"#;
let result = analyze_with_profile("https://www.exam.com", Some(html), "content_article").await;
assert!(result.is_ok());
}
#[tokio::test]
async fn test_basic_html_analysis() {
let html = r#"<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
<meta name="description" content="Test description">
</head>
<body>
<h1>Main Heading</h1>
<p>This is a test paragraph with some content.</p>
<h2>Subheading</h2>
<p>Another paragraph with more content for testing.</p>
<ul>
<li>List item 1</li>
<li>List item 2</li>
</ul>
<a href="https://example.com">External link</a>
</body>
</html>"#;
let report = analyze("https://example.com/test", Some(html))
.await
.unwrap();
assert!(report.score >= 0.0 && report.score <= 100.0);
assert_eq!(report.metadata.title, "Test Page");
assert!(report.metadata.meta_description.is_some());
let metrics = &report.metrics.html_analysis;
assert!(metrics.content.word_count > 10);
assert!(metrics.structure.paragraph_count >= 1);
assert!(metrics.structure.headings_count >= 2);
assert!(metrics.seo.title_len > 5);
}
#[tokio::test]
async fn test_empty_content_handling() {
let html = r#"<!DOCTYPE html>
<html>
<head><title>Empty</title></head>
<body></body>
</html>"#;
let report = analyze("https://example.com/empty", Some(html))
.await
.unwrap();
assert!(report.score >= 0.0 && report.score <= 100.0);
assert_eq!(report.metadata.title, "Empty");
assert_eq!(report.metrics.html_analysis.content.word_count, 0);
assert_eq!(report.metrics.html_analysis.structure.paragraph_count, 0);
}
#[tokio::test]
async fn test_image_analysis() {
let html = r#"<!DOCTYPE html>
<html>
<head><title>Images Test</title></head>
<body>
<h1>Image Test</h1>
<img src="test1.jpg" alt="Test image 1">
<img src="test2.jpg" alt="Test image 2">
<img src="test3.jpg">
<p>Some content with images.</p>
</body>
</html>"#;
let report = analyze("https://example.com/images", Some(html))
.await
.unwrap();
assert_eq!(report.metrics.html_analysis.media.images_count, 3);
assert!(report.processed_document.images.len() >= 2);
}
#[tokio::test]
async fn test_link_analysis() {
let html = r#"<!DOCTYPE html>
<html>
<head><title>Links Test</title></head>
<body>
<h1>Link Test</h1>
<p>This page has <a href="https://external.com">external links</a> and
<a href="/internal">internal links</a>.</p>
<a href="https://another.com">Another external</a>
</body>
</html>"#;
let report = analyze("https://example.com/links", Some(html))
.await
.unwrap();
assert!(report.metrics.html_analysis.links.external_links > 0);
assert!(report.processed_document.links.len() >= 2);
}
#[tokio::test]
async fn test_heading_structure() {
let html = r#"<!DOCTYPE html>
<html>
<head><title>Headings Test</title></head>
<body>
<h1>Main Title</h1>
<h2>Section 1</h2>
<h3>Subsection 1.1</h3>
<h3>Subsection 1.2</h3>
<h2>Section 2</h2>
<h4>Should be h3</h4>
<p>Content between headings.</p>
</body>
</html>"#;
let report = analyze("https://example.com/headings", Some(html))
.await
.unwrap();
assert!(report.metrics.html_analysis.structure.headings_count >= 5);
assert!(report.processed_document.headings.len() >= 5);
let headings = &report.processed_document.headings;
assert!(headings.iter().any(|h| h.text.contains("Main Title")));
assert!(headings.iter().any(|h| h.text.contains("Section 1")));
}
#[tokio::test]
async fn test_error_handling() {
let result = analyze("https://example.com", Some("")).await;
println!("Empty HTML result: {:?}", result.is_err());
let result2 = analyze("https://example.com", Some("<html></html>")).await;
println!("Minimal HTML result: {:?}", result2.is_err());
assert!(true); }
#[tokio::test]
async fn test_metadata_extraction() {
let html = r#"<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Metadata Test Page</title>
<meta name="description" content="This is a test page description">
<meta name="author" content="Test Author">
<meta name="keywords" content="test, metadata, page">
<link rel="canonical" href="https://example.com/canonical">
<meta property="og:title" content="OG Title">
<meta property="og:description" content="OG Description">
</head>
<body>
<h1>Content</h1>
<p>Page content here.</p>
</body>
</html>"#;
let report = analyze("https://example.com/metadata", Some(html))
.await
.unwrap();
let metadata = &report.metadata;
assert_eq!(metadata.title, "Metadata Test Page");
assert_eq!(
metadata.meta_description,
Some("This is a test page description".to_string())
);
assert_eq!(metadata.author, Some("Test Author".to_string()));
assert_eq!(
metadata.canonical_url,
Some("https://example.com/canonical".to_string())
);
assert_eq!(metadata.language, Some("en".to_string()));
}