import { describe, it, expect } from "bun:test";
import grabWebMetaHTML from "../../../functions/server/web-pages/grab-web-meta-html";
describe("grabWebMetaHTML", () => {
it("returns empty string for empty meta object", () => {
expect(grabWebMetaHTML({ meta: {} })).toBe("");
});
it("generates a title tag", () => {
const html = grabWebMetaHTML({ meta: { title: "My Page" } });
expect(html).toContain("
My Page");
});
it("generates a description meta tag", () => {
const html = grabWebMetaHTML({ meta: { description: "A description" } });
expect(html).toContain(' {
const html = grabWebMetaHTML({
meta: { keywords: ["react", "bun", "ssr"] },
});
expect(html).toContain('content="react, bun, ssr"');
});
it("uses string keywords directly", () => {
const html = grabWebMetaHTML({ meta: { keywords: "react, bun" } });
expect(html).toContain('content="react, bun"');
});
it("generates author meta tag", () => {
const html = grabWebMetaHTML({ meta: { author: "Alice" } });
expect(html).toContain(' {
const html = grabWebMetaHTML({ meta: { robots: "noindex" } });
expect(html).toContain(' {
const html = grabWebMetaHTML({
meta: { canonical: "https://example.com/page" },
});
expect(html).toContain(' {
const html = grabWebMetaHTML({ meta: { themeColor: "#ff0000" } });
expect(html).toContain(' {
const html = grabWebMetaHTML({
meta: {
og: {
title: "OG Title",
description: "OG Desc",
image: "https://example.com/img.png",
url: "https://example.com",
type: "website",
siteName: "Example",
locale: "en_US",
},
},
});
expect(html).toContain(' {
const html = grabWebMetaHTML({
meta: {
twitter: {
card: "summary_large_image",
title: "Tweet Title",
description: "Tweet Desc",
image: "https://example.com/tw.png",
site: "@example",
creator: "@alice",
},
},
});
expect(html).toContain(' {
const html = grabWebMetaHTML({ meta: { og: { title: "Only Title" } } });
expect(html).toContain("og:title");
expect(html).not.toContain("og:description");
expect(html).not.toContain("og:image");
});
it("does not emit tags for missing fields", () => {
const html = grabWebMetaHTML({ meta: { title: "Hello" } });
expect(html).not.toContain("description");
expect(html).not.toContain("og:");
expect(html).not.toContain("twitter:");
});
});