This repository has been archived by the owner on Sep 3, 2023. It is now read-only.
/
index.test.ts
141 lines (131 loc) · 3.76 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { expect } from 'vitest'
import { injectSchemaOrg, useSchemaOrg, useSetup } from '../../../.test'
import type { Breadcrumb } from './index'
import { PrimaryBreadcrumbId } from './index'
import { defineBreadcrumb } from '#provider'
describe('defineBreadcrumb', () => {
it('can be registered', () => {
useSetup(() => {
useSchemaOrg([
defineBreadcrumb({
itemListElement: [
{ name: 'Home', item: '/' },
{ name: 'Blog', item: '/blog' },
{ name: 'My Article' },
],
}),
])
const { findNode } = injectSchemaOrg()
const breadcrumbs = findNode<Breadcrumb>(PrimaryBreadcrumbId)
expect(breadcrumbs).toMatchInlineSnapshot(`
{
"@id": "https://example.com/#breadcrumb",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"item": "https://example.com",
"name": "Home",
"position": 1,
},
{
"@type": "ListItem",
"item": "https://example.com/blog",
"name": "Blog",
"position": 2,
},
{
"@type": "ListItem",
"name": "My Article",
"position": 3,
},
],
}
`)
})
})
it('can handle duplicate', () => {
useSetup(() => {
useSchemaOrg([
defineBreadcrumb({
itemListElement: [
{ name: 'Home', item: '/', position: 1 },
{ name: 'Blog', item: '/blog', position: 2 },
{ name: 'My Article', position: 4 },
],
}),
defineBreadcrumb({
itemListElement: [
{ name: 'Some joining page', item: '/blog/test', position: 3 },
],
}),
defineBreadcrumb({
'@id': '#subbreadcrumb',
'itemListElement': [
{ name: 'Some other link', item: '/blog/test' },
],
}),
defineBreadcrumb({
'@id': '#subbreadcrumb',
'custom': 'test',
'itemListElement': [
{ name: 'Some other link', item: '/blog/test' },
],
}),
])
const client = injectSchemaOrg()
expect(client.graphNodes).toMatchInlineSnapshot(`
[
{
"@id": "https://example.com/#breadcrumb",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"item": "https://example.com",
"name": "Home",
"position": 1,
},
{
"@type": "ListItem",
"item": "https://example.com/blog",
"name": "Blog",
"position": 2,
},
{
"@type": "ListItem",
"name": "My Article",
"position": 4,
},
],
},
{
"@id": "https://example.com/#/schema/breadcrumblist/XYJRR9nagB",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"item": "https://example.com/blog/test",
"name": "Some joining page",
"position": 3,
},
],
},
{
"@id": "https://example.com/#subbreadcrumb",
"@type": "BreadcrumbList",
"custom": "test",
"itemListElement": [
{
"@type": "ListItem",
"item": "https://example.com/blog/test",
"name": "Some other link",
"position": 1,
},
],
},
]
`)
})
})
})