Files
community-rule/tests/unit/hooks/useSchemaData.test.jsx
T
adilalloandCursor c180e79c38 Give every public route its own description, and keep canonicals and structured data on the host that serves the page.
Decorative images on the marketing pages stay quiet, and every dialog close button is named Close.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 11:04:52 -07:00

111 lines
2.7 KiB
React

import { renderHook } from "@testing-library/react";
import { describe, test, expect } from "vitest";
import { useSchemaData } from "../../../app/hooks/useSchemaData";
describe("useSchemaData", () => {
test("generates Organization schema", () => {
const { result } = renderHook(() =>
useSchemaData({
type: "Organization",
name: "Test Org",
url: "https://example.com",
email: "test@example.com",
sameAs: ["https://twitter.com/test"],
}),
);
expect(result.current).toEqual({
"@context": "https://schema.org",
"@type": "Organization",
name: "Test Org",
url: "https://example.com",
email: "test@example.com",
sameAs: ["https://twitter.com/test"],
});
});
test("generates WebSite schema without a search action", () => {
const { result } = renderHook(() =>
useSchemaData({
type: "WebSite",
name: "Test Site",
url: "https://example.com",
}),
);
expect(result.current).toEqual({
"@context": "https://schema.org",
"@type": "WebSite",
name: "Test Site",
url: "https://example.com",
});
expect(result.current).not.toHaveProperty("potentialAction");
});
test("generates HowTo schema", () => {
const { result } = renderHook(() =>
useSchemaData({
type: "HowTo",
name: "How to test",
description: "Test description",
steps: [
{ name: "Step 1", text: "Do this" },
{ name: "Step 2", text: "Do that" },
],
}),
);
expect(result.current).toEqual({
"@context": "https://schema.org",
"@type": "HowTo",
name: "How to test",
description: "Test description",
step: [
{
"@type": "HowToStep",
position: 1,
name: "Step 1",
text: "Do this",
},
{
"@type": "HowToStep",
position: 2,
name: "Step 2",
text: "Do that",
},
],
});
});
test("generates BreadcrumbList schema", () => {
const { result } = renderHook(() =>
useSchemaData({
type: "BreadcrumbList",
items: [
{ name: "Home", url: "https://example.com" },
{ name: "Page", url: "https://example.com/page" },
],
}),
);
expect(result.current).toEqual({
"@context": "https://schema.org",
"@type": "BreadcrumbList",
itemListElement: [
{
"@type": "ListItem",
position: 1,
name: "Home",
item: "https://example.com",
},
{
"@type": "ListItem",
position: 2,
name: "Page",
item: "https://example.com/page",
},
],
});
});
});