lobe-chat

Форк
0
/
ld.test.ts 
102 строки · 3.0 Кб
1
// @vitest-environment node
2
import { describe, expect, it } from 'vitest';
3

4
import { DEFAULT_LANG } from '@/const/locale';
5

6
import { AUTHOR_LIST, Ld } from './ld';
7

8
describe('Ld', () => {
9
  const ld = new Ld();
10

11
  describe('generate', () => {
12
    it('should generate correct LD+JSON structure', () => {
13
      const result = ld.generate({
14
        title: 'Test Title',
15
        description: 'Test Description',
16
        url: 'https://example.com/test',
17
        locale: DEFAULT_LANG,
18
      });
19

20
      expect(result['@context']).toBe('https://schema.org');
21
      expect(Array.isArray(result['@graph'])).toBe(true);
22
      expect(result['@graph'].length).toBeGreaterThan(0);
23
    });
24
  });
25

26
  describe('genOrganization', () => {
27
    it('should generate correct organization structure', () => {
28
      const org = ld.genOrganization();
29

30
      expect(org['@type']).toBe('Organization');
31
      expect(org.name).toBe('LobeHub');
32
      expect(org.url).toBe('https://lobehub.com/');
33
    });
34
  });
35

36
  describe('getAuthors', () => {
37
    it('should return default author when no ids provided', () => {
38
      const author = ld.getAuthors();
39
      expect(author['@type']).toBe('Organization');
40
    });
41

42
    it('should return person when valid id provided', () => {
43
      const author = ld.getAuthors(['arvinxx']);
44
      expect(author['@type']).toBe('Person');
45
      // @ts-ignore
46
      expect(author.name).toBe(AUTHOR_LIST.arvinxx.name);
47
    });
48
  });
49

50
  describe('genWebPage', () => {
51
    it('should generate correct webpage structure', () => {
52
      const webpage = ld.genWebPage({
53
        title: 'Test Page',
54
        description: 'Test Description',
55
        url: 'https://example.com/test',
56
        locale: DEFAULT_LANG,
57
      });
58

59
      expect(webpage['@type']).toBe('WebPage');
60
      expect(webpage.name).toBe('Test Page · LobeChat');
61
      expect(webpage.description).toBe('Test Description');
62
    });
63
  });
64

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',
70
      });
71

72
      expect(image['@type']).toBe('ImageObject');
73
      expect(image.url).toBe('https://example.com/image.jpg');
74
    });
75
  });
76

77
  describe('genWebSite', () => {
78
    it('should generate correct website structure', () => {
79
      const website = ld.genWebSite();
80

81
      expect(website['@type']).toBe('WebSite');
82
      expect(website.name).toBe('LobeChat');
83
    });
84
  });
85

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',
92
        author: ['arvinxx'],
93
        identifier: 'test-id',
94
        locale: DEFAULT_LANG,
95
      });
96

97
      expect(article['@type']).toBe('Article');
98
      expect(article.headline).toBe('Test Article · LobeChat');
99
      expect(article.author['@type']).toBe('Person');
100
    });
101
  });
102
});
103

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.