1
// @vitest-environment node
2
import { describe, expect, it } from 'vitest';
4
import { DEFAULT_LANG } from '@/const/locale';
6
import { AUTHOR_LIST, Ld } from './ld';
11
describe('generate', () => {
12
it('should generate correct LD+JSON structure', () => {
13
const result = ld.generate({
15
description: 'Test Description',
16
url: 'https://example.com/test',
20
expect(result['@context']).toBe('https://schema.org');
21
expect(Array.isArray(result['@graph'])).toBe(true);
22
expect(result['@graph'].length).toBeGreaterThan(0);
26
describe('genOrganization', () => {
27
it('should generate correct organization structure', () => {
28
const org = ld.genOrganization();
30
expect(org['@type']).toBe('Organization');
31
expect(org.name).toBe('LobeHub');
32
expect(org.url).toBe('https://lobehub.com/');
36
describe('getAuthors', () => {
37
it('should return default author when no ids provided', () => {
38
const author = ld.getAuthors();
39
expect(author['@type']).toBe('Organization');
42
it('should return person when valid id provided', () => {
43
const author = ld.getAuthors(['arvinxx']);
44
expect(author['@type']).toBe('Person');
46
expect(author.name).toBe(AUTHOR_LIST.arvinxx.name);
50
describe('genWebPage', () => {
51
it('should generate correct webpage structure', () => {
52
const webpage = ld.genWebPage({
54
description: 'Test Description',
55
url: 'https://example.com/test',
59
expect(webpage['@type']).toBe('WebPage');
60
expect(webpage.name).toBe('Test Page · LobeChat');
61
expect(webpage.description).toBe('Test Description');
65
describe('genImageObject', () => {
66
it('should generate correct image object', () => {
67
const image = ld.genImageObject({
68
image: 'https://example.com/image.jpg',
69
url: 'https://example.com/test',
72
expect(image['@type']).toBe('ImageObject');
73
expect(image.url).toBe('https://example.com/image.jpg');
77
describe('genWebSite', () => {
78
it('should generate correct website structure', () => {
79
const website = ld.genWebSite();
81
expect(website['@type']).toBe('WebSite');
82
expect(website.name).toBe('LobeChat');
86
describe('genArticle', () => {
87
it('should generate correct article structure', () => {
88
const article = ld.genArticle({
89
title: 'Test Article',
90
description: 'Test Description',
91
url: 'https://example.com/test',
93
identifier: 'test-id',
97
expect(article['@type']).toBe('Article');
98
expect(article.headline).toBe('Test Article · LobeChat');
99
expect(article.author['@type']).toBe('Person');