Skip to content

Commit f250318

Browse files
committed
chore: update
1 parent 035e52d commit f250318

File tree

2 files changed

+244
-0
lines changed

2 files changed

+244
-0
lines changed

__tests__/html/pixel-10.html

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Google Pixel 10 Pro - The Future of Android</title>
7+
8+
<!-- Open Graph tags -->
9+
<meta property="og:title" content="Google Pixel 10 Pro - AI-Powered Photography">
10+
<meta property="og:type" content="product">
11+
<meta property="og:url" content="https://store.google.com/product/pixel_10_pro">
12+
<meta property="og:description" content="Experience the next generation of mobile photography with Google Pixel 10 Pro. Featuring advanced AI capabilities, 200MP camera, and Tensor G5 processor.">
13+
<meta property="og:image" content="https://storage.googleapis.com/pixel/pixel-10-pro-hero.jpg">
14+
<meta property="og:image:width" content="1200">
15+
<meta property="og:image:height" content="630">
16+
<meta property="og:image:type" content="image/jpeg">
17+
<meta property="og:image:alt" content="Google Pixel 10 Pro in Obsidian Black">
18+
<meta property="og:site_name" content="Google Store">
19+
<meta property="og:locale" content="en_US">
20+
<meta property="og:locale:alternate" content="es_ES">
21+
<meta property="og:locale:alternate" content="fr_FR">
22+
23+
<!-- Product specific Open Graph tags -->
24+
<meta property="product:price:amount" content="1299.00">
25+
<meta property="product:price:currency" content="USD">
26+
<meta property="product:availability" content="preorder">
27+
<meta property="product:condition" content="new">
28+
<meta property="product:retailer_item_id" content="pixel_10_pro_256gb">
29+
<meta property="product:brand" content="Google">
30+
31+
<!-- Twitter Card tags -->
32+
<meta name="twitter:card" content="summary_large_image">
33+
<meta name="twitter:site" content="@madebygoogle">
34+
<meta name="twitter:creator" content="@google">
35+
<meta name="twitter:title" content="Google Pixel 10 Pro - Redefining Mobile Photography">
36+
<meta name="twitter:description" content="200MP camera system, Tensor G5 processor, and Magic Eraser Pro. Pre-order the Pixel 10 Pro today.">
37+
<meta name="twitter:image" content="https://storage.googleapis.com/pixel/pixel-10-pro-twitter.jpg">
38+
<meta name="twitter:image:alt" content="Google Pixel 10 Pro showcase">
39+
40+
<!-- Additional meta tags -->
41+
<meta name="description" content="Buy Google Pixel 10 Pro with advanced AI photography, 6.9-inch LTPO display, and all-day battery life. Free shipping and returns.">
42+
<meta name="keywords" content="Pixel 10 Pro, Google phone, Android 15, AI camera, smartphone">
43+
<meta name="author" content="Google">
44+
<meta name="robots" content="index, follow">
45+
<link rel="canonical" href="https://store.google.com/product/pixel_10_pro">
46+
<link rel="icon" type="image/x-icon" href="/favicon.ico">
47+
48+
<!-- App Links -->
49+
<meta property="al:android:app_name" content="Google Store">
50+
<meta property="al:android:package" content="com.google.store">
51+
<meta property="al:android:url" content="googlestore://product/pixel_10_pro">
52+
<meta property="al:ios:app_name" content="Google Store">
53+
<meta property="al:ios:app_store_id" content="123456789">
54+
<meta property="al:ios:url" content="googlestore://product/pixel_10_pro">
55+
<meta property="al:web:url" content="https://store.google.com/product/pixel_10_pro">
56+
57+
<!-- JSON-LD Structured Data -->
58+
<script type="application/ld+json">
59+
{
60+
"@context": "https://schema.org/",
61+
"@type": "Product",
62+
"name": "Google Pixel 10 Pro",
63+
"image": [
64+
"https://storage.googleapis.com/pixel/pixel-10-pro-1.jpg",
65+
"https://storage.googleapis.com/pixel/pixel-10-pro-2.jpg",
66+
"https://storage.googleapis.com/pixel/pixel-10-pro-3.jpg"
67+
],
68+
"description": "The Google Pixel 10 Pro features a revolutionary 200MP camera system with advanced AI processing, delivering professional-quality photos and videos.",
69+
"sku": "PIXEL10PRO256",
70+
"mpn": "GA04532-US",
71+
"brand": {
72+
"@type": "Brand",
73+
"name": "Google"
74+
},
75+
"review": {
76+
"@type": "Review",
77+
"reviewRating": {
78+
"@type": "Rating",
79+
"ratingValue": "4.8",
80+
"bestRating": "5"
81+
},
82+
"author": {
83+
"@type": "Person",
84+
"name": "TechReviewer"
85+
}
86+
},
87+
"aggregateRating": {
88+
"@type": "AggregateRating",
89+
"ratingValue": "4.7",
90+
"reviewCount": "2456"
91+
},
92+
"offers": {
93+
"@type": "Offer",
94+
"url": "https://store.google.com/product/pixel_10_pro",
95+
"priceCurrency": "USD",
96+
"price": "1299.00",
97+
"priceValidUntil": "2025-12-31",
98+
"itemCondition": "https://schema.org/NewCondition",
99+
"availability": "https://schema.org/PreOrder",
100+
"seller": {
101+
"@type": "Organization",
102+
"name": "Google Store"
103+
}
104+
}
105+
}
106+
</script>
107+
</head>
108+
<body>
109+
<h1>Google Pixel 10 Pro</h1>
110+
<p>The most advanced Pixel phone yet, featuring breakthrough AI technology and professional camera capabilities.</p>
111+
112+
<div class="product-details">
113+
<h2>Key Features</h2>
114+
<ul>
115+
<li>200MP main camera with AI enhancement</li>
116+
<li>Google Tensor G5 processor</li>
117+
<li>6.9" LTPO OLED display with 120Hz refresh rate</li>
118+
<li>5500mAh battery with 65W fast charging</li>
119+
<li>Android 15 with 7 years of updates</li>
120+
<li>Magic Eraser Pro and Photo Unblur</li>
121+
</ul>
122+
</div>
123+
</body>
124+
</html>

