|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | 2 | import { truncate, withAlpha } from '../app/utils/og' |
3 | | -import { breadcrumbListLd, jsonLd } from '../app/utils/json-ld' |
4 | 3 |
|
5 | 4 | describe('withAlpha', () => { |
6 | 5 | it('expands 6-digit hex', () => { |
@@ -40,55 +39,3 @@ describe('truncate', () => { |
40 | 39 | expect(truncate('a'.repeat(20), 10)).toBe(`${'a'.repeat(10)}…`) |
41 | 40 | }) |
42 | 41 | }) |
43 | | - |
44 | | -describe('jsonLd', () => { |
45 | | - it('produces parseable JSON with the same values', () => { |
46 | | - expect(JSON.parse(jsonLd({ a: 1, b: 'x' }))).toEqual({ a: 1, b: 'x' }) |
47 | | - }) |
48 | | - |
49 | | - it('escapes markup so a title cannot close the script element', () => { |
50 | | - const output = jsonLd({ headline: 'Bad </script><img src=x>' }) |
51 | | - expect(output).not.toContain('</script>') |
52 | | - expect(output).not.toContain('<') |
53 | | - // Still decodes back to the original text. |
54 | | - expect(JSON.parse(output).headline).toBe('Bad </script><img src=x>') |
55 | | - }) |
56 | | - |
57 | | - it('escapes ampersands (HTML entity contexts)', () => { |
58 | | - const output = jsonLd({ name: 'A & B' }) |
59 | | - expect(output).not.toContain('&') |
60 | | - expect(JSON.parse(output).name).toBe('A & B') |
61 | | - }) |
62 | | -}) |
63 | | - |
64 | | -describe('breadcrumbListLd', () => { |
65 | | - it('emits position + item on every ListItem (Google requires item)', () => { |
66 | | - expect( |
67 | | - breadcrumbListLd([ |
68 | | - { name: 'Docs', item: 'https://comark.dev' }, |
69 | | - { name: 'Introduction', item: 'https://comark.dev/getting-started/introduction' }, |
70 | | - ]) |
71 | | - ).toEqual({ |
72 | | - '@context': 'https://schema.org', |
73 | | - '@type': 'BreadcrumbList', |
74 | | - itemListElement: [ |
75 | | - { '@type': 'ListItem', position: 1, name: 'Docs', item: 'https://comark.dev' }, |
76 | | - { |
77 | | - '@type': 'ListItem', |
78 | | - position: 2, |
79 | | - name: 'Introduction', |
80 | | - item: 'https://comark.dev/getting-started/introduction', |
81 | | - }, |
82 | | - ], |
83 | | - }) |
84 | | - }) |
85 | | - |
86 | | - it('never omits item, even for a single root crumb', () => { |
87 | | - const list = breadcrumbListLd([{ name: 'Docs', item: 'https://comark.dev/' }]) |
88 | | - for (const entry of list.itemListElement) { |
89 | | - expect(entry).toHaveProperty('item') |
90 | | - expect(typeof entry.item).toBe('string') |
91 | | - expect(entry.item.length).toBeGreaterThan(0) |
92 | | - } |
93 | | - }) |
94 | | -}) |
0 commit comments