Skip to content

Commit 2dcc42a

Browse files
ovindu-aghostdevv
andauthored
Tests for CldOgImage (#151)
Co-authored-by: Willow (GHOST) <ghostdevbusiness@gmail.com>
1 parent 10c6ac4 commit 2dcc42a

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { render, cleanup } from '@testing-library/svelte';
2+
import { afterEach, describe, expect, it, vi } from 'vitest';
3+
import { CldOgImage } from '$src/index';
4+
5+
describe('CldImage', () => {
6+
afterEach(() => {
7+
cleanup();
8+
});
9+
10+
it('should generate the correct URL for Cloudinary Open Graph image in the og:image meta tag', () => {
11+
render(CldOgImage, {
12+
props: {
13+
src: 'og_image',
14+
alt: 'OG Image',
15+
config: { cloud: { cloudName: 'testing-og' } },
16+
},
17+
});
18+
19+
const metaTag = document.querySelector<HTMLMetaElement>(
20+
'meta[property="og:image"]',
21+
);
22+
23+
expect(metaTag).toBeInstanceOf(HTMLMetaElement);
24+
expect(metaTag?.content).toContain('https://res.cloudinary.com');
25+
expect(metaTag?.content).toContain('og_image');
26+
});
27+
28+
it('should render with a dynamically generated Cloudinary URL using a random cloud name', () => {
29+
const cloudName = crypto.randomUUID();
30+
31+
render(CldOgImage, {
32+
props: {
33+
src: 'og_image',
34+
alt: '',
35+
config: { cloud: { cloudName } },
36+
},
37+
});
38+
39+
const metaTag = document.querySelector<HTMLMetaElement>(
40+
'meta[property="og:image"]',
41+
);
42+
43+
expect(metaTag).toBeInstanceOf(HTMLMetaElement);
44+
expect(metaTag?.content).toContain(cloudName);
45+
});
46+
47+
it('should work with global config from environment variables', () => {
48+
const cloudName = crypto.randomUUID();
49+
vi.stubEnv('VITE_CLOUDINARY_CLOUD_NAME', cloudName);
50+
51+
render(CldOgImage, {
52+
props: {
53+
src: 'og_image',
54+
alt: '',
55+
},
56+
});
57+
58+
const metaTag = document.querySelector<HTMLMetaElement>(
59+
'meta[property="og:image"]',
60+
);
61+
62+
expect(metaTag?.content).toContain(cloudName);
63+
});
64+
});

0 commit comments

Comments
 (0)