__tests__/pixel-10-test.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { readFileSync } from "node:fs";
2+
import { extractOpenGraph } from "../src";
3+
4+
describe("Pixel 10 HTML extraction", () => {
5+
it("should extract all Open Graph data from Pixel 10 product page", async () => {
6+
const html = readFileSync(`${__dirname}/html/pixel-10.html`, "utf8");
7+
const result = extractOpenGraph(html);
8+
9+
// Basic Open Graph tags
10+
expect(result.ogTitle).toEqual("Google Pixel 10 Pro - AI-Powered Photography");
11+
expect(result.ogType).toEqual("product");
12+
expect(result.ogUrl).toEqual("https://store.google.com/product/pixel_10_pro");
13+
expect(result.ogDescription).toEqual(
14+
"Experience the next generation of mobile photography with Google Pixel 10 Pro. Featuring advanced AI capabilities, 200MP camera, and Tensor G5 processor.",
15+
);
16+
expect(result.ogSiteName).toEqual("Google Store");
17+
expect(result.ogLocale).toEqual("en_US");
18+
19+
// Open Graph Image
20+
expect(result.ogImage).toEqual({
21+
url: "https://storage.googleapis.com/pixel/pixel-10-pro-hero.jpg",
22+
width: "1200",
23+
height: "630",
24+
type: "image/jpeg",
25+
});
26+
27+
// Twitter Card tags
28+
expect(result.twitterCard).toEqual("summary_large_image");
29+
expect(result.twitterSite).toEqual("@madebygoogle");
30+
expect(result.twitterCreator).toEqual("@google");
31+
expect(result.twitterTitle).toEqual("Google Pixel 10 Pro - Redefining Mobile Photography");
32+
expect(result.twitterDescription).toEqual(
33+
"200MP camera system, Tensor G5 processor, and Magic Eraser Pro. Pre-order the Pixel 10 Pro today.",
34+
);
35+
expect(result.twitterImage).toEqual({
36+
url: "https://storage.googleapis.com/pixel/pixel-10-pro-twitter.jpg",
37+
width: null,
38+
height: null,
39+
alt: "Google Pixel 10 Pro showcase",
40+
});
41+
42+
// App Links
43+
expect(result.alAndroidAppName).toEqual("Google Store");
44+
expect(result.alAndroidPackage).toEqual("com.google.store");
45+
expect(result.alAndroidUrl).toEqual("googlestore://product/pixel_10_pro");
46+
expect(result.alIosAppName).toEqual("Google Store");
47+
expect(result.alIosAppStoreId).toEqual("123456789");
48+
expect(result.alIosUrl).toEqual("googlestore://product/pixel_10_pro");
49+
expect(result.alWebUrl).toEqual("https://store.google.com/product/pixel_10_pro");
50+
51+
// Other meta tags
52+
expect(result.favicon).toEqual("/favicon.ico");
53+
expect(result.author).toEqual("Google");
54+
55+
// Verify the keys we expect to be present
56+
expect(Object.keys(result)).toEqual(
57+
expect.arrayContaining([
58+
"ogTitle",
59+
"ogType",
60+
"ogUrl",
61+
"ogDescription",
62+
"ogImage",
63+
"ogSiteName",
64+
"ogLocale",
65+
"twitterCard",
66+
"twitterSite",
67+
"twitterCreator",
68+
"twitterTitle",
69+
"twitterDescription",
70+
"twitterImage",
71+
"alAndroidAppName",
72+
"alAndroidPackage",
73+
"alAndroidUrl",
74+
"alIosAppName",
75+
"alIosAppStoreId",
76+
"alIosUrl",
77+
"alWebUrl",
78+
"favicon",
79+
"author",
80+
]),
81+
);
82+
});
83+
84+
it("should extract structured data and merge with Open Graph data", async () => {
85+
const html = readFileSync(`${__dirname}/html/pixel-10.html`, "utf8");
86+
const result = extractOpenGraph(html, { extractStructuredData: true });
87+
88+
// When extractStructuredData is enabled, Product data from JSON-LD is merged
89+
// The library merges Product name and description into ogTitle and ogDescription
90+
expect(result.ogTitle).toEqual("Google Pixel 10 Pro - AI-Powered Photography");
91+
expect(result.ogDescription).toEqual(
92+
"Experience the next generation of mobile photography with Google Pixel 10 Pro. Featuring advanced AI capabilities, 200MP camera, and Tensor G5 processor.",
93+
);
94+
});
95+
96+
it("should extract all media with allMedia option enabled", async () => {
97+
const html = readFileSync(`${__dirname}/html/pixel-10.html`, "utf8");
98+
const result = extractOpenGraph(html, { allMedia: true });
99+
100+
// When allMedia is true, ogImage should be an array
101+
expect(result.ogImage).toEqual([
102+
{
103+
url: "https://storage.googleapis.com/pixel/pixel-10-pro-hero.jpg",
104+
width: "1200",
105+
height: "630",
106+
type: "image/jpeg",
107+
},
108+
]);
109+
110+
// Twitter image should be an array with allMedia
111+
expect(result.twitterImage).toEqual([
112+
{
113+
url: "https://storage.googleapis.com/pixel/pixel-10-pro-twitter.jpg",
114+
width: null,
115+
height: null,
116+
alt: "Google Pixel 10 Pro showcase",
117+
},
118+
]);
119+
});
120+
});

0 commit comments

Comments
 (0)